I created a simple user control for Windows Forms for some learning experience, but I will use it in a production program. The control is basically a Button control dragged into the UserControl draw area, with one event:
I can drop this UC on my other forms, and the button will close the form that it is on. I figured I can avoid having to code the btnClose event in every form that I create by just using this control.
However! The button actually closes the form in DESIGN time as well as runtime. If I am designing the form and I click the control, the form disappears from the design window! Ack! Is there a way that I can tell my control to only be active during run-time to fix this bug I have created? Do UCs have a different conception of run-time?
Visual Basic:
Public Class ucCloseButton
Inherits System.Windows.Forms.UserControl
#Region " Windows Form Designer generated code "
#Region "Events"
Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btnClose.Click
Me.ParentForm.Close()
End Sub
#End Region
End Class
I can drop this UC on my other forms, and the button will close the form that it is on. I figured I can avoid having to code the btnClose event in every form that I create by just using this control.
However! The button actually closes the form in DESIGN time as well as runtime. If I am designing the form and I click the control, the form disappears from the design window! Ack! Is there a way that I can tell my control to only be active during run-time to fix this bug I have created? Do UCs have a different conception of run-time?