PC Review


Reply
Thread Tools Rate Thread

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

 
 
Cashewz
Guest
Posts: n/a
 
      24th Feb 2007

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
 
Reply With Quote
 
 
 
 
Lloyd Sheen
Guest
Posts: n/a
 
      24th Feb 2007
When you create your control use the AddHandler statement to add handlers
for the events you wish to capture.

LS

"Cashewz" <(E-Mail Removed)> wrote in message
news:Xns98E17F0F05BF8cashewz@216.196.97.131...
>
> 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


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
HELP: How do I code a button I created? sam Microsoft Outlook Form Programming 1 5th Jan 2010 07:51 PM
How to indentify control button objects created at runtime other than by GetHash()? raylopez99 Microsoft VC .NET 0 14th Feb 2007 01:50 AM
Re: Event Code for Controls created at runtime... Robert Bruce Microsoft Excel Programming 0 6th Dec 2006 12:11 PM
Re: Event Code for Controls created at runtime... Bob Phillips Microsoft Excel Programming 0 6th Dec 2006 10:35 AM
Can a type be instantiated at runtime? Will Pittenger Microsoft C# .NET 5 25th Jul 2005 03:52 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:05 PM.