Categorized | Security

Add controls on the fly

To add controls to your form (for example if a condition is met)

Dim RadioButton4 As New RadioButton()
Dim Label12 As New Label
RadioButton4.Text = “option 2″
RadioButton4.Appearance = Appearance.Button
RadioButton4.FlatAppearance.CheckedBackColor = Color.BlueViolet
If choice = “option 2″ Then
RadioButton4.Checked = True
End If
RadioButton4.Location = New Point(287, 114)
RadioButton4.Size = New Size(95, 23)
Me.Controls.Add(RadioButton4)

Label12.Text = “explanation of choices”
Label12.Location = New Point(287, 16)
Label12.Size = New Size(95, 13)
Label12.Font = New Font(label12.Font, FontStyle.Bold)
Me.Controls.Add(Label12)

View full post on Metallica’s blog

Related Posts

3 Responses to “Add controls on the fly”

  1. Pieter says:

    Thank you grin

  2. Billy O'Neal says:

    Hello )

    You can manually add functions to the event handlers instead of using “Handles” if you don’t want to have to declare a friend or local variable inside the form.

    Syntax is “AddHandler Event,Addressof function”
    For example:
    Dim btn as new Button
    Function iGotClicked(ByVal sender As Object, ByVal e As System.EventArgs)
    MsgBox(“This is some code run because I got clicked!”)
    End Function
    AddHandler btn.Click, AddressOf iGotClicked
    Form.Controls.Add(btn)

    Billy3

  3. Pieter says:

    Note that if you want to add for example a Click Event to a button that gets added later you need to add a line to the Form.Designer.vb similar to his one:
    Friend WithEvents Button6 As System.Windows.Forms.Button

    If you don’t you will get an error:
    Handles clause requires a WithEvents variable defined in the containing type or one of its base types.

Trackbacks/Pingbacks


Security Status

Beware Facebook "Timeline" scams http://t.co/W5EW0cVv
5 months ago
Nigerian government (unknowingly) hosts phishing website http://t.co/uQd42ENw
5 months ago
PCMag Awards McAfee All Access its Editors’ Choice: SANTA CLARA, Calif.--(BUSINESS WIRE)--McAfee today announced... http://t.co/FakV7Vd8
5 months ago
RT @mikko: I hadn't noticed Google Maps has added 3D models of buildings. Here's a (very accurate) view of F-Secure HQ in Helsinki http://t.co/IKfAZlak
5 months ago
North Koreans aren't known for their online presence. But others may be lured into clicking Kim Jong-Il 'videos' too http://t.co/yQOon6YT
5 months ago
How to Protect Your Professional Reputation on Facebook Timeline http://t.co/I4bcR2VN
5 months ago
This is pretty impressive from @Softpedia: Facebook scans 2 trillion link clicks and blocks 220 million posts each day http://t.co/vKsn9gNl
5 months ago
Need for integrated approach to security in industrial control systems - http://t.co/tPBCNOow with @PikeResearch
5 months ago
Some free-based music we play at work http://t.co/xu5agZfc
5 months ago
Japan’s cyber defense weapon: a virus. It includes quotes by @Luis_Corrons via @InfosecurityMag
5 months ago