[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

=?Utf-8?B?VG9kZCBCcmlnaHQ=?=

1/17/2005 3:29:00 PM

I've got a UserControl that I've created and I am handling all painting. I'm
using the following line of code:

SetStyle( ControlStyles.DoubleBuffer |
ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true );

The problem is that when I add this line into my control's Load() event, the
control doesn't paint until I mouse over it. In addition, when I drag a
window over it, the control either doesn't repaint at all or repaints
partially. Everything seems to work great without this line of code??? Is
there anything else I need to do to enable double buffering? Any extra
events, some special code in the paint event?

Thanks,
Todd


13 Answers

Sean Hederman

1/17/2005 3:46:00 PM

0

Todd,

I don't know if this'll help, but I always put the SetStyle call in the
OnHandleCreated override, just after calling base.OnHandleCreated.

"Todd Bright" <ToddBright@discussions.microsoft.com> wrote in message
news:751B2DEA-0308-4769-BF65-E97B1FEF4517@microsoft.com...
> I've got a UserControl that I've created and I am handling all painting.
> I'm
> using the following line of code:
>
> SetStyle( ControlStyles.DoubleBuffer |
> ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true );
>
> The problem is that when I add this line into my control's Load() event,
> the
> control doesn't paint until I mouse over it. In addition, when I drag a
> window over it, the control either doesn't repaint at all or repaints
> partially. Everything seems to work great without this line of code???
> Is
> there anything else I need to do to enable double buffering? Any extra
> events, some special code in the paint event?
>
> Thanks,
> Todd
>
>


=?Utf-8?B?VG9kZCBCcmlnaHQ=?=

1/17/2005 4:31:00 PM

0

Same problem. Buttons don't draw until I mouse over them. I've got the
following lines...

this.SetStyle(ControlStyles.DoubleBuffer |
ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.ResizeRedraw, true);
this.UpdateStyles();

I've tried them in the Load() and OnHandleCreated() events. Both exhibit
the same incorrect results. I can't help but think that it is the UserPaint
style that is causing this. Is there some other call I need to be making in
another event to tell the control to draw itself when first displayed?


"Sean Hederman" wrote:

> Todd,
>
> I don't know if this'll help, but I always put the SetStyle call in the
> OnHandleCreated override, just after calling base.OnHandleCreated.
>
> "Todd Bright" <ToddBright@discussions.microsoft.com> wrote in message
> news:751B2DEA-0308-4769-BF65-E97B1FEF4517@microsoft.com...
> > I've got a UserControl that I've created and I am handling all painting.
> > I'm
> > using the following line of code:
> >
> > SetStyle( ControlStyles.DoubleBuffer |
> > ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true );
> >
> > The problem is that when I add this line into my control's Load() event,
> > the
> > control doesn't paint until I mouse over it. In addition, when I drag a
> > window over it, the control either doesn't repaint at all or repaints
> > partially. Everything seems to work great without this line of code???
> > Is
> > there anything else I need to do to enable double buffering? Any extra
> > events, some special code in the paint event?
> >
> > Thanks,
> > Todd
> >
> >
>
>
>

Mick Doherty

1/17/2005 6:49:00 PM

0

I always put the SetStyle call in the constructor, but I don't think that's
the problem.

I know it doesn't help, but I think you'll find that this problem may
disappear on another system. I have no Idea what causes it, but I have heard
of the problem. Unfortunately, I cannot reproduce this behaviour on my
system.
I would like to know what causes it though, as anything I write and
distribute may exhibit this behaviour on an end users PC. If I can't
reproduce it then how can I repair it?

Just out of curiosity:
Does this simple Paint method result in the same effect?

\\using System.Drawing.Drawing2D;

protected override void OnPaint (PaintEventArgs e)
{
Rectangle r = this.ClientRectangle;
LinearGradientBrush brush = new LinearGradientBrush(r, Color.Blue,
Color.Green,LinearGradientMode.ForwardDiagonal);
e.Graphics.FillRectangle(brush, r);
brush.Dispose();
}
///

If not, can you reproduce the problem in a similarly simple example?

--
Mick Doherty
http://dotnetrix.co.uk/no...


"Todd Bright" <ToddBright@discussions.microsoft.com> wrote in message
news:8D066891-8E10-49D8-8CE7-BA74363BF485@microsoft.com...
> Same problem. Buttons don't draw until I mouse over them. I've got the
> following lines...
>
> this.SetStyle(ControlStyles.DoubleBuffer |
> ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true);
> this.SetStyle(ControlStyles.ResizeRedraw, true);
> this.UpdateStyles();
>
> I've tried them in the Load() and OnHandleCreated() events. Both exhibit
> the same incorrect results. I can't help but think that it is the
> UserPaint
> style that is causing this. Is there some other call I need to be making
> in
> another event to tell the control to draw itself when first displayed?
>
>
> "Sean Hederman" wrote:
>
>> Todd,
>>
>> I don't know if this'll help, but I always put the SetStyle call in the
>> OnHandleCreated override, just after calling base.OnHandleCreated.
>>
>> "Todd Bright" <ToddBright@discussions.microsoft.com> wrote in message
>> news:751B2DEA-0308-4769-BF65-E97B1FEF4517@microsoft.com...
>> > I've got a UserControl that I've created and I am handling all
>> > painting.
>> > I'm
>> > using the following line of code:
>> >
>> > SetStyle( ControlStyles.DoubleBuffer |
>> > ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true );
>> >
>> > The problem is that when I add this line into my control's Load()
>> > event,
>> > the
>> > control doesn't paint until I mouse over it. In addition, when I drag
>> > a
>> > window over it, the control either doesn't repaint at all or repaints
>> > partially. Everything seems to work great without this line of code???
>> > Is
>> > there anything else I need to do to enable double buffering? Any extra
>> > events, some special code in the paint event?
>> >
>> > Thanks,
>> > Todd
>> >
>> >
>>
>>
>>


=?Utf-8?B?VG9kZCBCcmlnaHQ=?=

1/17/2005 7:19:00 PM

0

Yep, still happens. Thought that maybe it was because I'm calling the
drawing code in another procedure from the Paint event that it may be causing
the problem. Moved your code to the Paint event... same thing. Seems like
there are a few "unknown" answers to problems like this floating around.
Wonder how Microsoft and the other 3rd party control writers get theirs to
work???

"Mick Doherty" wrote:

> I always put the SetStyle call in the constructor, but I don't think that's
> the problem.
>
> I know it doesn't help, but I think you'll find that this problem may
> disappear on another system. I have no Idea what causes it, but I have heard
> of the problem. Unfortunately, I cannot reproduce this behaviour on my
> system.
> I would like to know what causes it though, as anything I write and
> distribute may exhibit this behaviour on an end users PC. If I can't
> reproduce it then how can I repair it?
>
> Just out of curiosity:
> Does this simple Paint method result in the same effect?
>
> \\> using System.Drawing.Drawing2D;
>
> protected override void OnPaint (PaintEventArgs e)
> {
> Rectangle r = this.ClientRectangle;
> LinearGradientBrush brush = new LinearGradientBrush(r, Color.Blue,
> Color.Green,LinearGradientMode.ForwardDiagonal);
> e.Graphics.FillRectangle(brush, r);
> brush.Dispose();
> }
> ///
>
> If not, can you reproduce the problem in a similarly simple example?
>
> --
> Mick Doherty
> http://dotnetrix.co.uk/no...
>
>
> "Todd Bright" <ToddBright@discussions.microsoft.com> wrote in message
> news:8D066891-8E10-49D8-8CE7-BA74363BF485@microsoft.com...
> > Same problem. Buttons don't draw until I mouse over them. I've got the
> > following lines...
> >
> > this.SetStyle(ControlStyles.DoubleBuffer |
> > ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true);
> > this.SetStyle(ControlStyles.ResizeRedraw, true);
> > this.UpdateStyles();
> >
> > I've tried them in the Load() and OnHandleCreated() events. Both exhibit
> > the same incorrect results. I can't help but think that it is the
> > UserPaint
> > style that is causing this. Is there some other call I need to be making
> > in
> > another event to tell the control to draw itself when first displayed?
> >
> >
> > "Sean Hederman" wrote:
> >
> >> Todd,
> >>
> >> I don't know if this'll help, but I always put the SetStyle call in the
> >> OnHandleCreated override, just after calling base.OnHandleCreated.
> >>
> >> "Todd Bright" <ToddBright@discussions.microsoft.com> wrote in message
> >> news:751B2DEA-0308-4769-BF65-E97B1FEF4517@microsoft.com...
> >> > I've got a UserControl that I've created and I am handling all
> >> > painting.
> >> > I'm
> >> > using the following line of code:
> >> >
> >> > SetStyle( ControlStyles.DoubleBuffer |
> >> > ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true );
> >> >
> >> > The problem is that when I add this line into my control's Load()
> >> > event,
> >> > the
> >> > control doesn't paint until I mouse over it. In addition, when I drag
> >> > a
> >> > window over it, the control either doesn't repaint at all or repaints
> >> > partially. Everything seems to work great without this line of code???
> >> > Is
> >> > there anything else I need to do to enable double buffering? Any extra
> >> > events, some special code in the paint event?
> >> >
> >> > Thanks,
> >> > Todd
> >> >
> >> >
> >>
> >>
> >>
>
>
>

Mick Doherty

1/17/2005 8:10:00 PM

0

Which style it is that causes the problem (DoubleBuffer, UserPaint or
AllPaintingInWMPaint)

You may find that the control behaves differently when you build a release
version and run that instead (I have noticed differences in painting between
Debug and Release Apps, although they appear the same when run from within
the IDE).

--
Mick Doherty
http://dotnetrix.co.uk/no...


"Todd Bright" <ToddBright@discussions.microsoft.com> wrote in message
news:4AE8BA62-F59C-457C-B1BB-44407B1C77E9@microsoft.com...
> Yep, still happens. Thought that maybe it was because I'm calling the
> drawing code in another procedure from the Paint event that it may be
> causing
> the problem. Moved your code to the Paint event... same thing. Seems
> like
> there are a few "unknown" answers to problems like this floating around.
> Wonder how Microsoft and the other 3rd party control writers get theirs to
> work???


John Parrish

1/17/2005 9:16:00 PM

0

Mick Doherty wrote:
> Which style it is that causes the problem (DoubleBuffer, UserPaint or
> AllPaintingInWMPaint)
>
> You may find that the control behaves differently when you build a release
> version and run that instead (I have noticed differences in painting between
> Debug and Release Apps, although they appear the same when run from within
> the IDE).
>

I've seen this in some of my code too.. the best thing I could think was
that the last thing to be drawn is drawn in the buffer and for whatever
reason the buffer isn't painted. Maybe check Update() in addition to
invalidate, but that never seemed to work for me.

=?Utf-8?B?VG9kZCBCcmlnaHQ=?=

1/17/2005 9:25:00 PM

0

It is the AllPaintingInWmPaint style that is causing the problem. I've got
the control on a Panel, not directly on a form. When the screen draws
initially the buttons are there but then they disappear and all you can see
is the Panel background color. Well, tried putting it directly on a form and
it did the same thing.

I've also tried running the EXE itself, in both debug and release... same
thing. Could there be something in the paint code that's causing this? Like
I said, it works just fine without the styles set. Doesn't seem to flicker
or anything. Just thought I'd put this in to avoid any potential issues with
it on other machines.


"Mick Doherty" wrote:

> Which style it is that causes the problem (DoubleBuffer, UserPaint or
> AllPaintingInWMPaint)
>
> You may find that the control behaves differently when you build a release
> version and run that instead (I have noticed differences in painting between
> Debug and Release Apps, although they appear the same when run from within
> the IDE).
>
> --
> Mick Doherty
> http://dotnetrix.co.uk/no...
>
>
> "Todd Bright" <ToddBright@discussions.microsoft.com> wrote in message
> news:4AE8BA62-F59C-457C-B1BB-44407B1C77E9@microsoft.com...
> > Yep, still happens. Thought that maybe it was because I'm calling the
> > drawing code in another procedure from the Paint event that it may be
> > causing
> > the problem. Moved your code to the Paint event... same thing. Seems
> > like
> > there are a few "unknown" answers to problems like this floating around.
> > Wonder how Microsoft and the other 3rd party control writers get theirs to
> > work???
>
>
>

Frank Hileman

1/17/2005 10:26:00 PM

0

Could it be the clipping rectangle? This must be set explicitly in your
paint.

Regards,
Frank Hileman

check out VG.net: http://www.vg...
Animated vector graphics system
Integrated Visual Studio .NET graphics editor

"Todd Bright" <ToddBright@discussions.microsoft.com> wrote in message
news:EDEC6AF6-4013-4AE1-BB57-EFFE0B28E21B@microsoft.com...
> It is the AllPaintingInWmPaint style that is causing the problem. I've
> got
> the control on a Panel, not directly on a form. When the screen draws
> initially the buttons are there but then they disappear and all you can
> see
> is the Panel background color. Well, tried putting it directly on a form
> and
> it did the same thing.
>
> I've also tried running the EXE itself, in both debug and release... same
> thing. Could there be something in the paint code that's causing this?
> Like
> I said, it works just fine without the styles set. Doesn't seem to
> flicker
> or anything. Just thought I'd put this in to avoid any potential issues
> with
> it on other machines.


Mick Doherty

1/17/2005 11:24:00 PM

0

According to MSDN AllPaintingInWMPaint causes the control to ignore the
WM_ERASEBKGND message to help remove flicker.

Looking at the messages in WNDPROC(), imediately after a WM_ERASEBKGND
message there is a WM_PAINT message, so it should not cause a problem.

Is that what you are seeing in the output window with the following code?

Hashtable messages = new Hashtable();
protected override void WndProc(ref Message m)
{
base.WndProc (ref m);
if (!messages.Contains(m.Msg))
{
messages.Add(m.Msg,m.Msg);
System.Diagnostics.Debug.WriteLine(m.ToString());
}
}


Does it help to do this? (I don't know if it's recommended, but anythings
worth a shot.)

protected override void OnPaintBackground(PaintEventArgs pevent)
{
//base.OnPaintBackground (pevent);
base.OnPaint(pevent);
}


--
Mick Doherty
http://dotnetrix.co.uk/no...


"Todd Bright" <ToddBright@discussions.microsoft.com> wrote in message
news:EDEC6AF6-4013-4AE1-BB57-EFFE0B28E21B@microsoft.com...
> It is the AllPaintingInWmPaint style that is causing the problem. I've
> got
> the control on a Panel, not directly on a form. When the screen draws
> initially the buttons are there but then they disappear and all you can
> see
> is the Panel background color. Well, tried putting it directly on a form
> and
> it did the same thing.
>
> I've also tried running the EXE itself, in both debug and release... same
> thing. Could there be something in the paint code that's causing this?
> Like
> I said, it works just fine without the styles set. Doesn't seem to
> flicker
> or anything. Just thought I'd put this in to avoid any potential issues
> with
> it on other machines.
>
>
> "Mick Doherty" wrote:
>
>> Which style it is that causes the problem (DoubleBuffer, UserPaint or
>> AllPaintingInWMPaint)
>>
>> You may find that the control behaves differently when you build a
>> release
>> version and run that instead (I have noticed differences in painting
>> between
>> Debug and Release Apps, although they appear the same when run from
>> within
>> the IDE).
>>
>> --
>> Mick Doherty
>> http://dotnetrix.co.uk/no...
>>
>>
>> "Todd Bright" <ToddBright@discussions.microsoft.com> wrote in message
>> news:4AE8BA62-F59C-457C-B1BB-44407B1C77E9@microsoft.com...
>> > Yep, still happens. Thought that maybe it was because I'm calling the
>> > drawing code in another procedure from the Paint event that it may be
>> > causing
>> > the problem. Moved your code to the Paint event... same thing. Seems
>> > like
>> > there are a few "unknown" answers to problems like this floating
>> > around.
>> > Wonder how Microsoft and the other 3rd party control writers get theirs
>> > to
>> > work???
>>
>>
>>


Frank Hileman

1/18/2005 12:09:00 AM

0

I think setting these style bits outside the constructor may be causing the
problem. Try moving it to the constructor.

Regards,
Frank Hileman

check out VG.net: http://www.vg...
Animated vector graphics system
Integrated Visual Studio .NET graphics editor

"Todd Bright" <ToddBright@discussions.microsoft.com> wrote in message
news:EDEC6AF6-4013-4AE1-BB57-EFFE0B28E21B@microsoft.com...
> It is the AllPaintingInWmPaint style that is causing the problem. I've
> got
> the control on a Panel, not directly on a form. When the screen draws
> initially the buttons are there but then they disappear and all you can
> see
> is the Panel background color. Well, tried putting it directly on a form
> and
> it did the same thing.
>
> I've also tried running the EXE itself, in both debug and release... same
> thing. Could there be something in the paint code that's causing this?
> Like
> I said, it works just fine without the styles set. Doesn't seem to
> flicker
> or anything. Just thought I'd put this in to avoid any potential issues
> with
> it on other machines.