|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Owner Drawn form background problemsDoing a simple gradient background on a form: Protected Overrides Sub OnPaintBackground(ByVal e As System.Windows.Forms.PaintEventArgs) MyBase.OnPaint(e) Dim r As Rectangle = ClientRectangle Dim b As Brush = New System.Drawing.Drawing2D.LinearGradientBrush (r, Color.Gray, Color.Black, System.Drawing.Drawing2D.LinearGradientMode.Vertical) e.Graphics.FillRectangle(b, ClientRectangle) End Sub Problem: On form resize the background is not painted properly. When increasing the width the gradient is not re-drawn, it is just extended (the 2nd color is painted in the new area exposed). When increasing height the newly exposed area is drwan properly but the old ard is not re-drawn. The client rectangle used in the paint event covers the entire form, so why is it not re-drawing the form? Thanks, kpg Private Sub frmMain_Resize(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Me.Resize Me.Invalidate() End Sub If I had a nickle for everytime I answered my own questions, well, I'd have a lot of nickles. Am 08.04.2010 21:49, schrieb kpg:
> vs 2005 vb.net windows form app. Why do you call OnPaint in OnPaintbackground? I'd remove the line.> > Doing a simple gradient background on a form: > > Protected Overrides Sub OnPaintBackground(ByVal e As > System.Windows.Forms.PaintEventArgs) > > MyBase.OnPaint(e) Show quoteHide quote > Dim r As Rectangle = ClientRectangle Because the old visible area is not part of the invalidated area of the> Dim b As Brush = New System.Drawing.Drawing2D.LinearGradientBrush > (r, Color.Gray, Color.Black, > System.Drawing.Drawing2D.LinearGradientMode.Vertical) > e.Graphics.FillRectangle(b, ClientRectangle) > > End Sub > > > Problem: > > On form resize the background is not painted properly. When increasing the > width the gradient is not re-drawn, it is just extended (the 2nd color is > painted in the new area exposed). When increasing height the newly exposed > area is drwan properly but the old ard is not re-drawn. > > The client rectangle used in the paint event covers the entire form, so why > is it not re-drawing the form? Form. Windows knows which area is invalid and drawing is clipped to the invalid region only. To overcome this...: Sub New() ' Dieser Aufruf ist für den Windows Form-Designer erforderlich. InitializeComponent() ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu. SetStyle(ControlStyles.ResizeRedraw, True) UpdateStyles() End Sub -- Armin Am 08.04.2010 22:14, schrieb Armin Zingler:
> [...] Sry, accidently sent too early.-- Armin Am 08.04.2010 21:49, schrieb kpg:
> vs 2005 vb.net windows form app. Why do you call OnPaint in OnPaintbackground? I'd remove the line.> > Doing a simple gradient background on a form: > > Protected Overrides Sub OnPaintBackground(ByVal e As > System.Windows.Forms.PaintEventArgs) > > MyBase.OnPaint(e) Show quoteHide quote > Dim r As Rectangle = ClientRectangle Because the old visible area is not part of the invalidated area of the> Dim b As Brush = New System.Drawing.Drawing2D.LinearGradientBrush > (r, Color.Gray, Color.Black, > System.Drawing.Drawing2D.LinearGradientMode.Vertical) > e.Graphics.FillRectangle(b, ClientRectangle) > > End Sub > > > Problem: > > On form resize the background is not painted properly. When increasing the > width the gradient is not re-drawn, it is just extended (the 2nd color is > painted in the new area exposed). When increasing height the newly exposed > area is drwan properly but the old ard is not re-drawn. > > The client rectangle used in the paint event covers the entire form, so why > is it not re-drawing the form? Form. Only the new part has to be redrawn. Windows knows which area is invalid and drawing is clipped to the invalid region only. http://msdn.microsoft.com/en-us/library/dd145135%28VS.85%29.aspx To overcome this...: Sub New() ' Dieser Aufruf ist für den Windows Form-Designer erforderlich. InitializeComponent() ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu. SetStyle(ControlStyles.ResizeRedraw, True) UpdateStyles() End Sub -- Armin >> MyBase.OnPaint(e) Only becuase the example I had did it. I know it seems to work fine> > Why do you call OnPaint in OnPaintbackground? I'd remove the line. without it, I thought it was there 'just in case'. I'll remove it, however. Thanks, kpg
Treeview duplicate nodes (VB.NET 2008)
Gridview order Accessing Sub Menu Items ASP Tab Control Single v. Double Help Use a static form of the EventLog class? How to tell if folder item is file or folder? null reference exception could result at runtime How to get the list of all SQL Server foreign keys in a database by using Microsoft.SqlServer.Manage Problem passing exception from AppDomain |
|||||||||||||||||||||||