ToolStripMenuItem double click? - vb.net

I have a program with a MenuStrip, containing multiple ToolStripMenuItems. There are 4 main ones, and each of those has a collection of more ToolStripMenuItems which appear as a dropdown from the main items.
I'm attempting to force the user to double click the items (this program is run on a small touch screen device and the users are accidentally pressing the wrong items by mistake...when a drop down menu appears by clicking the upper level menu, the first menu item is partially over the top level menu item, causing it to be highlighted if they hold their finger a minute too long and then "clicking" it when they lift their finger). I changed the Click event that was being fired from these items to the DoubleClick event, and changed the DoubleClick property of each ToolStripMenuItem to true, but the first click on any of the menu items causes the drop down menu to collapse instead of allowing me to physically double click the menu item.
I've been looking through the MSDN documentation but I'm having a lot of trouble figuring this one out. Below is a simple example.
Private Sub ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ExitToolStripMenuItem.DoubleClick
Me.Close
End Sub
It's not firing the event because it's not allowing me to double click the menu item in the first place(from what it looks like, anyway).

Related

VB.NET Module-level variable to store count of child forms

In this exercise, you’ll create an application with a multiple-document interface that consists of a parent form and two child forms.
Open the project and add a parent form
1. Open the CalculateFlooringCosts project in the CalculateFlooringCostsMDI directory. Then, review the code for the Carpeting Costs and Hardwood Costs forms so you understand how they work.
Add a form to the project, and set the IsMdiContainer property of this form to True to identify it as the parent form. Resize the form so it’s large enough to hold several child forms, and use the Application page of the Project Designer to change the startup form to the new form.
Add the File menu to the parent form
Add a MenuStrip control to the parent form. Then, use the Menu Designer to add a File menu to the parent form. This menu should include four menu items that display a Carpeting Costs form, display a Hardwood Costs form, close the active child form, and exit from the application. Give each menu item an appropriate name, include access keys for the menu and menu items, and include a separator bar between the Close and Exit items.
Add an event handler for the Click event of each item in the File menu. The event handlers for the New Carpeting Costs and New Hardwood Costs items should create a new instance of the appropriate form, set the parent form to the current form, and display the form. The event handler for the Close item should close the active child form, if there is one. And the event handler for the Exit item should exit from the application.
Change the Exit buttons on the Carpeting Costs and Hardwood Costs forms to Close buttons, and change the StartPosition property of these forms to WindowsDefaultLocation.
Test the application to be sure that the items in the File menu work as expected.
Add the Window menu to the parent form
Add a Window menu to the right of the File menu. Then, add three items to this menu that will let the user arrange the forms in a cascaded, vertical, or horizontal layout.
Give each item in the Window menu an appropriate name, and then add an event handler for the Click event of each item that arranges the child forms appropriately.
Set the MdiWindowListItem property of the menu strip so the Window menu will display a list of the open child forms.
Test the application to be sure that the items in the Window menu work as expected.
Add a toolbar to the parent form
Add a ToolStrip control to the parent form. Then, add two buttons to this toolbar with the text “Carpeting Costs” and “Hardwood Costs” on them. Be sure to assign appropriate names to these buttons.
Add an event handler for the Click event of each button that uses the Click event handler for the associated menu to display the form.
Test the application to be sure that the toolbar buttons work.
Add a status bar to the parent form
Add a StatusStrip control to the parent form. Then, add a single ToolStripStatusLabel control to the status bar.
Add a module-level variable to the parent form to store the count of child forms, and give this variable an initial value of 0. Add code to increase or decrease the value of this variable each time a new form is opened or closed.
Add a procedure named DisplayFormCount that sets the Text property of the ToolStripStatusLabel control to “Number of child forms currently displayed: ” appended with the current form count. Then, add code to call this procedure when the form is loaded and each time the form count changes.
Test the application to be sure that the form count is displayed properly.
It's steps 15 and 16 I am stuck on.
I have tried this:
Private Sub DisplayFormCount(Sender As Object, e As EventArgs) Handles Me.MdiChildActivate
Dim activeForm As Form = Me.ActiveMdiChild
Me.sbMain.Items(0).Text = "Number of child forms currently displayed: " & Convert.ToString(Me.MdiChildren.Count)
End Sub
And it works for the most part. Upon form loading, it shows 0, then adding a form will make the count increase by 1. The problem is when I go to close the first child window, it doesn't subract. Afterwards all window closes reduces the count by 1 and when all windows are closed, it still says there's a count of 1.

The ListBox Click event is lost when focus is set to a TabControl

I am working with a Visual Basic.NET project in Visual Studio 2017 (.NET Framework 4.6.1)
I am using a Listbox which is associated with a BindingSource.
The Listbox is contained within one pane of a SplitterControl.
I also have a TabControl is located within the other pane of the SplitterControl. This control contains child data associated with the items in the ListBox and is refreshed when the ListBox is clicked and an item is subsequently selected in the ListBox. The Click event refreshes a Treeview, which then populates the TabControl with data if/when (1) a tree node is clicked and (2) appropriate data is retrieved for that node.
The Listbox Click event works fine while clicking different items consecutively within the Listbox only.
However, once the mouse clicks in the TabControl (in the other pane of the SplitterControl), then once the initial Listbox is clicked, the Click event doesn’t fire.
I have researched this issue (on StackOverFlow as well as other forums) and suggestions have basically revolved around the idea that the Click event could be forced by calling the routine set up as the Click event handler (e.g., myListBox_Click).
I have tried this, but the problem is that I am losing the current SelectedIndex / SelectedValue.
To illustrate by reproducing the issue within the app where I am encountering the problem:
The app in question (note the Listbox highlighted by the red arrow - Screenshot 1):
Screenshot 1
Upon startup of the app, the Listbox behaves as it should, if the user clicks nowhere else, only selecting various items within the Listbox. The TabControl (initial tab shown is always the Profile tab) is refreshed accordingly.
However, if at any point, the mouse is clicked in the TabControl (e.g., to select another tab, note Screenshot 2)
Screenshot 2
Now, when the user clicks on another item in the Listbox, the wrong item is selected (shown in Screenshot 3):
Screenshot 3
The Click event is now being forced via a call to MyListBox_Click within the TabControl_Leave event; my thinking was that this was the appropriate place to put the subroutine call. My reasoning was that when the Listbox was clicked in this scenario, the first event to fire (as far as I could tell) was the TabControl_Leave event.
Not surprisingly, if the same item in the Listbox (in this example scenario, Allegheny) is subsequently clicked, than the result is what should have happened on the previous click (that the SelectedValue is correct, as seen in Screenshot 4):
Screenshot 4
Of course, this is correct, since the last click occurred while the Listbox was already the active control.
I have tried several approaches such as (1) using a global variable to store the current index/value and retrieving it, and (2) using the Tag property of the TabControl to store and retrieve the same value. This has either worked inconsistently or not at all because of the order in which the control events fire.
Hopefully, I've been clear enough on the nature of my problem/issue.
Anyone have any ideas on what my next approach could be? Any ideas/insights/suggestions will, of course, be greatly appreciated.
Thanks in advance,
Chris Fleetwood
Software Developer
North Carolina Partnership for Children (SmartStart)

Access Form Opening on Bottom of the Screen

I have an access form with about 7 tabs on it.
When I click on one of the tabs, the window automatically opens to the very bottom of the page for some reason.
I'm really not sure what's causing this... There is no VBA code stating to do this.
I tried implementing this code:
Private Sub Incident_Information_Click()
Forms![PIR Form].[Claim Number].SetFocus
End Sub
And:
Private Sub TabCtl0_Click()
If Me.TabCtl0.Value = 2 Then
Forms![PIR Form 2].[Claim Number].SetFocus
End If
End Sub
I hoped that when the user goes to the "Incident Information" tab, the window would automatically be set to the first control (in this case text box named "Claim Number").
Sometimes this works and sometimes it doesn't. The majority of the time, the screen still scrolls down to the bottom of the form.
Can anyone assist? I don't what's causing this issue and how to correct it.
Open the form in design view and select the controls (tab control) that are shown at the bottom of the screen.
Change this property: Vertical Anchor to Top.
Change your Tab Stop property to No for vertically long controls.
There are controls in some of my Tabs that are vertically long. Whenever I just clicked the tab, the scrollbar would go down. I changed Tab Stop property to No on a subform in one tab and a multiline textbox in another tab and it fixed the scrollbar jump problem.

Add user control to panel on button click

I'm new to VB.NET and struggling with below.
In my button click event I'm trying to add a user control every time a button is clicked. I only ever see one control, I presume I'm just overwriting each time. How do I get it to display each version in the list?
Dim ucMyCtrl As New MyControl
pnlAddMyControl.Controls.Add(ucMyCtrl )

Keep cursor out of all Textboxes on form

I have a form with several buttons and TextBoxes. After the user clicks on a button, the text in one or more of the TextBoxes changes, and the cursor (edit: caret, not the mouse cursor) goes into a textbox. (This question helped, identifying that the TextBox with the lowest TabStop as being the one where it would land, and explaining how to avoid having text in that box selected when this happens.) But what I'd like to see is that the cursor (caret) stays out of all the TextBoxes unless the user decides he wants to put it there -- highlight & copy something, for instance. This wouldn't be common, but it could happen.
How can I make adjustments to the form or the TextBoxes so that the cursor (caret) doesn't show up in any textbox (so long as the user doesn't click inside a TextBox)?
Thanks!
If the code in your button's click event causes the focus to change to another control, you could update the last line of the click event, like this:
Private Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
'Your code here
Button1.Focus() 'this last line of the sub sets the focus back to the button
End Sub
After some experimentation, it looks like setting the TabStop property of each TextBox to False will also prevent the cursor from moving into any of the TextBoxes on its own after a Refresh.
I suspect that sBarbacki's answer will work equally well, or probably better with a large number of controls that one wants to avoid getting the focus automatically.