Change tab order inside ToolStripMenu - vb.net

When the ToolStrip control is focused the first ToolStripItem is focused too.
I need to set the focus to the second item, but there is no TabIndex property in ToolStripItems.
I've tried to select the item manually when the ToolStrip gets the focus, but there is no Focus method either.
Actually, we use a inherited control, so I can create custom properties/methods, if it's needed.
Any idea on how to achieve this?

The ToolStrip is doing something when it fires the Enter event, so just setting the focus on a ToolStripItem won't work unless you focus after the enter event code has completed. The BeginInvoke method is a way to run code after the event has finished:
Private Sub ToolStrip1_Enter(sender As Object, e As EventArgs) Handles ToolStrip1.Enter
Me.BeginInvoke(New Action(Sub()
ToolStrip1.Items(1).Select()
End Sub))
End Sub

Related

Handle Control in UserControl click

I made a user control, with a picture box and 2 labels. Whenever i click on any of the controls in the user control in a form, the user control click event does not happen. How can i do for when i click any of the labels or the picturebox the usercontrol.click event happens too?
The labels are "label1" and "label2", The picture box is named "pic1".
The usercontrol's name is "Tile".
Please Help!
I have tried something like event handling, using addhandler but it confuses me a little...
Public Event ItemClicked()
`Private Sub Pic1_Clicked(sender As Object, e As EventArgs) Handles Pic1.Click
RaiseEvent ItemClicked()
End Sub`
But i'm stuck there, i don't know what else to do.

Catching event when a control loses child control

Imagine this application in Vb.net, I have 2 panels and several buttons. I am moving buttons from a panel to other panel (through catching drag and drop events). I reached it.
Now I am trying the following:
Is there any way to raise an event from a panel when this panel loses some child button (or control)?
Thanks in advance.
Try this event when a control has added to the panel :
Private Sub Panel1_ControlAdded(ByVal sender As Object, ByVal e As System.Windows.Forms.ControlEventArgs) Handles Panel1.ControlAdded
End Sub
And this when a control has removed :
Private Sub Panel1_ControlRemoved(ByVal sender As Object, ByVal e As System.Windows.Forms.ControlEventArgs) Handles Panel1.ControlRemoved
End Sub
The panel control doesn't seem to have an event that fires when its child control collection changes. source
The best thing to do would be handle this as part of the drop event. Presumably you have some code to determine if the button is to be moved. If this is true, call a function to do everything you want when a panel loses a control.

Why does my new form move behind the opener?

I'm not going to post a bunch of code here since I do not think it is a code issue.
Here is a link to my original question where I have shown the code if you are interested. Code
Just as a test I created a blank form window (Form1.vb) and no code gets passed to it and no code runs when it opens. If I do Form1.Show() from a MenuStrip Control or a Button Control, the window opens and stays on top. Now if I do Form1.Show() from a TreeView Control, the window opens and goes behind the window with the TreeView Control.
So my question is, what is different about the TreeView opening a form vs a button or other control?
I am using the basic VB TreeView Controll, and the new form is being called in AfterSelect method for the TreeView.
The AfterSelect works if you use your keyboard navigation to select a node, but it doesn't work when you use the mouse because the mouse capture is forcing the parent form to remain in focus. You would have to run your code after the AfterSelect event:
Private Sub TreeView1_AfterSelect(sender As Object, e As TreeViewEventArgs) _
Handles TreeView1.AfterSelect
Me.BeginInvoke(New Action(Sub()
Dim f2 As New Form2
f2.Show(Me)
End Sub))
End Sub
Use the Form.Show(parentForm) option, this will always put the new form on top of the old one.
have you tried Form1.ShowDialog() ? or if you don't want to show it as a dialog you should use:
Form1.Show()
Form1.BringToFront()

All Controls Click event on form

Is there a simple way to Activate the form when any controls in the form is clicked like datagirdview, panel, menustrip, button, textbox, label, etc....
it happens that my project can show many different form and it's hard for me to activate one form when it's on the back of the active form. I need to clicked the border of the form to activate it.
most likely your problem arises because your form is MDI child.. you'll have to click the menu bar to activate the form.. but if you have a borderless form, clicking on controls wont activate the form.. again, this usually happens on MDI but it shouldnt happen on a regular winform.. unless you have other running events in the background that interferes with the process.
You question is not clear at all, and I don't know what you are trying to archieve, but for executing something with a click event you have to add the handler for every control.
If you are declaring it not dinamically just:
Private Sub ControlsClick(sender As Object, e As EventArgs) _
Handles Panel1.Click, Button1.Click, TextBox2.Click ' etc.
Me.Activate 'Or Whatever
End Sub
You have to add the handler for each control. The same if you do it dinamically:
Private Sub InitializeClickHandlers(sender As Control, Optional bChilds As Boolean = True)
For Each elem As Control In sender.Controls
AddHandler elem.Click, AddressOf ControlsClick(elem, New EventArgs)
If bChilds AndAlso elem.Controls.Count > 0 Then
Call InitializeClickHandlers(sender)
End If
Next
End Sub
Then, for every control in the form, you call it like: Call InitializeClickHandlers(Me)
Or, for every control inside a panel: Call InitializeClickHandlers(Panel1)

Dirty Form with TabControl

Hi I have a form with a TabControl, 3 tabpages and controls(textboxes and comboboxes) in each tabPage.
I have one event for all the changings of the controls in tabPages (controlValueChanged) and one event for the tabControl.SelectedIndexChanged.
So I want to my button (btnOK) enabled if the form is Dirty.
Private Sub controlValueChanged(sender As System.Object, e As System.EventArgs)
If bLoading=False 'bLoading is a boolean that is true after I create and populate the controls
Dirty = True 'Dirty is a boolean property
End If
End Sub
So when I change something in one of my controls the event is fired and btnOK is Enabled.
The problem is that the first time that I change (visiting) to a tabPage the controls is that TabPage fire the controlValueChanged event causing my button to Enabled even if I haven't changed anything in my controls.
If I am visiting a TabPage for second time the event is not fired.
I know that this is normal but how I can overcome this problem and have my Dirty =true only if the control is fired because of something is changing and not when the tabPage is changing?
What about creating a new boolean variable - DoNotMakeDirty, say, then you could, in the TabControl1_SelectedIndexChanged sub, set DoNotMakeDirty = True and then put an if statement in your controlValueChanged sub.