Code for instantiated button created at runtime... huh?

C

Cashewz

Hello, i'm trying to set this code:


rtbRichTextBox.SaveFile(Me.Text & ".rtf")


to the code below in a click event for "btnButton". The button was
created at runtime, so i'm not sure how to set up the click event for a
control that doesnt exist at design time.




Private Sub mnuNewMemo_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles mnuNewMemo.Click

Dim MyChild As New Form
MyChild.MdiParent = Me
MyChild.Show()

Static intNum As Integer
intNum += 1
MyChild.Text = "Child Form "
MyChild.Text &= intNum
MyChild.Height = 400
MyChild.Width = 400



''' CONTROLS CREATED AT RUNTIME!
'Declare Controls
Dim rtbRichTextBox As System.Windows.Forms.RichTextBox
Dim btnButton As System.Windows.Forms.Button

'Instantiate the Controls
rtbRichTextBox = New System.Windows.Forms.RichTextBox
btnButton = New System.Windows.Forms.Button

'Add the controls to the form
MyChild.Controls.Add(rtbRichTextBox)
rtbRichTextBox.Dock = DockStyle.Fill
rtbRichTextBox.Controls.Add(btnButton)

btnButton.Left = rtbRichTextBox.Width - 125
btnButton.Top = 25
btnButton.Width = 75
btnButton.Height = 20
btnButton.Text = "Save"


End Sub
 
L

Lloyd Sheen

When you create your control use the AddHandler statement to add handlers
for the events you wish to capture.

LS
 

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