[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 ???
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.
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
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
Re: PerformClick a button in TabControl ???
Quote:
Originally Posted by
pourkascheff
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