I have a WPF menu which I add items to programatically. It consist of a couple of MenuItems. However, in one of the menuitems I add a ListBox.(I needed a scroller because we have many items and that made it easy).
The menu looks fine and works. The problem is that after I select (click on) something on the ListBox the menu closes as expected; but if I move the mouse over it, the menu pops open. I have searched all over the internet with no luck which is not surprising since it is pretty custom stuff.
The last thing I tried was checking the events and see if I can handle them. I can detect the MouseOver. However I do not see any PopOpen or OnClick event for the menu.
Any ideas if I can detect these events? Any other ideas, suggestions would be appreciated. And if there is a way to add a scroller to a bunch of MenuItems then I may change my design as well.
Related
I can't seem to fix this issue (which i hope is small) i have somehow when adding a ContextMenu did something to have the MainMenu bar not show up when i debug, if i click on the "MainMenu" in the designer (1st image) the menu bar shows up in the designer fine:
But if i click off it, then click on another control like:
The MainMenu disappears from the designer, when i build / debug the MainMenu is gone, is there a way to fix this easily enough (i assumed it would be as simple as checking a setting but googling did not return anything that i saw that was helpful)
Any help would be appreciated.
It looks like your MainMenu has ended up hidden behind your other controls. Try right clicking on the main menu and selecting Bring To Front. If you can't right click on it, right click on the control that's filling the rest of the form and select Send to back.
When you click on a menu control in the component tray it will always show it at the top of the screen (even if you click on a ContextMenu).
One other thing worth doing is to open the Document Outline window from the View->Other Windows menu in Visual Studio. This gives you a hierarchichal view of all the controls on the current form. You should be able to see your main menu here (unless you've somehow removed it from your form!)
This is for WinForms.
I am having a strange problem that is driving me absolutely batty. I have a tab control for which standard system events, and only standard system events, are not firing. The specific event I was trying to get to fire was the TabIndexChanged event. It doesn't matter whether I add this programmatically or with the designer.
Note: Mouse events will fire. Keypress events will fire. All other events that I have tried will fire.
System events on OTHER controls will fire.
It isn't a single tab control that is having a problem either. If I drag a new tab control onto the form it will also have this problem.
I do not really have any code to show here because it would just be the event as generated by the designer and a Console.WriteLine message to see if it is firing (this line outputs for other events). What I am hoping for is some insight as to what could cause this problem.
The entire program is quite large, so I cannot really clip the whole thing into this forum so that individuals can hunt for a specific problem. My hope is that somebody might be able to point me to what might cause this behavior. I am thinking that maybe something got screwed up when editing in design mode, but I just do not know what to look for. I am relatively new to C# and programming is a hobby for me.
Thank you for your time,
FC
You need to try the property SelectedIndexChanged; to expose that property, with the property window open, click once outside the tabbed container then click one of the small tabs once, don't click inside the tab area. Find the property, type in an event name and then double click it.
When I'm making a Windows form application, and I use the toolbox and drag an item onto the form, I get a nice tool on the form, like button, listbox, etc. When I double click on the button, listBox, etc it goes to the text code part where all the delegates are. Also known as the event handlers. But what happens when I want to delete an item on the visual part of the application (the Code.cs[design] part)? I select it, then right click it and then delete it. It's off the screen. But, the problem is with all the event handlers. They're still left in the text-based code section but I don't need them there at all, and they generate a whole bunch of errors because references are gone, etc.
So, basically, I'm asking someone on the forum how to completely get rid of a button, listBox, both the visual part of it in code.cs[design] and in the code.cs part? I don't want to go line-by-line in deleting junk, I want to get rid of the button/listBox and it's accompanying code in one fell swoop.
It will delete such an automatically added event handler. But only if you didn't modify it and left it untouched with no code added. Visual Studio will not delete code that you have written. The reason for that should be obvious.
If this happens a lot then you need to get a pair of scissors and cut the mouse umbilical cord. Design first, program later.
I can't be done and it shouldn't.
You first delete the visible control and after that you delete the code stubs.
The handler assignments in the Designer.cs are then being deleted with the visible control automagically, as they were created.
Just make sure to get the order right: first delete the controls then the code.
Unless you mix those up there is no need to ever edit the designer.cs file. The code may contain important stuff you wrote. Therefore is is not deleted by studio.
You create it, you delete it! Two steps, period.
PS: The code stubs are (unfortunately) added chronologically. It would be nice if they were grouped by the controls they belong to. If you are in doubt, you can always use the 'find all references' command to find those methods buried in the past..
If you have a code stub generated, delete the method. Once that's done, Click on your 'forms view' - you will have an error screen shown.
Click on the link, and it will being you to the designer view, with your cursor shown on a specific line. Delete this line of code. Having that done, you could then delete the physical element from your designer.
I'm looking to have a Windows Forms toolbar overflow its buttons onto a second toolbar another level down rather than having the dropdown menu. We find that it is not obvious to our users that they need to click the dropdown to see more tools. Suggestions?
Break your toolbar up into several smaller toolbars, like how MS Office does it. This way you can arrange them on as many rows as you like.
If breaking this into multiple toolbars will not provide the user experience that you want (although it is clearly the best practice), I believe you can listen to the Resize event, and then move all items from the Items collection that have IsOnOverflow set to true to a second tool strip.
I started noticing strange behavior when navigating the main toolbar of my Winforms application, and I don't know how to fix it. When I initially open the dropdown of the File menu, it looks like this:
I begin to scroll down each item with the arrow keys, and everything is fine until I reach "Exit". As soon as I hit the down arrow key from "Log Off", or if I hit the up arrow key from "Open", the menu rearranges itself to look like this:
I'm puzzled by this behavior. The menu still works, and from this point, if I start scrolling up, I can get the arrangement back to normal:
A few observations:
The menu still works.
This doesn't happen when using the mouse.
I have some code that toggles the Visible property of some of the menu items. I was able to modify what the arrangement was by playing around with this, but it was still messed up.
Can anyone help me understand what is going on, and how to fix it?
I found the source of this problem. It is a known bug that Microsoft apparently doesn't intend to fix. The problem happens when you attempt to toggle visibility/availability of menu items during runtime. Microsoft reminds us that "this issue is purely visual, there's no functionality loss."
Their suggested workaround is to add/remove the menuitems rather than show/hiding them.
Another workaround is suggested on the forums: deriving from ToolStripDropDownMenu, turning off AutoSize, handling it on your own, and adding 1 extra pixel of height.
I found a blog post that addressed this issue, but the author never got around to posting his solution. He makes a useful point concerning Visible vs Available, however.