WinForms - Back in the saddle

Posted on 2012-08-23
Last Modified: 2012-08-23
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

Question by:lrbrister
    LVL 13

    Accepted Solution

    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
    LVL 85

    Expert Comment

    by:Mike Tomlinson
    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():
    LVL 85

    Expert Comment

    by:Mike Tomlinson
    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...

    Author Closing Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
    More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now