开发者

How to draw a rectangle in Compact Edtion?

开发者 https://www.devze.com 2022-12-12 20:23 出处:网络
I am trying to draw a rectangle on a windows mobile phone. Draw the rectangle Fill the rectangle with a color

I am trying to draw a rectangle on a windows mobile phone.

  1. Draw the rectangle
  2. Fill the rectangle with a color
  3. Draw it on to the phone.
  4. Give it a event handler that when a user clicks something happens.

I am unsure how do 开发者_JAVA百科steps 2, 3 and 4. I see that there is a drawing class called rectangle but I don't know how to get it on the form.

I then don't know how I could give it a event handler. I am planning to dynamically make like 12 of these so I have to somehow tell which one is clicked and the color it contains in it.

Thanks

Edit so far I have this but I don't see it on my form.

 Graphics surface = this.CreateGraphics();
    Pen pen = new Pen(Color.Black, 1f);
    System.Drawing.Rectangle test = new Rectangle(0, 0, 500, 500);
    surface.DrawRectangle(pen, test);


It sounds like you want a colored button. I think the easiest way to do this is to inherit from Control and override its Paint event.

public class ColoredButton : Control {
    protected override void OnPaint(PaintEventArgs e) {
        Graphics graphics = e.Graphics;
        Pen pen = new Pen(Color.Black, 1f);
        SolidBrush brush = new SolidBrush(Color.Red);

        graphics.FillRectangle(brush, 0, 0, Width, Height);
        graphics.DrawRectangle(pen, 0, 0, Width-1, Height-1);
    }
}

Now just hook into the native control Click event.

Or if you want fancier controls, take a look at this library

http://code.msdn.microsoft.com/uiframework

0

精彩评论

暂无评论...
验证码 换一张
取 消