Windows Develop Bookmark and Share   
 index > Windows Forms General > OnPaint method not firing in my WinForm custom control...
 

OnPaint method not firing in my WinForm custom control...

Not sure what the problem is here. I've been looking into this for about 2 hours now and haven't been able to figure out why the custom control OnPaint method won't fire.

I'm programatically adding the custom control to an existing form which looks something like this:

Dim multListCtl As New ccMultiAnswerList()
multListCtl.RowCount = 1
multListCtl.ColumnCount = 2
newPoint.Y += 20
multListCtl.Width = 300
multListCtl.Location = newPoint
Me.Controls.Add(multListCtl)


Here's what my constructor on my custom control looks like:

Public Sub New()

InitializeComponent()

Me.SetStyle(ControlStyles.DoubleBuffer, True)
Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
Me.SetStyle(ControlStyles.UserPaint, True)
Me.SetStyle(ControlStyles.ResizeRedraw, True)

Me.tblAnswerLayout.ColumnCount = m_colCount + 1
Me.tblAnswerLayout.RowCount = 0

End Sub

And the OnPaint method:

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

MyBase.OnPaint(e)
DrawAnswerList()

End Sub


Any ideas as to why this might be happening?


Gui Guy  Wednesday, May 20, 2009 8:20 PM
Check the control's Location, Size and Visible properties.

Hans Passant.
  • Marked As Answer byGui Guy Wednesday, May 20, 2009 8:52 PM
  •  
nobugz  Wednesday, May 20, 2009 8:32 PM
Check the control's Location, Size and Visible properties.

Hans Passant.
  • Marked As Answer byGui Guy Wednesday, May 20, 2009 8:52 PM
  •  
nobugz  Wednesday, May 20, 2009 8:32 PM
That fixed the problem. Thanks.

Would you be able to explain what about those settings causes the paint to fire?
Gui Guy  Wednesday, May 20, 2009 8:52 PM
The control has to be visible on the form's client area.

Hans Passant.
nobugz  Wednesday, May 20, 2009 9:10 PM

You can use google to search for other answers

Custom Search

More Threads

• Access methods from a scriptable app
• Command Line Compiler
• Newbie staff VB.NET
• I desperatly need your help, Its an XP Bug! :(
• Multiple State Changes In UIP App Block
• Async Call to multiple function & should return to common method
• Recognizing and object in a 2nd form
• how to bind the DataTable to the DAtaGridView control?
• Tool Tip for dropdown in IE6
• transporting value to another form and back