-
Apr 7th, 2014, 02:09 PM
#1
Thread Starter
New Member
How to make a button visible when a tab is clicked?
In a program I'm working on I have a tab control. Outside the tab control is a button and the button is only needed when one of the tab control pages is open. How do I ensure that the button will not be visible when the user clicks on the other tab pages?
-
Apr 7th, 2014, 02:21 PM
#2
Re: How to make a button visible when a tab is clicked?
You could check which tab is selected in its "SelectedIndexChanged" event, like this:
Code:
Private Sub TabControl1_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles TabControl1.SelectedIndexChanged
If TabControl1.SelectedTab.Name = "TabPage2" Then
btnUpdate.Visible = False
ElseIf TabControl1.SelectedTab.Name = "TabPage1" Then
btnUpdate.Visible = True
End If
End Sub
-
Apr 7th, 2014, 02:57 PM
#3
Re: How to make a button visible when a tab is clicked?
You could simplify that to this:
Code:
btnUpdate.Enabled = If(TabControl1.SelectedTab.Name = "TabPage1", True, False)
-
Apr 7th, 2014, 05:42 PM
#4
Re: How to make a button visible when a tab is clicked?
Or even simpler:
Code:
btnUpdate.Enabled = (TabControl.SelectedTab.Name = "TabPage1")
.
You do not even need the parenthesys, but leave them to make it clear.
Last edited by kaliman79912; Apr 7th, 2014 at 05:47 PM.
More important than the will to succeed, is the will to prepare for success.
Please rate the posts, your comments are the fuel to keep helping people
-
Apr 7th, 2014, 05:53 PM
#5
Re: How to make a button visible when a tab is clicked?
Code:
btnUpdate.Visible = TabControl1.SelectedTab.Name = "TabPage1"
When compiled its about 4 calls less, so should be more efficient.
But the general rule is to avoid string comparisons whenever possible becasue they are very slow and integers are very efficient and fast, so use the index instead!
Code:
Private Sub TabControl1_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles TabControl1.SelectedIndexChanged
btnUpdate.Visible = TabControl1.SelectedIndex = 0
End Sub
Now the compiled code is about half the size with half as many calls compared to the string version! (Wow I wasn't expecting such a huge difference).
Last edited by Edgemeal; Apr 15th, 2014 at 07:45 AM.
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|