473,396 Members | 2,154 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,396 software developers and data experts.

Paint event

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.

Occasionally, the paint event doesn't fire. This occurs mostly in apps
with many 3rd party controls when the user presses Alt key the first
time. The problem doesn't occur after the 1st key press. I can't seem
to nail down where the problem is coming from.

Any and all ideas are welcome, as I am at the end of the rope.

Thanks.
Apr 11 '06 #1
13 2400
"Frank Rizzo" <no**@none.com> wrote in message
news:u$**************@TK2MSFTNGP04.phx.gbl...
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.

Occasionally, the paint event doesn't fire. This occurs mostly in apps
with many 3rd party controls when the user presses Alt key the first time.
The problem doesn't occur after the 1st key press. I can't seem to nail
down where the problem is coming from.

Any and all ideas are welcome, as I am at the end of the rope.


Try the onpaint override instead.

Michael
Apr 12 '06 #2
Michael C wrote:
"Frank Rizzo" <no**@none.com> wrote in message
news:u$**************@TK2MSFTNGP04.phx.gbl...
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.

Occasionally, the paint event doesn't fire. This occurs mostly in apps
with many 3rd party controls when the user presses Alt key the first time.
The problem doesn't occur after the 1st key press. I can't seem to nail
down where the problem is coming from.

Any and all ideas are welcome, as I am at the end of the rope.


Try the onpaint override instead.


Tried it. Same thing happened.
Apr 12 '06 #3
"Frank Rizzo" <no**@none.com> wrote in message
news:uq**************@TK2MSFTNGP05.phx.gbl...
Try the onpaint override instead.


Tried it. Same thing happened.


Do you do a this.Validate() anywhere in the paint? Can you post a simplified
sample that demonstrates the problem?
Apr 13 '06 #4
Michael C wrote:

"Frank Rizzo" &lt;no**@none.com&gt; wrote in message news:uq**************@TK2MSFTNGP05.phx.gbl...



Try the onpaint override instead.



Tried it. Same thing happened.



Do you do a this.Validate() anywhere in the paint? Can you post a simplified sample that demonstrates the problem?

Here is the sample.&nbsp; All this is inside of a user control.&nbsp; The control is inside another control which is inside a form.
The user presses Alt and then for about a second whatever I painted disappears and then reappears again (because the OnPaint event fired).


&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; private static Font _TextFont = new Font("Tahoma", 11f, FontStyle.Bold);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; private static Brush _TextBrush = new SolidBrush(SystemColors.Window);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; private static PointF _TextPoint = new PointF(6f, 2f);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; protected override void OnPaint(PaintEventArgs e)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp; PaintControlGradient(e);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; private void PaintControlGradient(PaintEventArgs e)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp; Color GradientBegin = Color.White;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp; Color GradientEnd = Color.Black;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp; Rectangle rect = new Rectangle(new Point(0, 0), this.Size);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp; LinearGradientBrush gradientBrush = new LinearGradientBrush(rect, GradientBegin, GradientEnd, 90f);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp; e.Graphics.FillRectangle(gradientBrush, rect);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp; e.Graphics.DrawString("Yeah", _TextFont, _TextBrush, _TextPoint);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
Apr 13 '06 #5
WRH

Maybe put an Invalidate in the control's OnLoad method?

"Frank Rizzo" <no**@none.com> wrote in message news:um**************@TK2MSFTNGP05.phx.gbl...
Michael C wrote:
"Frank Rizzo" <no**@none.com> wrote in message
news:uq**************@TK2MSFTNGP05.phx.gbl...
Try the onpaint override instead.
Tried it. Same thing happened.

Do you do a this.Validate() anywhere in the paint? Can you post a simplified
sample that demonstrates the problem?
Here is the sample. All this is inside of a user control. The control is inside another control which is inside a form.
The user presses Alt and then for about a second whatever I painted disappears and then reappears again (because the OnPaint event fired).
private static Font _TextFont = new Font("Tahoma", 11f, FontStyle.Bold);
private static Brush _TextBrush = new SolidBrush(SystemColors.Window);
private static PointF _TextPoint = new PointF(6f, 2f);

protected override void OnPaint(PaintEventArgs e)
{
PaintControlGradient(e);
}

private void PaintControlGradient(PaintEventArgs e)
{
Color GradientBegin = Color.White;
Color GradientEnd = Color.Black;

Rectangle rect = new Rectangle(new Point(0, 0), this.Size);
LinearGradientBrush gradientBrush = new LinearGradientBrush(rect, GradientBegin, GradientEnd, 90f);

e.Graphics.FillRectangle(gradientBrush, rect);
e.Graphics.DrawString("Yeah", _TextFont, _TextBrush, _TextPoint);
}

Apr 13 '06 #6
"Frank Rizzo" <no**@none.com> wrote in message
news:um**************@TK2MSFTNGP05.phx.gbl...
Here is the sample. All this is inside of a user control. The control is
inside another control which is inside a form.
The user presses Alt and then for about a second whatever I painted
disappears and then reappears again (because the
OnPaint event fired).


I can't reproduce the problem. I tried a UC in a UC in a form and even added
a menu because I presumed you had a menu. It all worked perfect on my
machine.

BTW, did you know this can be replaced

private static Brush _TextBrush = new SolidBrush(SystemColors.Window);

with

private static Brush _TextBrush = SystemBrushes.Window;
or Brushes.White if you just want white.

It has the added advantage that it doesn't need to be disposed.

Michael
Apr 13 '06 #7
Michael C wrote:
"Frank Rizzo" <no**@none.com> wrote in message
news:um**************@TK2MSFTNGP05.phx.gbl...
Here is the sample. All this is inside of a user control. The control is
inside another control which is inside a form.
The user presses Alt and then for about a second whatever I painted
disappears and then reappears again (because the
OnPaint event fired).
I can't reproduce the problem. I tried a UC in a UC in a form and even added
a menu because I presumed you had a menu. It all worked perfect on my
machine.


I can't repro the problem in my test app either. But it sure happens in
the main app. Maybe I'll make a small video and post it here, so you
can see what's going on.

BTW, did you know this can be replaced

private static Brush _TextBrush = new SolidBrush(SystemColors.Window);

with

private static Brush _TextBrush = SystemBrushes.Window;
Oh, thanks. I actually looked for that and couldn't find it. I'll have
to talk to my intellisense. I do see it now.
or Brushes.White if you just want white.

It has the added advantage that it doesn't need to be disposed.

Michael

Apr 14 '06 #8
In case anyone is interested, I solved the issue by turning
DoubleBuffered property to True on the control. Somehow magically, the
problem went away.

Yeah.
Apr 15 '06 #9
"Frank Rizzo" <no**@none.com> wrote in message
news:Oa**************@TK2MSFTNGP03.phx.gbl...
In case anyone is interested, I solved the issue by turning DoubleBuffered
property to True on the control. Somehow magically, the problem went
away.


That's not really a solution. This will use large amounts of memory as the
control will create a bitmap the size of the control. It will also slow your
paint speed down potentially to half I believe, which is a problem as
painting in dot net is slow enough as it is :-)

Michael
Apr 15 '06 #10
Michael C wrote:
"Frank Rizzo" <no**@none.com> wrote in message
news:Oa**************@TK2MSFTNGP03.phx.gbl...
In case anyone is interested, I solved the issue by turning DoubleBuffered
property to True on the control. Somehow magically, the problem went
away.
That's not really a solution. This will use large amounts of memory as the
control will create a bitmap the size of the control. It will also slow your
paint speed down potentially to half I believe, which is a problem as
painting in dot net is slow enough as it is :-)


Actually, it sped the living hell out of it (or at least perceived
speed). And got rid of my problem. I'll still make a video out of the
old method.

Michael

Apr 15 '06 #11
"Frank Rizzo" <no****@nospam.com> wrote in message
news:eP**************@TK2MSFTNGP02.phx.gbl...
Actually, it sped the living hell out of it (or at least perceived speed).
It does make it look a lot quicker but I don't think it will actually be
quicker. It has to paint to the buffer and then paint the buffer to the
control. I'm trying to get something similar working at the moment and I
tried with and without double buffer and found it to be slower.
And got rid of my problem.


Is it possible that some code was executing during the time when it was
unpainted that was causing the paint event to not be called?

Michael
Apr 15 '06 #12
Michael C wrote:
"Frank Rizzo" <no****@nospam.com> wrote in message
news:eP**************@TK2MSFTNGP02.phx.gbl...
Actually, it sped the living hell out of it (or at least perceived speed).
It does make it look a lot quicker but I don't think it will actually be
quicker. It has to paint to the buffer and then paint the buffer to the
control. I'm trying to get something similar working at the moment and I
tried with and without double buffer and found it to be slower.
And got rid of my problem.

Is it possible that some code was executing during the time when it was
unpainted that was causing the paint event to not be called?


Doubtful, the user control has its own window handle, so it would
process its own events. Besides the problem is reproducible 100% by
just pressing Alt. Perhaps other controls on the forms respond to it as
well causing the slowdown.

Michael

Apr 17 '06 #13
"Frank Rizzo" <no****@nospam.com> wrote in message
news:OX**************@TK2MSFTNGP02.phx.gbl...
Doubtful, the user control has its own window handle, so it would process
its own events.
The application has only one message loop and won't process any of the
messages in the loop while the app is using 100% cpu in the main thread. A
WM_PAINT message could be sitting in the loop and will be ignored until the
app becomes idle. You can test this by doing a sleep(30000) and dragging a
windows over your app, nothing will get repainted. WinXP does do some tricks
to make it loop like the app is painting itself but it's actually XP doing
the painting.
Besides the problem is reproducible 100% by just pressing Alt. Perhaps
other controls on the forms respond to it as well causing the slowdown.


Although I agree it is likely the 100% cpu isn't the cause, it could be the
WM_PAINT message being dropped in certain circumstances.

Michael
Apr 19 '06 #14

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

Similar topics

5
by: Tamir Khason | last post by:
How I can paint something onClick event? I need PaintEventArgs event in order to paint and raise Graphics, but onClick I have only EventArgs Event... Thanx
4
by: Tamir Khason | last post by:
Why when I lost focus (go to back) on form all GDI+ paints disappears..... BUG or I do something wrong???? TNX
2
by: Rene | last post by:
Currently, the paint even will only acknowledge painting going on inside of the ClipRectangle, any of the drawing that is outside of the ClipRectangle is ignored. How can I get the paint...
3
by: pacemkr | last post by:
Is it possible to force a control to paint to a Graphics object (or Device Context, or a bitmap, anywhere aside from the form) that I provide. I am writing a windows form class that supports...
8
by: WStoreyII | last post by:
i am using this code to try to paint a line on my form and it wont work i get an object not set to a reference error Dim myPen As New System.Drawing.Pen(System.Drawing.Color.Red) Dim...
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...
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...
4
by: Kürşat | last post by:
Hi all, I do some drawing in a form's paint event handler and I have a button on that form. Whenever the mouse enters or leaves the button Form's paint event occurs. Isn't that a strange...
7
by: Rotsey | last post by:
Hi, I have a interface that I use for a form so I can pass the form to another object. How do I add the Paint event to the interface and subsequently handle the paint event in my other...
5
by: =?Utf-8?B?SmVzcGVyLCBEZW5tYXJr?= | last post by:
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. ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.