Form sent to back on interaction with menu item - vb.net

I've got two forms, one being frmMain and the other being frmDatasets. The idea is that frmDatasets is used to manage the application's datasets (it's a program for comparing sorting algorithms).
I have a MenuStrip on frmDatasets with a few items. I just decided to change the Add Dataset item to a drop-down menu with options for loading one from file, or generating one according to certain parameters. All well and good; just add the items, swap some icons around, and change the event handler's signature to handle the right Click event.
Except when I run the program, clicking on the Add Datasets top-level item for the first time sends frmDatasets to the back, displaying an inactive frmMain. Clicking the item again shows the dropdown menu as usual.
If I instead click another top-level menu item, that works just fine. But then simply hovering my mouse over the Add Dataset item causes the 'send to back' thing to happen.
I say "send to back", but it's really just putting it behind frmMain. It remains in front of other windows like Visual Studio and Firefox.
Anyone know what on Earth is going on with this form?
EDIT: If I show frmDatasets as a modal dialog, it stops the whole "sending to back" thing, but I still have to click the menu item twice before it shows the list.
EDIT2: Overriding the onClick event to call mnuAddDatasetDropDown.ShowDropDown removes the double-click issue, but it's only a solution if I keep the form as a modal dialog. Still gets sent to back. Overriding mouseEnter doesn't do anything to solve it.

Setting the TopMost property of frmDatasets from its Design view to 'true' fixed all of the problems I was having. No insight as to what was going on, unfortunately, but if anyone else is having this problem then hopefully it'll work for them too.

Related

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)

How can a ContextMenuToolStripItem be displayed, without doing it programmatically?

I've taken over a project, which contains some UltraWinGrid controls on some of the forms.
On one of the original forms which has been there since before I took on the project, there is a ContextMenuStrip, which has just one ContextMenuToolstripItem on it, captioned 'Default for Column'.
This ContextMenuStrip is hidden by default, however, when the user right-clicks on the UltraGrid, the ContextMenuStripItem is displayed on the grid (rather than at the top of them form where the ContextMenuStrip is).
I'm trying to replicate this behaviour in a new form that I've added myself, however, after adding the ContextMenuToolstripItem in, I cannot get it to display when right-clicking my grid.
I've put a breakpoint on every subroutine in the in the older forms class, and none of them are triggered when right-clicking it.
Additionally I have also searched the class for DefaultForColumnToolstripMenuItem, and the only place it appears is in the Click event of the ContextMenuToolStripItem itself.
So, how else is it possible to show it when right-clicking the grid? I've copy and pasted the ContextMenuStrip from the old form onto the new form and still nothing occurred.
I'm assuming it's in a property somewhere that I'm missing?
Check for a ContextMenuStrip property on the UltraWinGrid. You can set it in the designer and your context menu will appear on right click without having to deal with the MouseClick handler, checking the mousebutton used, etc.

Can't View VBA Form

So I created a form, and have been using it for a while.
All of a sudden today it stopped working. Other forms load and can be viewed but not this one.
The weirdest part is that the controls still respond!
So I can't actually see the form but I can still interact with it. (only using keyboard no mouse clicks are responding) I know the form is enabled. But I simply can't see it! I have restarted excel, and the whole computer.
I even completely removed all code in the userform to see if I could get the blank shell to load, and while I can tell it loads (it disables everything in excel until I use Alt+F4) it still won't be visible. I have checked the Enabled, All Colors, Captiuon, Width, Height, Top, Left, StartUpPostion, SpecialEffect, Zoom, DrawBuffer properties and everything is fine.
I have also Exported and reimported it and still simply nothing. Also tried importing it into another Workbook, nothing. I at my wits end (not that it's very far to reach!)
Also, I can still see the userform in the designer I can still edit it, I get NO errors. This happens not only when calling the form in code, but even when running it right from the designer.
Any one ever have this issue? Any ideas or solutions?
The issue ended up being the Top and left properties. While I did check them, they way I checked them was not accurate; I still have no idea why, but I think it defiantly has something to do with dual monitor setup.
The way I tested double checked the forms top and left properties was by creating a new form and adding a button on the button click event I had a msgbox show the top and left properties of the form at time of clicking.
I then moved the new form to where I wanted the form that woudn't show to be and clicked the button; I then set these values to the form that wouldn't show.
I tested this location and made sure to match the properties with the values I wanted multiple times and it didn't work.
For some reason the values needed where about 1000 digits off (instead of 250 I needed to use 1250) even though I had set the form right where I wanted the new one to be and made sure to save the properties when they matched what I wanted

VB.NET forms keep disappearing while system is in use

We have a "Core" system that we use to run the business and there are about 15-18 people using it at any one time. The program is written in VB.NET and has about 165 forms.
The way it works is when the user runs the program he/she is prompted to log in and if the login is successful a "Main" form is displayed with a number of menus (Customers, Suppliers...). From there they can click on the menus which open another form on top of the "Main" (the "Main" form needs to be visible in the background because it displays information that is relevant to the users while they are in other screens)
The issue we are having is that if the users have other programs open while using the "Core" system (Outlook, Word, Chrome, anything really) and switch to another program and then back to the system, it only displays the "Main" form and any other forms open on top disappear. The way we get around this is by switching back to the other programs they have open and clicking on the minimise button in the top right corner of the window until all the other programs are minimised, which only leaves the "Core" system visible. However this is becoming a nuisance to all the users (including myself and the other developer) and we really need to sort this issue out in order to keep out staff happy :)
I would appreciate any advice or pointers in the right direction which will help us solve this issue and please feel free to ask if you need any more information.
It seems you are creating the ChildForm from the MainForm but the ChildForm itself is showing itself with Me.ShowDialog(). What you should probably try is showing the form from the MainForm and passing the MainForm in as the parent. This should keep the form tied to it's parent and on top. For example:
childForm.showDialog(Me)
Where Me is the MainForm. This is the documentation for that method.
This is the important part:
Owner Type: System.Windows.Forms.IWin32Window
Any object that implements IWin32Window that represents the top-level window that will own the modal dialog box.
Does that make sense?
Changing code to show dialog will change behavior of your code little bit, like your main from execution will hold till you close child form
But you can you use only show as child (not dialog)
childForm.show (Me)
This will not change anything except whenever you click on main form it will display its entire children on it.

How to stop my tools strip menu items from appearing in the taskbar?

I have a program which runs mainly though a NotifyIcon in the bottum right of my windows screen (XP). Whenever I open the ContextMenuStrip that appears when the icon is right clicked, a box also appears in the task bar. I also have nested menus inside the menu (mouse over one item leads to another menu), and each additional menu also creates a taskbar box upon appearing. So once I am at the third or fourth nested menu, there would be 3 or 4 windows appearing in the taskbar. After the menu disapears, so do the windows in the taskbar.
How can I stop the taskbar from displaying boxes to represent these menus? I have done nothing in my code as far as I know to create this type of behavior. I have searched for similar problems but have found nothing similar. There is no "showintaskbar" property for these items as far as I can see, and no other property that I can find which would affect this. I have investigated the owner of the contextmenustrip since I read the owner may effect these type of behaviors, but that doesnt seem to be helpful as there isn't an owner property of the contextmenustrip.
I don't know what else to search for, so I am here hoping someone can give me a clue as to what else may effect this type of behavior.
Any help is greatly appreciated. Thank you!
If you are using the ContextMenuStrip.Show() method, it will display in the taskbar as you describe. Try assigning your menu to the NotifyIcon.ContextMenuStrip property instead.