Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I am creating button at execution time because location varies.

I am not getting control code that is suppose to be generated.Any ideas?

 

heres my code:

button1 = New Button

button1.Location = New Point(1, 18 * (i - 5))

Controls.Add(button1)

button1.Text = "SUBMIT"

  • *Experts*
Posted

Not sure what you mean by "control code that is supposed to be generated." The only control code which is generated is created when you draw a control on the form with the designer. Your code is not altered when you dynamically add a control. However, Button1.Show() should cause the button to appear.

 

[edit]D'oh, I got sidetracked by another post and didn't push Submit[/edit]

  • *Experts*
Posted

I got this PM from hazejean, and for the benefit of others who may have the same problem, I will answer here:

button

I create buttons dynamically becasue they are different depending on text file being read.

this is my code

 

button1 = New Button

button1.Location = New Point(1, 18 * (i - 5))

Controls.Add(button1)

button1.Text = "SUBMIT"

 

If button1 is clicked I want to output a file to disk.

I have tried several way to detect if button is clicked.

All have been unsuccessful.

 

Ant ideas.?

 

Thanks

To add a hander to an event dynamically, use the AddHandler function. First create a handler sub with the proper parameters (you can generally get this from the MSDN, or by copying and pasting the params from an existing button). For example
Private Sub ButtonClickHandler(sender As Object, e As EventArgs)
 MessageBox.Show("Click!")
End Sub

'to hook up the above hander:
AddHandler Button1.Click, AddressOf ButtonClickHander

As usual, consult the MSDN for more information about handling events.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...