Wednesday, October 1, 2014

Visual basic 2010 - re-using form

here's an example with 5 labels:



Public Class Form1

Private Sub Labels_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label5.DoubleClick, Label4.DoubleClick, Label3.DoubleClick, Label2.DoubleClick, Label1.DoubleClick
Dim f As New Form2(DirectCast(sender, Label))
f.ShowDialog()
End Sub

End Class




Public Class Form2

Dim subject As Label

Public Sub New(ByVal subjectLabel As Label)
InitializeComponent()
subject = subjectLabel
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim cd As New ColorDialog
If cd.ShowDialog = DialogResult.OK Then
subject.BackColor = cd.Color
Me.DialogResult = Windows.Forms.DialogResult.OK
End If
End Sub

End Class





thanks for any help


No comments:

Post a Comment