VB.Net - Some menustrip questions - vb.net

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:

Related

How do I show a ToolStripMenu after user right-clicks a ToolStripMenuItem?

When the user right clicks on a ToolStripMenuItem (which is part of another ToolStripMenu), I want to show a new ToolStripMenu.
I'm using Visual Basic
I tried creating a ToolStripMenu and adding an Items in code. But when right clicking (on the ToolStripMenuItem) I cannot see the new ToolStripMenu. Is it maybe because I didn't define the location where the new ToolStripMenu should be visible?
THE CODE:
Private Sub RappelVerkoopfacturenToolStripMenuItem_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs)
If e.Button = System.Windows.Forms.MouseButtons.Right Then
Dim tsFavorites As New ToolStrip
tsFavorites.Items.Add("Add to favorites")
tsFavorites.Show()
End If
End Sub
You have to add the new ToolStrip to the Forms´ controls:
Me.Controls.Add(tsFavorites)
Additionally you don´t have to call the Show() method. Change visibility with the Visible property:
tsFavorites.Visible = True
(Nevertheless, the control is visible after adding it to the controls of the form by default. So you don´t have to set it explicitly.)

Contextmenu position in vb.net

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

Setting Focus on a Tab

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

Panel problem in visual basic 2010

I created a panel and I added a link to other form using the code
Private Sub Panel1_Paint_1(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint
AdminLogin.TopLevel = False
Me.Panel1.Controls.Add(AdminLogin)
AdminLogin.Show()
End Sub
The panel is displaying the adminlogin form which is inside the panel but when I click any buttons inside the adminlogin the adminlogin form blinks.
Why this blink is occurring ? how can I stop it?I had also added me.refresh inside the panel but it is not working?
Why this blink is occurring ?
It is blinking because you are adding a control every paint the panel which happens when you click on a button.
how can I stop it?
You only add the control if it is not already been added.
Of course this doesn't mean your overal design isn't flawed.

How Can I Create a Mouseover Tooltip on an Image in VB.NET?

Can I create a tooltip that will show up when a user moves his/her cursor over an image? I can't find such a property in Visual Studio, and I've scoured Google to no avail. I'm using an image in a PictureBox.
Here's to anyone out there on StackOverflow instead of some awesome Halloween party! Yay!
yea, for some reason the Picturebox doesnt have one.
imports System.Drawing
dim tt as new ToolTip()
tt.SetToolTip(picPicture, "This is a picture")
and dont worry, the weekend has only started, plenty of time to party.
Typically I create the interface then throw a ToolTip object from the Toolbox on to the form.
This then gives each object the "ToolTip" property (towards the bottom of the list) which can then be configured to your delight.
Drag a ToolTip control from the toolbox on the left onto your form (the designer will then put it below your form, since it's not meant to be visible normally). By default it will be named "tooltip1".
Then select your checkbox and go over to its properties window. You should see a property labeled "Tooltip on tooltip1" - set this to whatever you want. When you run the app and hold the mouse over your checkbox, you should see the tooltip text.
Assuming that you have added a picture box member with the WithEvents modifier you can use the following
Private tt As ToolTip = New ToolTip()
Sub OnPictureMouseHover(ByVal sender As Object, ByVal e As EventArgs) Handles PictureBox1.MouseHover
tt.Show("the message", Me)
End Sub
Sub OnPictureMouseLeave(ByVal sender As Object, ByVal e As EventArgs) Handles PictureBox1.MouseLeave
tt.Hide()
End Sub