473,407 Members | 2,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Paint message fire galore

Hi,

On a usercontrol I've put a set of radiobuttons within a groupbox. These
radiobuttons have visual style enables, i.e. they turn orange when hovering
over them and green when pushed.

Normally I put my updation of data shown in the controls on the usercontrol
in the Paint event handler of the usercontrol. When it comes to the
radiobuttons, a paint event for the usercontrol is fired whenever hovering
over the radiobuttons, making them impossible to change as they in the paint
event handler are set to reflect a given state.

Hoverver the problem is solved by putting the groupbox with the radiobuttons
on a panel on the usercontrol. The paint event for the control is now not
fired when hovering over it. Why?

Regards Jesper.
Oct 25 '07 #1
5 2064
Jesper wrote:
[...]
Normally I put my updation of data shown in the controls on the usercontrol
in the Paint event handler of the usercontrol. When it comes to the
radiobuttons, a paint event for the usercontrol is fired whenever hovering
over the radiobuttons, making them impossible to change as they in the paint
event handler are set to reflect a given state.

Hoverver the problem is solved by putting the groupbox with the radiobuttons
on a panel on the usercontrol. The paint event for the control is now not
fired when hovering over it. Why?
I don't know specifically. I suspect it has something to do with the
Panel buffering the drawing of the contained controls, but I can't say
for sure.

That said, the more general issue here is the question of what you
should or should not do in a Paint event handler. The answer to that
question is:

Should do: draw stuff
Should NOT do: anything else

The fact that you're doing something other than drawing in your paint
handler is the root cause of the issue you're seeing. Even if you can
avoid the immediate manifestation of the problem by moving the controls
to a Panel inside the UserControl, that doesn't mean you've addressed
the basic problem. It just means you've covered it up somehow. Who
knows when it will come back or how?

The correct solution is to change the flow of data, so that you only
Paint in response to changes in the data, and any updates to that data
is done in direct response to changes in the UI that are supposed to
update the data, rather than waiting until you have to redraw the UI to
propagate those changes.

Pete
Oct 25 '07 #2
Thanks Peter,

I have been using the paint event handler since MFC (I guess) to reflect my
data like this:

...._Paint(..)
{
textBox1.Text = someString;

//and

if ( true == foo )
{
radioButton1.Checked = true;
}
else
{
radioButton2.Checked = true;
}
}

Is this not good style?,
What's the alternative?

I appreciate the thread, it's quite important to me.
Regards Jesper.

"Peter Duniho" wrote:
Jesper wrote:
[...]
Normally I put my updation of data shown in the controls on the usercontrol
in the Paint event handler of the usercontrol. When it comes to the
radiobuttons, a paint event for the usercontrol is fired whenever hovering
over the radiobuttons, making them impossible to change as they in the paint
event handler are set to reflect a given state.

Hoverver the problem is solved by putting the groupbox with the radiobuttons
on a panel on the usercontrol. The paint event for the control is now not
fired when hovering over it. Why?

I don't know specifically. I suspect it has something to do with the
Panel buffering the drawing of the contained controls, but I can't say
for sure.

That said, the more general issue here is the question of what you
should or should not do in a Paint event handler. The answer to that
question is:

Should do: draw stuff
Should NOT do: anything else

The fact that you're doing something other than drawing in your paint
handler is the root cause of the issue you're seeing. Even if you can
avoid the immediate manifestation of the problem by moving the controls
to a Panel inside the UserControl, that doesn't mean you've addressed
the basic problem. It just means you've covered it up somehow. Who
knows when it will come back or how?

The correct solution is to change the flow of data, so that you only
Paint in response to changes in the data, and any updates to that data
is done in direct response to changes in the UI that are supposed to
update the data, rather than waiting until you have to redraw the UI to
propagate those changes.

Pete
Oct 26 '07 #3
In article <18**********************************@microsoft.co m>
Jesper,Denmark <Je***********@discussions.microsoft.comwrote:
Thanks Peter,
I have been using the paint event handler since MFC (I guess) to
reflect my data like this:
...._Paint(..)
{
textBox1.Text = someString;
//and
if ( true == foo )
{
radioButton1.Checked = true;
}
else
{
radioButton2.Checked = true;
}
}
Is this not good style?,
No, it's not a good style. Sorry to say, it was never a good style,
whether you were using MFC, or writing straight to the native Win32
API.
What's the alternative?
That's very hard to say without knowing what "someString" is and what
"foo" is. However, as a general rule of thumb, your design should be
changed so that when "someString" changes, that's where you set the
text in the TextBox, and when "foo" changes, that's where you change
the state of the RadioButton control.

Pete

--
I'm trying a new usenet client for Mac, Nemo OS X.
You can download it at http://www.malcom-mac.com/nemo

Oct 26 '07 #4
Ok, I can appreciate that. I guess that initial population of data into
controls should be moved to the Load event handler (?).

What do you put in the paint event handler then - GDI+ stuff?

regards Jesper.

"Peter Duniho" wrote:
In article <18**********************************@microsoft.co m>
Jesper,Denmark <Je***********@discussions.microsoft.comwrote:
Thanks Peter,
I have been using the paint event handler since MFC (I guess) to
reflect my data like this:
...._Paint(..)
{
textBox1.Text = someString;
//and
if ( true == foo )
{
radioButton1.Checked = true;
}
else
{
radioButton2.Checked = true;
}
}
Is this not good style?,

No, it's not a good style. Sorry to say, it was never a good style,
whether you were using MFC, or writing straight to the native Win32
API.
What's the alternative?

That's very hard to say without knowing what "someString" is and what
"foo" is. However, as a general rule of thumb, your design should be
changed so that when "someString" changes, that's where you set the
text in the TextBox, and when "foo" changes, that's where you change
the state of the RadioButton control.

Pete
--
I'm trying a new usenet client for Mac, Nemo OS X.
You can download it at http://www.malcom-mac.com/nemo

Oct 26 '07 #5
In article <7C**********************************@microsoft.co m>
Jesper,Denmark <Je***********@discussions.microsoft.comwrote:
Ok, I can appreciate that. I guess that initial population of data
into controls should be moved to the Load event handler (?).
What do you put in the paint event handler then - GDI+ stuff?
Yes. Only commands that are specifically involved with drawing (or
"painting", if you will :) ). Many forms and controls have no need
for a custom Paint handler. You should only create a Paint event
handler or override OnPaint in a Control-derived class if you have
some specific need to provide a custom visual representation of the
Control. Other tasks are much better handled elsewhere.

Pete

--
I'm trying a new usenet client for Mac, Nemo OS X.
You can download it at http://www.malcom-mac.com/nemo

Oct 26 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jesper | last post by:
Hi, Is there a way like in MFC's InvalidateRect function to call some function that in turns will fire a forms Paint event. The Paint event is fired automatically when you e.g. rezise your form...
5
by: vooose | last post by:
Consider a UserControl TopCont that contains two other UserControls, CompA and CompB. Somewhere in the constructor of TopCont we have CompA.Paint += new PaintEventHandler(compA_Paint);...
7
by: Schorschi | last post by:
I know there is a way to do this, but I don't know how. Via a custom event? I have some code that I only want to run during a paint event. I could build a form instance that has the code and...
6
by: jcrouse | last post by:
I am rotating some text is some label controls. In the one place I use it it works fine. In the other place I use it I can't figure out the syntax. I don't really understand the event. Where it...
1
by: James Ramaley | last post by:
I am trying to modify the way a NumericUpDown control draws itself. I just need to hide the up/down arrows. I tried overriding both the OnPaint method and the wm_paint message inside WndProc....
7
by: hamil | last post by:
The following code will display a tif file on a form. When another form is moved over the tif image, the tif image is erased where the form was moved. A paint event occurs when this happens. My...
13
by: Frank Rizzo | last post by:
I am creating a User Control that does a lot of it own painting from the UserControl_Paint event mostly using the e.Graphics object that's passed into Paint event. It works pretty good. ...
4
by: Sam | last post by:
Hai, I use a paintbox paint event to draw some images in a paintbox. I call the paint event by refreshing the paintbox using paintboxname.refresh() or paintboxname.update(). Problem with this...
1
by: ehabzaky | last post by:
Hi, I'm using some low level Win 32 API for some drawing functions on a picture box. I'm putting the drawing code in a method and call this method from the picture box paint event. The...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.