473,498 Members | 2,023 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

When to redraw control?

Hi all!

I've made a simple control derived from a panel class which draws gradient
in a overrided OnPaintBackground event.
Well, I know that I need to redraw control when it's resized by overriding
OnResize event, but
how would I know when to redraw if, let's say, user drags some form over it
or some other action that messes display of this control.

I'm stuck here ... what to do?

Thanks in advance! Take care!

D.
Nov 16 '05 #1
5 11053
The OnPaintBackground and OnPaint overrides should be called automatically
when a control needs to be repainted after it has been obscured. Just as an
option, you may also use the protected SetStyle() method and the
ControlStyles.ResizeRedraw enum value to have your control repainted when it
is resized instead of using the OnResize override.
http://msdn.microsoft.com/library/de...styletopic.asp

--
Tim Wilson
..Net Compact Framework MVP

"CroDude" <di***********@zg.htnet.hr> wrote in message
news:d0**********@news1.xnet.hr...
Hi all!

I've made a simple control derived from a panel class which draws gradient
in a overrided OnPaintBackground event.
Well, I know that I need to redraw control when it's resized by overriding
OnResize event, but
how would I know when to redraw if, let's say, user drags some form over it or some other action that messes display of this control.

I'm stuck here ... what to do?

Thanks in advance! Take care!

D.

Nov 16 '05 #2
Thanks for help, but unfortunately that didn't do it.
Every time when I drag some other form above that panel or if I hide child
control there are glitches in the drawing of the panel control.

Here is my drawing code:

protected override void OnPaint(PaintEventArgs e)
{
// If drawOutline is true, draw outline around toolbar
if(this.drawOutline)
{
// Set rectangle for drawing
Rectangle drawRectangle = e.ClipRectangle;
// Create pen with outlineColor applied
Pen outlinePen = new Pen(this.outlineColor, 2);
// Draw outline
e.Graphics.DrawRectangle(outlinePen, drawRectangle.X ,
drawRectangle.Y , drawRectangle.Width , drawRectangle.Height );
}
else
{
base.OnPaint(e);
}
}

and:

protected override void OnPaintBackground(PaintEventArgs e)
{
if(this.drawGradientBackground)
{
// Set gradient brush
LinearGradientBrush brush = new LinearGradientBrush(e.ClipRectangle,
this.gradientColorA, this.gradientColorB, this.gradientMode);
// Draw the gradient background.
e.Graphics.FillRectangle(brush, e.ClipRectangle);
}
else
{
base.OnPaintBackground (e);
}
}
Nov 16 '05 #3
Don't use e.ClipRectangle, use this.ClientRectangle instead. ClipRectangle
will return the exact area to paint. In other words, it will return only the
portion of the control that is invalidated and needs to be redrawn. However,
you were painting the entire control into this invalidated region. See the
modified code below.

protected override void OnPaintBackground(PaintEventArgs e)
{
base.OnPaintBackground(e);
if(this.drawGradientBackground)
{
// Set gradient brush.
LinearGradientBrush brush = new
LinearGradientBrush(this.ClientRectangle, this.gradientColorA,
this.gradientColorB, this.gradientMode);
// Draw the gradient background.
e.Graphics.FillRectangle(brush, this.ClientRectangle);
// Dispose.
brush.Dispose();
}
}

protected override void OnPaint(PaintEventArgs e)
{
// If drawOutline is true, draw outline around toolbar.
if(this.drawOutline)
{
// Create pen with outlineColor applied.
Pen outlinePen = new Pen(this.outlineColor, 2);
// Draw outline.
e.Graphics.DrawRectangle(outlinePen, this.ClientRectangle);
// Dispose.
outlinePen.Dispose();
}
// Fires the Paint event.
base.OnPaint(e);
}

--
Tim Wilson
..Net Compact Framework MVP

"CroDude" <di***********@zg.htnet.hr> wrote in message
news:d0**********@news1.xnet.hr...
Thanks for help, but unfortunately that didn't do it.
Every time when I drag some other form above that panel or if I hide child
control there are glitches in the drawing of the panel control.

Here is my drawing code:

protected override void OnPaint(PaintEventArgs e)
{
// If drawOutline is true, draw outline around toolbar
if(this.drawOutline)
{
// Set rectangle for drawing
Rectangle drawRectangle = e.ClipRectangle;
// Create pen with outlineColor applied
Pen outlinePen = new Pen(this.outlineColor, 2);
// Draw outline
e.Graphics.DrawRectangle(outlinePen, drawRectangle.X ,
drawRectangle.Y , drawRectangle.Width , drawRectangle.Height );
}
else
{
base.OnPaint(e);
}
}

and:

protected override void OnPaintBackground(PaintEventArgs e)
{
if(this.drawGradientBackground)
{
// Set gradient brush
LinearGradientBrush brush = new LinearGradientBrush(e.ClipRectangle, this.gradientColorA, this.gradientColorB, this.gradientMode);
// Draw the gradient background.
e.Graphics.FillRectangle(brush, e.ClipRectangle);
}
else
{
base.OnPaintBackground (e);
}
}

Nov 16 '05 #4
Dam' it, that was under my nose! Heh ... thanks Tim! That helped a lot!
Nov 16 '05 #5
Glad to help.

--
Tim Wilson
..Net Compact Framework MVP

"CroDude" <di***********@zg.htnet.hr> wrote in message
news:d0**********@news1.xnet.hr...
Dam' it, that was under my nose! Heh ... thanks Tim! That helped a lot!

Nov 16 '05 #6

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

Similar topics

1
1420
by: tadpole | last post by:
This has been the bane of my existence using Visual Studio 2003. Recipe: -Use UNC path to browse to directory on Win2003 Server with IIS. -Double Click the project file, the IDE opens, but...
2
2385
by: Johann Blake | last post by:
The following is a bug I have discovered using tab pages and threads and I am looking for a workaround. Create a new Windows Forms application and add a tab control with two tab pages. Add a...
3
2311
by: M O J O | last post by:
(using VB.net) Hi, I've created my own component inheriting from the RichTextBox. I override the WndProc's WM_NCPAINT so I can draw my own border (color). When I set my BorderColor...
2
15542
by: Simon Verona | last post by:
If I have a combobox set enabled=false then by default it will have dark grey text on a grey background. I want it to show as blue on white. I'm trying code such as : combobox.enabled=false...
4
4614
by: grayaii | last post by:
Hi, I have a simple form that handles all its paint functionality like so: this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true); And the entry point to this...
4
2687
by: Mark Olbert | last post by:
I've written a composite custom control which I would like to have update its design-time display when one of several properties changes at design time. These custom properties are not simply the...
17
5081
by: Zytan | last post by:
I can scroll a WebBrowser to the bottom like so: if (webControl.Document != null) webControl.Document.Body.ScrollTop = int.MaxValue; But, if I include a proper DOCTYPE (for XHTML 1.1 DTD) like...
1
1701
by: Sin Jeong-hun | last post by:
I have created a simple custom control, which displays a string data on it. It draws the string at its OnPaint(). When the string is changed I can call Invalidate() to redraw the string. Sort of...
6
3275
by: Martin Slater | last post by:
Hi all, I'm using a webbrowser control within an application for the UI and want to hide the flicker and redraw when changing pages. Ideally I want to render the new page to a seperate...
0
7162
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,...
1
6881
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
7375
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...
1
4899
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4584
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1411
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
650
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
287
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.