Windows Develop Bookmark and Share   
 index > Windows Forms General > Where should I put code to gradient fill a form?
 

Where should I put code to gradient fill a form?

Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)

MyBase.OnPaint(e)

Dim brush As New LinearGradientBrush(New Point(0, 0), New Point(Width, 0), _

Color.SteelBlue, Color.PowderBlue)

e.Graphics.FillRectangle(brush, Me.ClientRectangle)

End Sub

Right now the code fires off even if nothing is changed on the form and it always seems to fire off 2-3 times in a row. Is there a better place or should I go with a background image. If I do go with a Background image will it fill the menu bar also?

Developer_46038  Wednesday, April 30, 2008 7:51 PM

OnPaint is the correct place for this code.

You can print out thee.ClipRectangle if you are interested in figuring out what area of the form has been invalidated which caused Paint to be called. At the end of the day, it is basically up to the OS to determine when to paint. Unless it is causing noticable performance problems, you probably do not need to do anything.

> If I do go with a Background image will it fill the menu bar also?

No. However, you can handle the MenuStrip.Paint event if you want to use a similar technique for the MenuStrip (or ToolStrip).

BinaryCoder  Thursday, May 01, 2008 12:30 AM

OnPaint is the correct place for this code.

You can print out thee.ClipRectangle if you are interested in figuring out what area of the form has been invalidated which caused Paint to be called. At the end of the day, it is basically up to the OS to determine when to paint. Unless it is causing noticable performance problems, you probably do not need to do anything.

> If I do go with a Background image will it fill the menu bar also?

No. However, you can handle the MenuStrip.Paint event if you want to use a similar technique for the MenuStrip (or ToolStrip).

BinaryCoder  Thursday, May 01, 2008 12:30 AM

You can use google to search for other answers

Custom Search

More Threads

• Add ActiveX component
• MultiThreading - Create,Stop & Refersh.
• Using messagebox from a aspx web form?
• AutoComplete Problem
• Font problem
• Controlling elements in a seperate C# form
• undo function
• Why is refreshing on scrolling so slow!?
• BackgroundWorker and GUI
• ListView sorting