PC Review Forums Newsgroups Microsoft DotNet Microsoft VB .NET An embarrassingly single question

Reply

An embarrassingly single question

 
Thread Tools Rate Thread
Old 28-12-2003, 11:28 AM   #1
Christian O'Connell
Guest
 
Posts: n/a
Default An embarrassingly single question


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
  Reply With Quote
Old 28-12-2003, 11:55 AM   #2
Armin Zingler
Guest
 
Posts: n/a
Default Re: An embarrassingly single question

"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

  Reply With Quote
Old 28-12-2003, 12:05 PM   #3
Ken Tucker [MVP]
Guest
 
Posts: n/a
Default Re: An embarrassingly single question

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



  Reply With Quote
Old 28-12-2003, 12:43 PM   #4
Herfried K. Wagner [MVP]
Guest
 
Posts: n/a
Default Re: An embarrassingly single question

* 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>
  Reply With Quote
Old 28-12-2003, 01:57 PM   #5
Christian O'Connell
Guest
 
Posts: n/a
Default Re: An embarrassingly single question

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

  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off