Results 1 to 5 of 5

Thread: [RESOLVED] PerformClick a button in TabControl ???

  1. #1

    Thread Starter
    Hyperactive Member pourkascheff's Avatar
    Join Date
    Apr 2020
    Location
    LocalHost
    Posts
    354

    Resolved [RESOLVED] PerformClick a button in TabControl ???

    Hi all! \O
    I recently realized that when I link a button to a StripMenu button with following code:
    Code:
        Private Sub ShutdownToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ShutdownToolStripMenuItem.Click
            Shutdown_btn.PerformClick()
        End Sub
    
    
        Private Sub Shutdown_btn_Click(sender As Object, e As EventArgs) Handles Shutdown_btn.Click
            End
        End Sub
    Shortcut set on stripmenu button (example= Alt + F4) performs exact the same expected action.

    But when you relocate the mentioned button in a TabControl you should open the corresponded tab and press shortcut buttons otherwise nothing happens. Seems shortcut will be bypassed.

    Is there any tabcontrol property to set to "true" to get global shortcut sensitivity ???

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: PerformClick a button in TabControl ???

    First, the control is a MenuStrip, not a StripMenu.

    Secondly, don't use End for anything. If you want to exit a WinForms application then call Application.Exit.

    As for your issue, it's not what you think. What's actually happening is that a TabControl is optimised such that controls on TabPages don't get created unless that TabPage is selected. That way, creating a form with lots of controls on it is still quite quick. The solution to the problem is to not put the functionality you want executed in the Click event handler of the Button. Put it in its own method and then call that method from both event handlers. That way, the menu item has no reliance on the Button having been created.

  3. #3

    Thread Starter
    Hyperactive Member pourkascheff's Avatar
    Join Date
    Apr 2020
    Location
    LocalHost
    Posts
    354

    Re: PerformClick a button in TabControl ???

    Whatever...

    "End" command was an example.

    No idea what are you talking about. I'd rather select its tabindex, perform what I need then return back to normal cause btn.performclick doesn't work in middle of the code neither. Shortcut was also an example dooshy

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: PerformClick a button in TabControl ???

    He didn't mean use PerformClick at all. He said use a sub or function in your form code, that would be called from both your ShutdownToolStripMenuItem_Click and your Shutdown_btn_Click handlers

  5. #5
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,754

    Re: PerformClick a button in TabControl ???

    Quote Originally Posted by pourkascheff View Post
    Whatever...

    "End" command was an example.

    No idea what are you talking about. I'd rather select its tabindex, perform what I need then return back to normal cause btn.performclick doesn't work in middle of the code neither. Shortcut was also an example dooshy
    If you want help check your attitude at the door.

    This is what you have with different names,

    Code:
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Button2.PerformClick()
        End Sub
    
        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            'do something
        End Sub
    This is what JMC and Paul are telling you to do,

    Code:
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            SomeThing()
        End Sub
    
        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            SomeThing()
        End Sub
    
        Private Sub SomeThing()
            'do something
        End Sub
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

Tags for this Thread

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