I have some labels on a panel. I'd like to draw a line around them.
Is there a way to do this in C# for Smartdevice in VS2005?
I see examples on the net for the desktop label - it has a Borderstyle property but alas the humble compact one doesn't.
I've tried using a Graphics object but I get a null reference error. The Graphics object doesn't have a constructor so it won't compile if I instantiate a new one.
You probably need to override the OnPaint event and use the Graphics given to you in the PaintEventArgs. Note however that this is not my area of expertise. Also Google for Custom Controls - there's a lot of info out there.
Code:
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); // call the base class OnPaint e.Graphics.xxxx; // do your own thing; }
you could use the b4p form.line to draw a rectangle around any control, like this:
Code:
Form1.Line (Label1.Left-1,Label1.Top-1,Label1.Left+Label1.Width+1,Label1.Top+Label1.Height+1,cRed, B) 'Draws an empty red box
in c# you just need to set the label.borderstyle to one of these values:
None - default value
FixedSingle - draws a single-line rectangle around the control.
Fixed3D - Draws a 3d border on the control.
__________________
Paulo Gomes - Porto, Portugal - Living/Working in France
Mobile Device: Samsung Galaxy S, Android 2.3.4 CUstom ROM
Laptop: Toshiba NB100-130 (running on Win7Ultimate)
My Posts helped you? Consider Buying me a Porto Glass!
you could use the b4p form.line to draw a rectangle around any control,
I'm afraid he wants to draw on a Panel!
Quote:
in c# you just need to set the label.borderstyle
In the Compact Framework labels don't have a BorderStyle, as he indicated in his first post, so this is not possible.
You need to remember that there are significant differences (usually, but not always, omissions) between the full Framework on the desktop and the Compact Framework on the device so you can never make assumptions but need to check the documentation.
A work-around is to first draw an image and then put the label on top of the image. If the image is just slightly higher up, more to the left, wider and higher then you get the effect you want (I think). See jpg
No, you are mapping B4ppc concepts onto C# and it doesn't work like that. You need to create your own label class inheriting from Label (called subclassing), do it in there, and then use instances of your own Label class instead of Label. You could also do it by subclassing Panel and overriding its OnPaint method You are entering a large world here and I can't walk you through it and Windows Forms programming it is not my area of expertise anyway. You will have to do your own research, there is much to learn.
If you Google there are a lot of tutorials out there on the Web and you may need a couple of good books as well.