Using MSDN examples

G

Guest

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
 
F

Frank Eller

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 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
 
G

Guest

:

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!
 
O

Oenone

LemonSeven said:
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.
 

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