• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 814
  • Last Modified:

WinForms - Back in the saddle

I have a project with a main form

The main form has a telerik menu system, and on Menu Item CLick I'll be loading user controls

The following in my Code.

What I would like to do is also set a variable on click event which I can pass into the user control.

I've been working on Web Forms the last 5 years and rusty on WinForms and passing variables.

My Code:
  Private Sub HomeMenu_ItemClicked(ByVal sender As Object, ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs) Handles HomeMenu.ItemClicked
        'Unload any existing Control
        If Me.mainPanel.Controls.Count > 0 Then
        End If

        'Declare a contrl for use
        Dim _panel As New Control
        _panel = New ucDefault

        'Actions based on menu clicked
        Select Case e.ClickedItem.Text.ToString()
            Case "Home"
                pbApplication.Image = ngMan.My.Resources.Bookmark
            Case "Email"
                pbApplication.Image = ngMan.My.Resources.emailMain
            Case "CliMan"
                pbApplication.Image = ngMan.My.Resources.hospitalMain
            Case "CanMan"
                pbApplication.Image = ngMan.My.Resources.nurseMain
            Case "NG Man"
                pbApplication.Image = ngMan.My.Resources.receptionist
            Case "HoursMan"
                pbApplication.Image = ngMan.My.Resources.hoursMain
            Case "CalcMan"
                pbApplication.Image = ngMan.My.Resources.calcMain
            Case "LodgeMan"
                pbApplication.Image = ngMan.My.Resources.office_building_icon
                _panel = New ucLodgeMan
            Case Else
                pbApplication.Image = ngMan.My.Resources.Bookmark
        End Select

    End Sub

Open in new window

  • 2
1 Solution
Jesus RodriguezIT ManagerCommented:
Add a Public Variable at the load of your program and then set the values whenever you needit an access the variable when you want making refrerence to the Form.Variable

 Public VFarGen as string=""

 Public sub Main.Load() 'Main Form When load
  ' Other things
End Sub

Form The Other Form On the click button

Dim ValOfVariable as string = Main.VFarGen
Mike TomlinsonMiddle School Assistant TeacherCommented:
Not sure exactly what you're looking for...

"I'll be loading user controls"
"I would like to ... set a variable on click event"

Do you need to wire up a click event for your user control?  If yes, use AddHandler():
        'Declare a contrl for use
        Dim _panel As New Control
        _panel = New ucDefault
        AddHandler _panel.SomeEventName, AddressOf SomeMethodName

Open in new window

See AddHandler(): http://msdn.microsoft.com/en-us/library/7taxzxka(VS.80).aspx
Mike TomlinsonMiddle School Assistant TeacherCommented:
You could also make your UserControl to raise a CUSTOM EVENT that passes out information when it is clicked.  Again, you'd use AddHandler() when you create that UserControl to wire up that custom event...
lrbristerAuthor Commented:

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now