a question for erel or agraham or anyone else

Ricky D

Well-Known Member
Licensed User
Longtime User
Hi guys.

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.

any help would be appreciated.

regards, Ricky
 

agraham

Expert
Licensed User
Longtime User
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;
}
 

Cableguy

Expert
Licensed User
Longtime User
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.
 
Last edited:

agraham

Expert
Licensed User
Longtime User
you could use the b4p form.line to draw a rectangle around any control,
I'm afraid he wants to draw on a Panel!

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.
 

BjornF

Active Member
Licensed User
Longtime User
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

I know, it isn't very elegant but hey it works :)

all the best / Björn
 

Attachments

  • Labels.jpg
    Labels.jpg
    3.5 KB · Views: 189

BjornF

Active Member
Licensed User
Longtime User
Sorry, the example wasn't very clear, see this one instead. / Björn
 

Attachments

  • labels2.jpg
    labels2.jpg
    3.3 KB · Views: 197

bdiscount

Active Member
Licensed User
You can draw label with border and save as bmp etc, then load image to image or image button. there are some draw/paint progs here do a search.
 

Ricky D

Well-Known Member
Licensed User
Longtime User
overriding

hi agraham,

how do I override the onpaint event for each individual label?

would it be

protected override void la_OnPaint(PaintEventArgs e)

where la is the label?

regards, Ricky
 

agraham

Expert
Licensed User
Longtime User
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.
 

Ricky D

Well-Known Member
Licensed User
Longtime User
ok mate, thanks

I have come across some stuff on the net.

I'll see how I go.

regards, Ricky
 

Ricky D

Well-Known Member
Licensed User
Longtime User
umm... onPaint not firing

here is my simple attempt in C# to create a border around the label

B4X:
    public class MyLabel : Label
    {
        public MyLabel()
        {
            MessageBox.Show("here1");
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            MessageBox.Show("here");
            base.OnPaint(e);
            Pen MyPen = new Pen(Color.Black,2);
            e.Graphics.DrawRectangle(MyPen, this.Left, this.Top, this.Width, this.Height);
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
            }
            base.Dispose(disposing);
        }
    }

when I create the label the here1 message pops up. I never see the here message popup - it's the one inside the OnPaint override.

Any ideas anyone?

regards, Ricky
 

agraham

Expert
Licensed User
Longtime User
Any ideas anyone?
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 :confused:

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.
 

Ricky D

Well-Known Member
Licensed User
Longtime User
doesn't work on a panel

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 :(

regards, Ricky
 

JJM

Active Member
Licensed User
Longtime User
Hello,

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.

Best regards

JJ M
 
Top