NekoManu Posted July 29, 2004 Posted July 29, 2004 I am trying to create a splashscreen. I have a form with a background image. On that form I want to put a few labels with a transparent background, so that I see that text without the rectangle behind it. This was very easy in Visual Basic 6.0, .NET on the other hand seems to have lost it. Can anyone tell me how to do this? :confused: Quote
sjn78 Posted July 29, 2004 Posted July 29, 2004 Use GDI and draw the text directly onto the form? Although doing this you may have to draw the image directly onto the form as well. Quote
NekoManu Posted July 30, 2004 Author Posted July 30, 2004 Use GDI and draw the text directly onto the form? Although doing this you may have to draw the image directly onto the form as well. Can you tell me what GDI is, how it works or where I can find some info on that? Quote
sjn78 Posted July 30, 2004 Posted July 30, 2004 For a splash screen, or any form in that matter, you can override the paint event. Make sure you imports system.drawing & system.drawing.drawing2d. I am typing this from memory, but its something like this. In the on_paint overrides, dim f as new font("Arial") e.graphics.drawstring("Your text", f, x, y) Same goes for you image. Create an image dim img as image img.fromfile("yourimage") e.graphics.drawimage(img, x, y, width, height) Put the drawimage before your drawstring otherwise the image will be drawn overtop of your text. You will have to check your images size and resize it according to the size you want your splash screen. Just have a look into the e.graphics.... and you will find plenty in there to manually draw items onto your form. Quote
NekoManu Posted July 30, 2004 Author Posted July 30, 2004 That seems to work, but... How do I know x, y? What I mean is that I have 1 form for all the applications, so the text is different each time and I want to have the text centered. How do I center the text? I thought of using this: (Form.width / 2) - (Text.width / 2) The problem with that is "Text.width", I don't know how to get that. Quote
sjn78 Posted July 30, 2004 Posted July 30, 2004 x = (form.width / 2) - (e.Graphics.MeasureString("yourstring", f).Width / 2) f is your font. y you will have to do something similar (form.height / 2) - 10 or something to allow for your font height. Just play with the '10' to make it suit. Quote
WaltzerSoft Posted August 3, 2004 Posted August 3, 2004 Make Transparent Label is so easy: Private Label1 as new Label Me.Label1.BackColor = Color.FromArgb(0,0,0,0) Quote
NekoManu Posted August 3, 2004 Author Posted August 3, 2004 I'm sorry but that does not work when you have an image on the background. It works fine with backgroundimagelayout = Tile; but when you use Strech the label is not transparent. You just see a complete copy of the backgroundimage in the label box. Quote
Leaders snarfblam Posted August 4, 2004 Leaders Posted August 4, 2004 This is how transparent controls are drawn. First their container is drawn in their rectangle, and then the control (in your case your label) is drawn on top. NO CONTROLS IN BETWEEN ARE DRAWN in that rectangle. For instance: if you have a Form than contains a PictureBox and a transparent label on top of the PictureBox then when the label is drawn, first it draws the forms background in the label's window, and then the label itself on top, but not the Picturebox in between. The appearance is almost as though you cut a hole throught the picturebox straight to the form. In otherwords, placing transparent controls on top of other controls does not produce the exected effect. Transparent controls only work properly when drawn directly over the container (i.e. your form). SO, if you are using a picture box to draw your form's background, your transparent label will cut a hole throught the picture to the empty underlying form, probably giving the appearance of a label that isnt transparent at all. If you are using a picture box, a transparent label on top wont work. You need to set your image to the form's .BackgroundImage property, and the label's background color to Color.Transparent. I tried this and it works as expected. An alternative (if you dont want the image tiled all across your form) is to use a panel control, setting the panel's .BackgroundImage property to your image and place the label INSIDE the panel so that the panel (with your image on it) is drawn behind your label, instead of the blank form. However, if you are showing your image via the Form.BackgroundImage property and the label's .Backcolor propert is set to Color.Transparent, and you still have an opaque rectangle around the label, I don't know what to tell you, because I just tried and it worked. In VB6, the labels were what are known as "Windowless Controls". As the name implies, they down have their own window. Their text was drawn directly on top of whatever is underneath them. In .NET, everything gets it's own window, which makes transparency much more complicated. Quote [sIGPIC]e[/sIGPIC]
*Experts* DiverDan Posted August 4, 2004 *Experts* Posted August 4, 2004 I think it might be further explained that the "transparent label" adopts it's container's background or backcolor properity. A panel is a container, therefore the transparent label shows the panel's background. You can add the label to a picture box's controls (making the picture box it's container) and it will show the picture box's image. If you do decide on painting the label text directly on the picture box, I recommend using the picture box's paint event in place of a sub routine. This way, the label text will automatically be re-painted when needed. Quote Member, in good standing, of the elite fraternity of mentally challenged programmers. Dolphins Software
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.