Overriding Button Class Text.set and OnPaint

B

Ben

I'm having a really hard time trying to figure out how to override
the
drawing in my class derived from Button. When I set the text
property, the drawing seems to be taking place in the set method. I
try to override OnPaint and VS never even stops on my OnPaint
breakpoint. I try overriding set, but I have no idea how to get the
Graphics object from the control. I'm trying to develop games for
Windows Mobile 5.x, and it won't let me use the Control classes
CreateGraphics function.

Please help! Thank you!
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,


Ben said:
I'm having a really hard time trying to figure out how to override
the
drawing in my class derived from Button. When I set the text
property, the drawing seems to be taking place in the set method. I
try to override OnPaint and VS never even stops on my OnPaint
breakpoint. I try overriding set, but I have no idea how to get the
Graphics object from the control.

The second parameter of the onPaint gives you access to the Graphics
instance you need to use.


I'm trying to develop games for
Windows Mobile 5.x, and it won't let me use the Control classes
CreateGraphics function.

CF is a just a subset of the framework, there are a lot of classes/methods
not present.
 
B

Ben

Hi,




The second parameter of the onPaint gives you access to the Graphics
instance you need to use.

I'm trying to develop games for


CF is a just a subset of the framework, there are a lot of classes/methods
not present.

my OnPaint function never gets executed.
 
B

Ben

Here is my class:

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Text;

namespace System.Windows.Forms
{
class SButton: Button
{
List<int> small_nums = new List<int>();
int my_x;
int my_y;

public SButton(int new_my_x, int new_my_y)
{
my_x = new_my_x;
my_y = new_my_y;
}

public int get_my_x()
{
return my_x;
}

public int get_my_y()
{
return my_y;
}

public override string Text
{
get
{
return base.Text;
}
set
{
base.Text = value;
}
}

void draw_small_nums(PaintEventArgs p)
{
Graphics g = p.Graphics;
Font small_font = new Font(FontFamily.GenericSansSerif, 8,
FontStyle.Regular);
RectangleF small_text_rect = new RectangleF();
string small_nums_text;

foreach (int i in small_nums)
{
switch (i)
{
case 0: default:
small_nums_text = "0";
small_text_rect.X = 0;
small_text_rect.Y = 0;
break;
}

g.DrawString(small_nums_text, small_font, null,
small_text_rect);
}
}

public void add_small_num()
{
}

public void remove_small_num()
{
}

protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
draw_small_nums(e);
}
}
}
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

That;s weird, it should be executed

Is this a CF app ?
 
B

Ben

Hi,

That;s weird, it should be executed

Is this a CF app ?

Yes, it is a CF project, and I am using the Pocket PC Emulator to test
it on VS Orcas Beta 1.
If I switch the parent class from a Button to an Image, everything
works fine.
Apparently, not all of the standard controls use OnPaint().
Apparenty, Button is one of them for CF projects, but not for non CF
projects, beause I've seem several examples of where people override
the OnPaint function of Button.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

Ben said:
Yes, it is a CF project, and I am using the Pocket PC Emulator to test
it on VS Orcas Beta 1.

CF has a lot of restrictions. go to opennetcf.org and see the
owneddrawcontrol example there.

Additionally consider posting Cf related questions in the CF NG
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top