can we create controls during runtime?

rufus

Active member
Joined
Jul 7, 2003
Messages
28
Location
Arlington,TX
can we create during runtime, like can I write code, that creates controls like textbox, buttons, and display on the outout. without creating the controls, using the IDE.
 
Just wonder why dont you write your controls first, then decide whether deploy it during run time.

I dont think there is a way for you to CREATE control during run time. Maybe I misunderstanding you, what do you want to do actually?
 
Actually, Iam developing a game,
Iam using threading concept to display some balls going around the screen randomly. I displayed a gun image on the screen too.

Now want to shoot those balls by moving the mouse on the screen. so for this I need to move the picturebox, which I have already created.

so I tried to create picture boxes during runtime, when ever I press the mouse button down and set the location of the picture box to the mouse positions.

so thats why I need to create the picturebox control during runtime and assign the location.

so I wrote the following, but could not display anything.
Is the below way correct or is there any other way.


Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown

Dim pic As New System.Windows.Forms.PictureBox()
Dim resources As System.Resources.ResourceManager = new System.Resources.ResourceManager(GetType(Form1))

pic.Location = New System.Drawing.Point(e.X, e.Y)
pic.Size = New System.Drawing.Size(104, 80)

pic.Image = CType(resources.GetObject("j:\shooter.jpg"),_ System.Drawing.Bitmap)

pic.Visible = True

End Sub
 
You need to add it to the control collection of your form:
Code:
Me.Controls.Add(pic)
By the way, dont post Control questions in Database forum :).
 
Back
Top