Results 1 to 9 of 9

Thread: [2005] Button Help

  1. #1

    Thread Starter
    Fanatic Member bharanidharanit's Avatar
    Join Date
    Oct 2008
    Location
    India
    Posts
    673

    [2005] Button Help

    Hello sir,
    I am having 3 linklabels on the form and 1 button.
    Consider these are the linklabels.
    a
    b
    c

    When "a" is clicked, button is visible on the form and when i click the button HTML output is displayed (i had already attached HTML pages to my project and also i know how to display output for HTML pages in the project) .

    For a,b,c i am having different HTML pages.

    What i actually need is?
    I want to use only one button. But when i click a,b,c linklabels, the appropriate HTML output must be displayed.

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: [2005] Button Help

    So when you click one of the labels, you need to set some form level variable to indicate which one was pressed. Then the button click event would display the HTML based on the value of that variable.
    My usual boring signature: Nothing

  3. #3

    Thread Starter
    Fanatic Member bharanidharanit's Avatar
    Join Date
    Oct 2008
    Location
    India
    Posts
    673

    Re: [2005] Button Help

    Quote Originally Posted by Shaggy Hiker
    So when you click one of the labels, you need to set some form level variable to indicate which one was pressed. Then the button click event would display the HTML based on the value of that variable.
    Hello sir,
    I cant get you sir,
    Can u explain me in more detail?

  4. #4

    Thread Starter
    Fanatic Member bharanidharanit's Avatar
    Join Date
    Oct 2008
    Location
    India
    Posts
    673

    Re: [2005] Button Help

    Hello sir,
    How to set form level variables to detect which button is pressed?

  5. #5
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: [2005] Button Help

    Quote Originally Posted by bharanidharanit
    Hello sir,
    How to set form level variables to detect which button is pressed?
    you would create a public variable at the top of the code page. something like
    Public MyVariableName as integer = 0
    then in the relevant event for the link label, you would do something like:
    MyVariableName = 1
    of course, the value of MyVariableName would be different for each, eg:
    MyVariableName = 1
    MyVariableName = 2
    MyVariableName = 3

    then you would check the value of MyVariableName and do what you want accordingly. eg:
    Select Case MyVariableName
    Case 1
    'do something for MyVariableName = 1
    Case 2
    'do something for MyVariableName = 2
    Case Else
    'do something for MyVariableName when its not = 1 or = 2
    End Select
    of course, i used an integer but you can use any data type, i suppose

  6. #6
    Fanatic Member
    Join Date
    Aug 2006
    Location
    In my head
    Posts
    913

    Re: [2005] Button Help

    You can also set the .Tag property on the Button then display the HTML based on the .Tag Property.

    Code:
     Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
            Button1.Tag = "a"
        End Sub
    
        Private Sub LinkLabel2_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel2.LinkClicked
            Button1.Tag = "b"
        End Sub
    
        Private Sub LinkLabel3_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel3.LinkClicked
            Button1.Tag = "c"
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            If Button1.Tag IsNot Nothing Then
                Select Case Button1.Tag.ToString
                    Case "a"
                        'Show HTML for a
                    Case "b"
                        'Show HTML for b
                    Case "c"
                        'Show HTML for c
                    Case Else
                        MessageBox.Show("Not a valid selection")
    
                End Select
            End If
        End Sub
    The way they were describing in previous posts on using a form level variable is something similar to what is above, see below:
    Code:
    Public Class Form1
    
        Private LabelClicked As String = "a"
    
        Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
            LabelClicked = "a"
        End Sub
    
        Private Sub LinkLabel2_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel2.LinkClicked
            LabelClicked = "b"
        End Sub
    
        Private Sub LinkLabel3_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel3.LinkClicked
            LabelClicked = "c"
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Select Case LabelClicked
                Case "a"
                    'Show HTML for a
                Case "b"
                    'Show HTML for b
                Case "c"
                    'Show HTML for c
                Case Else
                    MessageBox.Show("Not a valid selection")
    
            End Select
        End Sub
    
    End Class
    Either way the result is the same. I hope this helps you some!

    Good Luck!

    D
    Platforms of choice: Visual Studio 2005/2008 Professional : Visual Studio 2010 Enterprise : PHP - Notepad++/WAMP

    Please Rate If I helped you.
    Please remember to mark threads as closed if your issue has been resolved.

    Reserved Words in Access | Connection Strings

  7. #7

    Thread Starter
    Fanatic Member bharanidharanit's Avatar
    Join Date
    Oct 2008
    Location
    India
    Posts
    673

    Re: [2005] Button Help

    Quote Originally Posted by dminder
    You can also set the .Tag property on the Button then display the HTML based on the .Tag Property.

    Code:
     Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
            Button1.Tag = "a"
        End Sub
    
        Private Sub LinkLabel2_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel2.LinkClicked
            Button1.Tag = "b"
        End Sub
    
        Private Sub LinkLabel3_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel3.LinkClicked
            Button1.Tag = "c"
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            If Button1.Tag IsNot Nothing Then
                Select Case Button1.Tag.ToString
                    Case "a"
                        'Show HTML for a
                    Case "b"
                        'Show HTML for b
                    Case "c"
                        'Show HTML for c
                    Case Else
                        MessageBox.Show("Not a valid selection")
    
                End Select
            End If
        End Sub
    The way they were describing in previous posts on using a form level variable is something similar to what is above, see below:
    Code:
    Public Class Form1
    
        Private LabelClicked As String = "a"
    
        Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
            LabelClicked = "a"
        End Sub
    
        Private Sub LinkLabel2_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel2.LinkClicked
            LabelClicked = "b"
        End Sub
    
        Private Sub LinkLabel3_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel3.LinkClicked
            LabelClicked = "c"
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Select Case LabelClicked
                Case "a"
                    'Show HTML for a
                Case "b"
                    'Show HTML for b
                Case "c"
                    'Show HTML for c
                Case Else
                    MessageBox.Show("Not a valid selection")
    
            End Select
        End Sub
    
    End Class
    Either way the result is the same. I hope this helps you some!

    Good Luck!

    D
    Thankyou sir,
    But i am having nearly 1000 of linklabels. Then the coding is some tough. Is there any other possible easy way to do this?

  8. #8
    Addicted Member
    Join Date
    Mar 2008
    Posts
    148

    Re: [2005] Button Help

    1000? Isn't that a bit too much to fit on one form? But if you are, are you going to be creating them manually or using some piece of code to generate them when the form loads?

  9. #9
    Fanatic Member
    Join Date
    Aug 2006
    Location
    In my head
    Posts
    913

    Re: [2005] Button Help

    Well to do what you described in the original post those are your best 2 options. Regardless if it is 1, 10 or 1000, you will still have to do the same thing - welcome to our world!!

    D
    Platforms of choice: Visual Studio 2005/2008 Professional : Visual Studio 2010 Enterprise : PHP - Notepad++/WAMP

    Please Rate If I helped you.
    Please remember to mark threads as closed if your issue has been resolved.

    Reserved Words in Access | Connection Strings

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width