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.
B4X:
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:
B4X:
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.
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.
I've been looking at the VS2005 docs. The page for Label.OnPaint does say "NET Compact Framework
Supported in: 2.0, 1.0", however on the Label members page the OnPaint protected method does not show the Compact Framework icon
The Panel members page OnPaint protected method does show the Compact Framework icon but leads to the generic Control.OnPaint page, not a specific one for Panel.OnPaint. This page also says "NET Compact Framework Supported in: 2.0, 1.0".
I'm thoroughly confused therefore as to how to interpret these documents as to what actually exists in the Compact Framework for a specific control. I'd suggest trying it on a Panel and see if it works there.
I did try that on a panel and same thing - if I could do it on the panel then it would be easy to surround each label with a "border" but alas I haven't got it to work
I do that:
I put in à Form of the designer a Label at the good position with a black background on this label I put an other one with 1 pixel less for the 4 sides!
Now my label is round with a frame black of one (or more) pixel.