Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
C# Control - Transparent Label
Message
De
09/10/2007 20:32:35
 
Information générale
Forum:
ASP.NET
Catégorie:
Formulaires
Divers
Thread ID:
01259615
Message ID:
01259918
Vues:
26
>Thanks for the code. I'll try it

You're welcome. Let me know if it works good enough for what you're trying to do.

>My point in comparing C# to VFP is that one would think that I would have more flexability in C# than I had in VFP. Something as simple as a transparent control is native to VFP.

Yes, but my point is that it works fine when placed in a proper container control ... a Form, a UserControl, a Panel. Just not for a PictureBox. I got it to work just fine by simply setting the BackColor to Transparent, didn't even have to bother with the SetStyle() method).

Anywho ... lemme know.

~~Bonnie


>
>Anyhow, thanks
>
>
>
>
>>This isn't your grandpa's FoxPro ... <g>
>>
>>Things are different in .NET, I guess you better get used to it. <g>
>>
>>As I said, the transparent background of the Label will be painted by it's parent. In this case, the parent of your Label is the Panel, not the PictureBox (you'd see how this works if you add a background image to the panel instead of putting it in the PictureBox).
>>
>>But, at any rate, if you want to put some text on a PictureBox, the only methodology that I can seem to find (and I Googled around a bit), is to handle the Paint event of the PictureBox. Try this, it works, I've already tested it (you won't see it at design time, but you will at runtime):
>>
>>
>>this.pictureBox1.Paint += new PaintEventHandler(pictureBox1_Paint);
>>
>>private void pictureBox1_Paint(object sender, PaintEventArgs e)
>>{
>>	e.Graphics.DrawString("HELLO WORLD!", new Font("Arial", 13), Brushes.Aquamarine, 20, 20);
>>}
>>
>>
>>~~Bonnie
>>
>>
>>>My project is one day old, and I'm hung up by something that is a mouse click in VFP.
>>>
>>>When I said I have no code I meant I havn't added any code. All I'v done is drop a panel and some images onto the form.
>>>
>>>I sent you an email. I must be missing something because this can't be that difficult.
>>>
>>>
>>>
>>>
>>>
>>>
>>>>>I have no code.
>>>>
>>>>Well, of course there's code Kevin ... the code that's generated in the Designer.cs. But, nevermind ... this seems to work fine if the parent is a Form, or a Panel, or some other Control, but it doesn't seem to work if the parent is a PictureBox. There's a note on that link you showed that says this:
>>>>
>>>>Windows Forms controls do not support true transparency. The background of a transparent Windows Forms control is painted by its parent.
>>>>
>>>>The problem is this ... the label's parent is the Panel, not the PictureBox. I'm not sure you can make the PictureBox the parent of the label.
>>>>
>>>>~~Bonnie
>>>>
>>>>
>>>>
>>>>
>>>>>
>>>>>All I have done so far is place a Panel control on a form. I then added a PictureBox in the panel and set it's Image to a blue verticle gradient.
>>>>>
>>>>>I then placed a label in the Panel, over the gradient image, near the top. The label's background appears as a white rectangle.
>>>>>
>>>>>My website is down, othewise I would post a screenshot.
>>>>>
>>>>>As far as that code I found - I'm not sure where this code goes.
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>>Kevin,
>>>>>>
>>>>>>That article seems pretty straightforward to me, I'm not sure what you're not understanding.
>>>>>>
>>>>>>How about we try this ... post the relevant code here and maybe we'll be able to spot the problem.
>>>>>>
>>>>>>~~Bonnie
>>>>>>
>>>>>>
>>>>>>
>>>>>>>I'm still not getting it. Why can't I make a label transparent????
>>>>>>>
>>>>>>>I found this article, but I need help understanding what it's telling me to do.
>>>>>>>http://msdn2.microsoft.com/en-us/library/wk5b13s4.aspx
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>>You'd need to set the control style to support transparency
>>>>>>>>
>>>>>>>>
>>>>>>>> private bool _HacerTransparente;
>>>>>>>>        public bool HacerTransparente
>>>>>>>>        {
>>>>>>>>            get { return _HacerTransparente; }
>>>>>>>>            set
>>>>>>>>            {
>>>>>>>>                _HacerTransparente = value;
>>>>>>>>
>>>>>>>>                this.SetStyle(ControlStyles.SupportsTransparentBackColor, _HacerTransparente);
>>>>>>>>                if (_HacerTransparente)
>>>>>>>>                {
>>>>>>>>                    BackColor = Color.Transparent ;
>>>>>>>>                }
>>>>>>>>                else
>>>>>>>>                {
>>>>>>>>                    BackColor = BackGroundColor;
>>>>>>>>                }
>>>>>>>>            }
>>>>>>>>        }
>>>>>>>>
>>>>>>>>
>>>>>>>>HTH,
>>>>>>>>
>>>>>>>>Enmanuel
>>>>>>>>
>>>>>>>>>I have tried both, and it has no effect. The label is not transparent.
>>>>>>>>>
>>>>>>>>>I have a panel control with a picturebox in it of a gradient. The label is then on top of the gradient. The label appears as black text inside a white rectangle.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>>>How do I set the background of a label to transparent?
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>this.MyLabel.BackColor = System.Drawing.Color.Transparent;
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>Or, from the PropertySheet's color picker, choose the Web tab to find the Transparent color.
>>>>>>>>>>
>>>>>>>>>>~~Bonnie
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform