Set dropdown direction in WinForms - winforms

By default, a winforms dropdown always extends to the right from the dropdown button / menu item. However, I have a toolbox button (similiar to chrome's options button) which is on the far-right side of the window; when clicked, the default menu would always extend outside of the window.
Are there any built-in ways to make the menu drop left from the dropdown button, or do I have to set the menu's position by hand, and manually show/hide?
Edit: there are 2 situations, where such behaviour is less than optimal:
if it's not full-screen, or close to the right end, it will hang out from the app's window; and
In a multi-monitor enviornment, it drops down on the next monitor

Take a look at this:
http://msdn.microsoft.com/en-us/library/system.windows.forms.toolstripdropdowndirection.aspx
Assuming you're using .NET and ToolStripMenuItems, there is a DropdownDirection property that you can set to one of these enums.

IIRC, it actually checks the size of the screen (not the window) and will drop the to the left to avoid going off of the screen. Would that be good enough?

Related

How to make a "flyout" control without affecting other controls in menu

Alright, here comes something tricky and I really hope there's some WPF guru here who knows a solution or at least a good approach for it:
I got a menu which can be switched into compact mode. In this mode only the label color, the icon and some informational controls are visible. All content of the menu item is hidden.
Now Normal and Compact modes are nice, but not very smooth. In compact mode the whole menu expands when you move your mouse over it. I'd like to achieve this effect with just one single menu item, but without resizing the whole menu (since the menu has a different background than the rest of the window, it would be visible that the whole menu expanded but not all menu items).
My idea is a "flyout". This alone might not be too difficult to implement, but there's some criteria which should be met in order to make it look good.
Here are pictures of the compact menu and one item in it's normal state.
Now I'd like to achieve that when you move over one of the compact entries, the entry kinda flies out to the left and is visible in it's full state like a popup. The problem here is: I can't remove the control since this would alter the menu order (visibly). I can't use a VisualBrush since it needs to be interactive.
As you can see, this looks pretty ugly.
That is what I would like to achieve (just poorly pasted in):
Any ideas how you could implement this?

RichTextBox scroll to end not working when not visible

I have a WPF RichTextBox in my application that sits in Grid. It gets updated every second or two as it displays logs (though sometimes there are no logs for up to a minute depending on the load).
The grid is not always visible, as it sits in its own tab. If the user is on another tab, the logger is not visible.
My problem is that I want the RichTextBox to scroll to the end every time a new paragraph is added. It seemed simple as there is a 'ScrollToEnd' method on the RichTextBox control and so I call that method every time text is added to the control.
The problem is that that method only works if the control is visible, if the user is on another tab, the RichTextBox will not scroll to the end and it looks weird when you click on the tab with the logger and after a couple of seconds or longer it scrolls to the bottom when it should already be at the bottom.
Is there a way around this annoying "feature" of the control? I would like to ALWAYS have the RichTextBox be at the bottom unless the user is manually taking control of the scroll bar.
Thanks!
By default, the TabControl actually doesn't change its contents visibility, it removes them from the view completely when you change tabs and then "re-attachs" them when you navigate back to the previous tab.
That's why the Visibility change doesn't get fired. Instead, you should handle the Loaded event, which should get fired right before the view is re-rendered.
Is there a reason you cannot simply call ScrollToEnd in response to the text box becoming visible? That seems like the simplest approach. Did you try it and run into an issue?
Edit: If you are using a TabControl, each TabItem has an IsSelected property you can bind to from the ItemContainerStyle. You could probably scroll your text box in response to the tab becoming selected.
As a separate note: if you are planning to make a custom control for this, here are some things to consider.
I wrote an auto-scrolling version of a FlowDocumentScrollViewer. (I never needed a RichTextBox specifically, but they display similar content.) I can tell you that there are a lot of things to account for, such as knowing when and when not to auto-scroll based on what the user is currently doing.
For example:
If the user takes over the scrolling themselves via the scrollbar or mousewheel, you don't want the control to fight with them.
If they start selecting text, you don't want to scroll it away from them mid selection.
If they scroll to the bottom, you probably want it to start auto-scrolling again.
Also, determining what the user is doing to begin with can sometimes be a complex process on its own.

Where is the Tab Order Assignment dialog in Visual Studio 2012?

For as long as I can recall, Visual Studio has had an integrate dialog that allows you to easily organize the tab order of your controls.
I've just created my first VS 2012 WinForms project, added all of my controls and went to find the Tab Indexing dialog, and it appears to be missing from Visual Studio.
I found this MSDN article which states that I can open this dialog by going to FORMAT>Tab order. The problem is that there is no Tab Order option on my FORMAT menu. Alternatively, the documentation states th at Ctrl+D should open this dialog. It doesn't.
Another alternative is to select the VIEW>Tab Order menu option. This method causes Tab Index boxes to hover over your controls. You can subsequently click on your controls, one at a time, in the order in which you want them to tab, to set the tab order.
This isn't acceptable because my form contains numerous panels and group boxes that cover one another. It is impossible for me to click-through my controls because many of them are no longer visible in the designer.
Is there an easy way for me to setup the tab order of my controls like there previously use to be within older versions of Visual Studio?
It is still available, you just need to add it back to the View menu. Tools + Customize, Commands tab, Menu bar = View. Select the menu item in Controls where you want to insert it, say the bottom one. Then Add Command, Category = View, Commands = Tab Order.
Your memory of this command does sound a bit hazy, it was never on the Format menu and its never been a dialog. If you want to put it on the Format menu then you can, just pick the Format menu bar in the Commands tab. You can't make it a dialog though, it numbers the controls in the designer view. Some odds that you actually remembered the View + Document Outline command.
Go to your alignment toolbar. At the end, click the tiny little "Add or Remove Buttons" down arrow. Click the "Add or Remove Buttons" button, and look towards the bottom of the list. You should see Tab Order. Click on that and it will be added to the alignment toolbar.
I found this to be very useful http://msdn.microsoft.com/en-us/library/csz6b8x8.aspx
It allows you to simply click on the various controls in the order that you want them to tab through. You do this while you are in the "Show tab order" mode as described above; the tip from Elton about adding the icon to a toolbar makes it easy to toggle the mode.
Ctrl-doubleclick the first control, then click subsequent controls, and press Enter to terminate. You can also start on the Nth control if you Ctrl-click the one before it, then click in order as normal.
(VS Express 2013)
The Tab order tool from the view menu disappears in some cases. For example, if you clikc a text box, then go to its properties, the tab order option will not show. You must select a control, then immediately go to the view menu and choose tab order.
You can click through your controls with the Document Outline view. If they all have the same TabIndex value, their Z-order will be used as tab order. The Z-order can be changed also with the Document Outline view.

Word style context menu in WPF?

What controls would be most suitable for creating a complex context menu, similar what you see in Windows Word. Should it be pop up, tooltip, or context menu or a transparent window?
What you think would be the best control to start with?
I'd start with a ContextMenu, since that is the behaviour you want. Unlike a ToolTip that won't automatically disappear after a few seconds, and it is already set up to by a collection of MenuItems.

Use popup or dynamic C# winform screen (or other solution)?

On C# winforms project, I have a small table, a filter box, an Add button and a Done button grouped together, and they all fit together within 250x250 pixels. I only need to show these elements to the user when they press a button. I figured this could be done using a pop up modal screen or by making room on the main screen until the user presses the Done button.
I know a disadvantage to modal screens is that they can cause problems for users when/if they lose track of the modal screen and then they think the program's not responding.
The disadvantage I see for using a dynamic main screen is that the reshaping interferes with the overall layout. But maybe I could find a way to overcome that problem.
I'm new to all of this, so I wanted to ask opinions here. Thanks.
Put them all on a panel (or, even better, a custom control), style it to look nice, and then only show the panel on button click.
If you put them in a groupBox or FlowLayout panel possibly in the corner of the main screen and then set the visibility or even enabled on the entire control when they can or can't press the buttons works well.
disable until time they can edit.
groubB.enabled = true;
or
groubB.Visible = true;
When the user clicks the button, could you disable all of the controls in the main form and then place the panel in the center of the main form, on top of the other controls? Maybe make the panel a little larger with some decoration around it for emphasis. Then, when the user clicks 'done,' dismiss the panel and re-enable all of the controls in the main form.

Resources