Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / October 2007

Tip: Looking for answers? Try searching our database.

Paint message fire galore

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jesper, Denmark - 25 Oct 2007 22:58 GMT
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.
Peter Duniho - 25 Oct 2007 23:49 GMT
Jesper wrote:
> [...]
> Normally I put my updation of data shown in the controls on the usercontrol
[quoted text clipped - 6 lines]
> 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
Jesper, Denmark - 26 Oct 2007 08:01 GMT
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.

> Jesper wrote:
> > [...]
[quoted text clipped - 33 lines]
>
> Pete
Peter Duniho - 26 Oct 2007 08:17 GMT
>  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 )
>       {
[quoted text clipped - 5 lines]
>       }
>  }

>  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

Signature

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

Jesper, Denmark - 26 Oct 2007 12:01 GMT
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.

> >  Thanks Peter,
>
[quoted text clipped - 31 lines]
>
> Pete

> I'm trying a new usenet client for Mac, Nemo OS X.
> You can download it at http://www.malcom-mac.com/nemo
Peter Duniho - 26 Oct 2007 17:47 GMT
>  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

Signature

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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.