Home All Groups Group Topic Archive Search About
Author
3 Apr 2005 4:07 PM
LemonSeven
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

Author
3 Apr 2005 5:27 PM
Frank Eller
Hi,
Show quoteHide quote
> 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
Author
3 Apr 2005 5:51 PM
LemonSeven
Show quote Hide quote
"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!
Show quoteHide quote
>
>
>
>
Author
3 Apr 2005 6:29 PM
Oenone
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