PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft VB .NET
An embarrassingly single question
Forums
Newsgroups
Microsoft DotNet
Microsoft VB .NET
An embarrassingly single question
![]() |
An embarrassingly single question |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
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 |
|
|
|
#2 |
|
Guest
Posts: n/a
|
"Christian O'Connell" <cdoconnell@hotmail.com> schrieb
> 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/e...s/listboxes.asp -- Armin http://www.plig.net/nnq/nquote.html http://www.netmeister.org/news/learn2quote.html |
|
|
|
#3 |
|
Guest
Posts: n/a
|
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 ---------------------------- "Christian O'Connell" <cdoconnell@hotmail.com> wrote in message news:9a595d62.0312280328.7dc0894f@posting.google.com... > 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 |
|
|
|
#4 |
|
Guest
Posts: n/a
|
* cdoconnell@hotmail.com (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. -- Herfried K. Wagner [MVP] <http://www.mvps.org/dotnet> |
|
|
|
#5 |
|
Guest
Posts: n/a
|
Thanks everyone. It is making sense now.
Chris. cdoconnell@hotmail.com (Christian O'Connell) wrote in message news:<9a595d62.0312280328.7dc0894f@posting.google.com>... > 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 |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

