By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,140 Members | 1,290 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,140 IT Pros & Developers. It's quick & easy.

Overriding Button Class Text.set and OnPaint

P: n/a
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!

Aug 14 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Hi,
"Ben" <mi**********@yahoo.comwrote in message
news:11**********************@19g2000hsx.googlegro ups.com...
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.
Aug 14 '07 #2

P: n/a
Ben
On Aug 14, 11:57 am, "Ignacio Machin \( .NET/ C# MVP \)" <machin TA
laceupsolutions.comwrote:
Hi,

"Ben" <mindslaye...@yahoo.comwrote in message

news:11**********************@19g2000hsx.googlegro ups.com...
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.
my OnPaint function never gets executed.

Aug 14 '07 #3

P: n/a
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<intsmall_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);
}
}
}

Aug 14 '07 #4

P: n/a
Hi,

That;s weird, it should be executed

Is this a CF app ?

"Ben" <mi**********@yahoo.comwrote in message
news:11*********************@o61g2000hsh.googlegro ups.com...
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<intsmall_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);
}
}
}

Aug 15 '07 #5

P: n/a
Ben
On Aug 15, 7:33 am, "Ignacio Machin \( .NET/ C# MVP \)" <machin TA
laceupsolutions.comwrote:
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.

Aug 15 '07 #6

P: n/a
Hi,

"Ben" <mi**********@yahoo.comwrote in message
news:11**********************@b79g2000hse.googlegr oups.com...
On Aug 15, 7:33 am, "Ignacio Machin \( .NET/ C# MVP \)" <machin TA
laceupsolutions.comwrote:
>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.
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
Aug 15 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.