Best to explain with an example.
TabControl has Tab1 and Tab2.
I'm trying to make it so when Tab1 is selected, Button1 is visible and stays visible.
When Tab2 is selected, Button1 is invisible and stays invisible. I need it to work when the Tab is clicked, not when the content area of the Tab is clicked.
Thank you.
Try this:
Private Sub TabControl1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TabControl1.MouseClick
Me.Button1.Visible = TabControl1.SelectedTab Is TabPage1
Me.Button2.Visible = TabControl1.SelectedTab Is TabPage2
End Sub
Btw, why do you need that? If Button1 is on TabPage 1 and Button2 is on TabPage2 they will appear/hide automatically.
Regards
One way you can do that is to add an "onclickclick" function to each tab head that sets the visibility style of the buttons you're trying to show / hide.
Related
I have multiple buttons on my VB.net form. I have a single ContextMenuStrip and I have assigned it to all the buttons. I can't seem to figure out how to set the button text to the menu selection based on which button I right clicked on.
Any ideas? Thanks in advance.
My code:
Private Sub PuTTYToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles PuTTYToolStripMenuItem.Click
Dim btn As Button = CType(sender, Button)
btn.Text = "PuTTY"
End Sub
So my MenuStrip property Dock is: None
My menustrip is not visible when I align it with tabcontrol but my linklabel is visible, how can I make my menustrip visible aswell?
http://i.imgur.com/XSV9Pcb.png
I want to change how the submenu will show when I click my Menu, by default it is showing at the right side
http://i.imgur.com/IWoiyf9.png
I want to make it show below the menu like this (edited)
http://i.imgur.com/dOtF6Ve.png
For your Third Query : Change Alignment of Your Parent Menu (e.g. Settings in your image ) to Right.
This would probably be easier if you just used a button to show a ContextMenuStrip:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
ContextMenuStrip1.Show(Button1, _
New Point(Button1.Width - ContextMenuStrip1.Items(0).Width, _
Button1.Height))
End Sub
Result:
I have a tableLayoutPanel in a form. There are 10 rows and 10 columns in tableLayoutPanel. Each cell contains a button. So there are 100 buttons. When a user clicks on any of the button I want to change the backcolor of that. Particular cell. How can I achieve this?
TableLayoutPanel's cell does not have a property to control background color. Instead, you can put a panel on it, which would in turn host your button. Assuming your buttons are dynamically created and a generic handler is attached to every one of them, the following code will change back color of the panel when the button it hosts is clicked:
Private Sub Button_Click(sender As System.Object, e As System.EventArgs)
CType(sender, Control).Parent.BackColor = Color.Black
End Sub
i have a datagridview. On right click it shows a contextmenu but it is always in the right upper corner. I want it so that the menu appears on the cell where user right clicks. It could be Cell 1 or two or whatever.
Thanks
Furqan
The easiest way to do this is to handle showing your context menu on your own (not using the context menu property on the grid view) on MouseDown for the data grid. Like this:
Private Sub DataGridView1_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles DataGridView1.MouseDown
If e.Button = Windows.Forms.MouseButtons.Right Then
ContextMenuStrip1.Show(CType(sender, Control), e.Location)
End If
End Sub
I have a tab in a windows form called Wafer Map that has three sub-tabs. The First sub-tab is the called Map and has a Load and Skip button. I am trying to set the focus on the Wafer sub-tab on the Load button click. This is the following code I have tried to use.
Private Sub Load_Wafer_Layout_Map_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Load_Wafer_Layout_Map.Click
Wafer_Info.Enabled = True
Wafer_Info.Show()
End Sub
The Wafer_Info.Enabled = True is used to enabled all of the controls on the Wafer tab and works properly when the button is clicked. I have tried using .Focus() and .Show() to bring focus to the next tab but I am not have any luck getting to switch. Anyone have any suggestions?
Just set it:
tabControl.SelectedTab = yourTab
On the Tab Controls Tab Pages, just ensure you name the tab you are attempting to reference. Additionally, see MSDN TabControl.SelectedTab
The code that worked for me is Tab_WaferMap.SelectTab(1). Tab_WaferMap is my main tab and the 1 is the index of the sub tab I wanted to show
I came across this thread as i was looking for a solution to my own focus issue. I have a TabControl with many TabPages. Each TabPage is set to auto scroll due to overflowing content. The problem I ran into was the mouse scroll wheel would not function if the TabPage did not have focus. Since there is not an event for each tab click it made setting focus to each TabPage a challenge. It was not hard, but a challenge none the less. So, here is my code (assuming auto scroll true).
On form load sets focus to main TabPage:
Private Sub frmParent_Load(sender As Object, e As System.EventArgs) Handles Me.Load
TabControl1.TabPages(0).Focus()
End Sub
Sets focus to current TabPage by getting the index then setting focus.
This is triggered by TabControl1.SelectedIndexChange event.
Private Sub TabControl1_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles TabControl1.SelectedIndexChanged
Dim intTabIndex As Integer = TabControl1.SelectedIndex
TabControl1.TabPages(intTabIndex).Focus()
End Sub
I hope someone find this useful. It was very useful for me.
Joshua
You can also set the Selected Index of the tab (and sub-tab) using a (zero based) numeric value:
TabParent.SelectedIndex = 3
TabSub.SelectedIndex=2