Imports System.DrawingImports System.ComponentModel'Imports MicroFour.StrataFrame.BusinessImports MicroFour.StrataFrame.UI.Collections ''' <summary>''' My Button class. I will use this class to exit a form.''' </summary>''' <remarks></remarks><ToolboxBitmap(GetType(System.Windows.Forms.Button))>Public Class myExitButton Inherits MicroFour.StrataFrame.UI.Windows.Forms.Button Public Sub New() MyBase.New() 'Me.Width = 23 'Me.Height = 32 'Me.Text = "Exit" End Sub Protected Overrides Sub OnClick(ByVal e As System.EventArgs) MyBase.OnClick(e) ' Simply Want to Close the Form The Following Works but the following is more generic ' Parent.Dispose() Dim parentform As Form = Me.GetParentForm() If parentform IsNot Nothing Then parentform.Close() End If End Sub Protected Overrides Sub oncreatecontrol() MyBase.OnCreateControl() Me.Width = 75 Me.Height = 23 Me.Text = "Exit" End Sub Private Function GetParentForm() As Object ' return var Dim parentform As Form = Nothing Dim ctl1 As Control = Me.Parent If TypeOf ctl1 Is Form Then parentform = DirectCast(ctl1, Form) Return parentform End If Do ctl1 = Me.GetNextControl(ctl1, True) If ctl1 IsNot Nothing Then ' Search for Form If TypeOf ctl1 Is Form Then parentform = DirectCast(ctl1, Form) End If End If Loop Until ctl1 Is Nothing Return parentform End Function ' The Following would probably work if you wanted to put the Parent Form in a Property ' Public Class closebutton 'imports System.Windows.Forms.Button ' Private _parentForm As System.Windows.Forms.Form ' '' <summary> ' ''' Defines. ' ''' </summary> ' Public Property ParentForm() As System.Windows.Forms.Form ' Get ' Return _parentForm ' End Get ' Set(ByVal value As System.Windows.Forms.Form) ' _parentForm = value ' End Set ' End Property ' Protected Overrides Sub OnCreateControl() ' MyBase.OnCreateControl() ' Me.Text = "Close" ' Me.Width = 75 ' Me.Height = 23 ' End Sub ' Protected Overrides Sub OnClick(ByVal e As EventArgs) ' MyBase.OnClick(e) ' '-- Close the form if its set. ' If Me.ParentForm IsNot Nothing Then ' Me.ParentForm.Close() ' End If ' End Sub ' End Class End Class
As Soon as I put it on the form to exit the weird stuff happens. I have used this on 9 or 10 forms before and nothing happened with Radiobuttongroups. Why all of a sudden???
Imports System.DrawingImports System.ComponentModel'Imports MicroFour.StrataFrame.BusinessImports MicroFour.StrataFrame.UI.CollectionsImports System.Windows.Forms.Button ''' <summary>''' My Button class. I will use this class to exit a form.''' </summary>''' <remarks></remarks><ToolboxBitmap(GetType(System.Windows.Forms.Button))>Public Class myExitButton2 Inherits MicroFour.StrataFrame.UI.Windows.Forms.Button Private _parentForm As System.Windows.Forms.Form Public Property ParentForm() As System.Windows.Forms.Form Get Return _parentForm End Get Set(ByVal value As System.Windows.Forms.Form) _parentForm = value End Set End Property Protected Overrides Sub OnCreateControl() MyBase.OnCreateControl() Me.Text = "Close" Me.Width = 75 Me.Height = 23 End Sub Protected Overrides Sub OnClick(ByVal e As EventArgs) MyBase.OnClick(e) '-- Close the form if its set. If Me.ParentForm IsNot Nothing Then Me.ParentForm.Close() End If End Sub
Imports MicroFour.StrataFrame.UI.Collections