By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,694 Members | 1,307 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,694 IT Pros & Developers. It's quick & easy.

Owner Draw Radio Button

P: n/a
Trying to place a few radio buttons where I draw the image on the button. I declare an array of three buttons and initialize them as below. The paint event is getting triggered for the buttons, but my drawing never shows up. What am I doing wrong? Thanks.
For x As Integer = 0 To 2
drawStyle(x) = New RadioButton
With drawStyle(x)
.Width = pnlPalette.Width - 4
.Height = 24
.Appearance = Appearance.Button
.FlatStyle = FlatStyle.Popup
.Left = 2
.Tag = x
End With
pnlPalette.Controls.Add(drawStyle(x))
AddHandler drawStyle(x).Paint, AddressOf drawStyle_Paint
Next

---------------------------

Private Sub drawStyle_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs)
Dim r As RadioButton = sender
Dim g As Graphics = r.CreateGraphics()

With r
If (.Tag = "One") Then g.FillRectangle(New SolidBrush(_fillColor), 2, 2, .Width - 4, .Height - 4)
If (.Tag = "Two") Then g.DrawRectangle(New Pen(_lineColor, _lineWidth), 2, 2, .Width - 4, .Height - 4)
End With
End Sub
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Rlrcstr" <rl*****@msn.com> schrieb:
Trying to place a few radio buttons where I draw the image on the button.
I declare an array of three buttons and initialize them as below. The
paint event is getting triggered for the buttons, but my drawing never
shows up. What am I doing wrong? Thanks.

For x As Integer = 0 To 2
drawStyle(x) = New RadioButton
With drawStyle(x)
.Width = pnlPalette.Width - 4
.Height = 24
.Appearance = Appearance.Button
.FlatStyle = FlatStyle.Popup
.Left = 2
.Tag = x
End With
pnlPalette.Controls.Add(drawStyle(x))
AddHandler drawStyle(x).Paint, AddressOf drawStyle_Paint
Next<<<

Instead of adding a handler to the buttons' 'Paint' events, create a class
that inherits from 'RadioButton' and overrides its 'OnPaint' method. Place
your drawing code in the 'OnPaint' method and use the derived class instead
of the standard radio button control.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #2

P: n/a
Perfect. Thanks.
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:et*************@tk2msftngp13.phx.gbl...
"Rlrcstr" <rl*****@msn.com> schrieb:
Trying to place a few radio buttons where I draw the image on the button.I declare an array of three buttons and initialize them as below. The
paint event is getting triggered for the buttons, but my drawing never
shows up. What am I doing wrong? Thanks.


For x As Integer = 0 To 2
drawStyle(x) = New RadioButton
With drawStyle(x)
.Width = pnlPalette.Width - 4
.Height = 24
.Appearance = Appearance.Button
.FlatStyle = FlatStyle.Popup
.Left = 2
.Tag = x
End With
pnlPalette.Controls.Add(drawStyle(x))
AddHandler drawStyle(x).Paint, AddressOf drawStyle_Paint
Next<<<

Instead of adding a handler to the buttons' 'Paint' events, create a class
that inherits from 'RadioButton' and overrides its 'OnPaint' method.

Place your drawing code in the 'OnPaint' method and use the derived class instead of the standard radio button control.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.