An embarrassingly single question

  • Thread starter Christian O'Connell
  • Start date
C

Christian O'Connell

Hi, still learning VB.Net and have this very simple question.
Why does my console debug window never display "TestOnPaint" ?
Chris

Public Class Form1
Inherits System.Windows.Forms.Form

'[+] Windows Form Designer generated code

Private Class SCListBox
Inherits ListBox

Protected Overrides Sub OnPaint(ByVal e As _
System.Windows.Forms.PaintEventArgs)
Debug.WriteLine("TestOnPaint")
MyBase.OnPaint(e)
End Sub

End Class


Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim f As New SCListBox
f.Text = "ff"
Me.Controls.Add(f)
f.Visible = True
f.Refresh()
End Sub

End Class
 
A

Armin Zingler

Christian O'Connell said:
Hi, still learning VB.Net and have this very simple question.
Why does my console debug window never display "TestOnPaint" ?
Chris

Public Class Form1
Inherits System.Windows.Forms.Form

'[+] Windows Form Designer generated code

Private Class SCListBox
Inherits ListBox

Protected Overrides Sub OnPaint(ByVal e As _
System.Windows.Forms.PaintEventArgs)
Debug.WriteLine("TestOnPaint")
MyBase.OnPaint(e)
End Sub

End Class


Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim f As New SCListBox
f.Text = "ff"
Me.Controls.Add(f)
f.Visible = True
f.Refresh()
End Sub

End Class

Probably OnPaint is not called with listboxes because a listbox is a
"native" Windows control painted by Windows itself.

http://msdn.microsoft.com/library/en-us/shellcc/platform/commctls/listboxes/listboxes.asp
 
K

Ken Tucker [MVP]

Hi,

Try this.

Private Class SCListBox

Inherits ListBox

Protected Overrides Sub OnPaint(ByVal e As _

System.Windows.Forms.PaintEventArgs)

Debug.WriteLine("TestOnPaint")

MyBase.OnPaint(e)

End Sub

Public Sub New()

Me.SetStyle(ControlStyles.UserPaint, True)

End Sub

End Class

Ken
 
H

Herfried K. Wagner [MVP]

* (e-mail address removed) (Christian O'Connell) scripsit:
Hi, still learning VB.Net and have this very simple question.
Why does my console debug window never display "TestOnPaint" ?

This doesn't work with the listbox. You may want to set its style to
ownerdrawn and draw the items in the control's 'DrawItem' event handler.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top