Results 1 to 8 of 8

Thread: How do I create an On_Click event for buttons created programattically? - Help!!

Threaded View

  1. #2
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    ok that makes no since

    if the button is on the child why do you need to generate it from the mdi form? if you want help provide the needed details and put code in the code or vbcode tags

    here though:

    VB Code:
    1. Option Explicit On
    2. Option Strict On
    3.  
    4. Imports Microsoft.VisualBasic
    5.  
    6. Imports System
    7. Imports System.Drawing
    8. Imports System.Windows.Forms
    9. Namespace mdiExample
    10. Public Class mdi : Inherits Form
    11.  
    12.     <STAThread()> _
    13.     Public Shared Sub Main()
    14.         System.Windows.Forms.Application.Run(new mdi())
    15.     End Sub
    16.    
    17.     Public Sub New()
    18.         MyBase.New()
    19.        
    20.         Me.IsMdiContainer = True
    21.         Me.Text = "MDI Example"
    22.         Me.Show
    23.        
    24.         Dim i As Short = 0
    25.         Dim frm As mdiChild
    26.         For i = 0 To 9         
    27.             frm = new mdiChild
    28.             frm.MdiParent = Me
    29.             frm.Text = CStr(i)
    30.             frm.Show
    31.         Next i
    32.        
    33.     End Sub
    34. End Class
    35.  
    36. Public Class mdiChild : Inherits Form
    37.    
    38.     Public Sub New()
    39.         MyBase.New
    40.        
    41.         Dim btn As new Button
    42.        
    43.         btn.Text = "A Button"
    44.         btn.Location = new Point(120,6)
    45.        
    46.         Me.Controls.Add(btn)
    47.         AddHandler btn.Click, AddressOf Me.btn_Click
    48.     End Sub
    49.    
    50.     Private Sub btn_Click(sender As Object, e As EventArgs)
    51.         MsgBox("A Button")
    52.     End Sub
    53. End Class
    54. End Namespace
    Last edited by Magiaus; Apr 12th, 2002 at 06:15 PM.
    Magiaus

    If I helped give me some points.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width