Dynamic Button where click closes form

nzcam

Member
Joined
Aug 29, 2005
Messages
6
Programming Experience
Beginner
Dynamic Button where click closes form (RESOLVED)

Hi, I am trying to write a a windows app where the close button is created via a public class. The click event is created in here as well.
I can get the click event to process but I can not get the click event to close the form.

Please help!!

Code for class looks like

Public Class SetFormv

Public Sub Set_Form(ByVal in_frm As System.Windows.Forms.Form)

Dim btnClose As New Button

btnClose.Text = "Close"

btnClose.DialogResult = DialogResult.OK

AddHandler btnClose.Click, AddressOf BtnClose_Click

in_frm.Controls.Add(btnClose)

End Sub

Public Sub BtnClose_Click(ByVal sender As Object, ByVal e As EventArgs)

' This procedure handles events raised by the object Obj.
EndSub

EndClass













End Sub



End
Class

 
Last edited:
also note that by using inheritance in this case if all the form's need to have another control added to all of them to do the exact same thing (like another button) then all you have to do is change the BaseForm and that change will be made to all the other forms for you

otherwise you would have to add all the code and everything to every form and that gets very tedious

also welcome to the forums
 
Back
Top