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

Using MSDN examples

P: n/a
Hi All, newbie here-

When I use an example from the MSDN Library, say, to programmically create
a radio button, all I get is an empty form. What am I missing? Here's the
code (I just add under the Windows generated code):

Form 1 (Class Name) - InitializeMyRadioButton (Method Name)
-------------------------------------------
Private Sub InitializeMyRadioButton()
' Create and initialize a new RadioButton.
Dim radioButton1 As New RadioButton()

' Make the radio button control appear as a toggle button.
radioButton1.Appearance = Appearance.Button

' Turn off the update of the display on the click of the control.
radioButton1.AutoCheck = False

' Add the radio button to the form.
Controls.Add(radioButton1)
End Sub


Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi,
When I use an example from the MSDN Library, say, to programmically
create a radio button, all I get is an empty form. What am I
missing? Here's the code (I just add under the Windows generated
code):

Form 1 (Class Name) - InitializeMyRadioButton (Method Name)
-------------------------------------------
Private Sub InitializeMyRadioButton()
' Create and initialize a new RadioButton.
Dim radioButton1 As New RadioButton()

' Make the radio button control appear as a toggle button.
radioButton1.Appearance = Appearance.Button

' Turn off the update of the display on the click of the control.
radioButton1.AutoCheck = False

' Add the radio button to the form.
Controls.Add(radioButton1)
End Sub


Are you sure your code is also called? just writing a Sub is not enough, you
need to call it from Somewhere ... for example here (sorry, german visual
studio ...)

Public Sub New()
MyBase.New()

' Dieser Aufruf ist fr den Windows Form-Designer erforderlich.
InitializeComponent()

InitializeMyRadioButton()

End Sub

The Sub New is in the "Windows Forms Designer generated code"-area ...

Regards,

Frank Eller
www.frankeller.de

Nov 21 '05 #2

P: n/a


"Frank Eller" wrote:

Are you sure your code is also called? just writing a Sub is not enough, you
need to call it from Somewhere ... for example here (sorry, german visual
studio ...)

Public Sub New()
MyBase.New()

' Dieser Aufruf ist für den Windows Form-Designer erforderlich.
InitializeComponent()

InitializeMyRadioButton()

End Sub

The Sub New is in the "Windows Forms Designer generated code"-area ...

Regards,

Frank Eller
www.frankeller.de
Thank you so much! It works now :-) I didn't think I was supposed to fool
around with any code in the "Windows Forms Designer generated code" area. I
have so much to learn..... Thank you, again!

Nov 21 '05 #3

P: n/a
LemonSeven wrote:
Thank you so much! It works now :-) I didn't think I was supposed
to fool around with any code in the "Windows Forms Designer generated
code" area. I have so much to learn..... Thank you, again!


In general, I think you are best off leaving that whole area alone, but it's
sometimes extremely useful to be able to put code into the constructor of
the class (i.e., the Public Sub New() procedure). You could put it into the
Form Load event too, but that doesn't execute until the form has actually
been displayed on screen, which can sometimes be too late.

--

(O) e n o n e
Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.