how to use dock window & non-dock together - c#

I need some part of UI to behave like dock window, but not all. I wonder if that's possible to mix the two. Say, I want 3 datagrids to be fixed in their positions, but I want settings windows to dock on right side or in middle of main window, when mouse hovers on it, it will expand and show all settings, when mouse moves away, the setting window simply collapses. but I do not want the other 3 data grids to move or collapse. I'd like the data grid show up as normal, not like a dock document.
Thanks
Edit
My project uses both WPF and WinForms. So I am looking for solutions for both

Just dock the settings to the right and listen to the MouseEnter and MouseLeave events. Change the width of the settings to zero, or something very small, when MouseLeave, and back to full width on MouseEnter.
Resizing a docked control behaves very nicely.

Related

How to run or adjust Windows application efficiently in any screen resolution in C# 4.0?

How to run or adjust Windows application efficiently in any screen resolution in C# 4.0?
I have done it in 1600 x 1200 resolution but if I try in lower resolutions only some part of the forms are visible.
How to solve this problem? I have searched a lot and got to know about Anchor & Dock will be useful but also to came to know that these should be used from the beginning of designing but I have completed my application while this resolution is now causing the problem when I install the application in any system
The quick and dirty method of making sure your controls remain visible would be to place a Panel on the form, set Dock = Fill and AutoScroll = True, then place every other control in your form inside it. Your controls won't get cut off, but your program won't win any awards for asthetics. If the program is brand new, that's really not the way you want to start things off.
You could redesign it to make use of Anchors and Docking, as you mentioned. You could also place items such as a row of Button controls or a series of TextBox controls in a FlowLayoutPanel, which will take care of repositioning them as you resize the form.
But if adjusting for screen resolutions is important to you, a better way would have been to use WPF from the start. Controls are automatically resized and repositioned as needed, based on their container control.
The real question should be:
How do I want the controls to resize themselves with their parent?
The answer is that you need to specify anchors. Anchors are used to tell your controls how they should react on resize, and what the concerns should be.
Lets say you have a form with two [Cancel] and [OK] buttons. They are usually seen fit at the bottom right of your window. But the default Anchor property is set to Top, Left, so on your form's resize, they stick to the Top, Left corner where they belong according to the default settings. This won't be any trouble if your maximize your form, thus you'll have your button probably in the middle of the screen. But at least, you will see every controls adequately.
But what if resize your form smaller and smaller? Do you still want them to stick at the Top, Left, or Bottom, Right would be more useful? My guess is that you should set the Anchor property to Bottom, Right, for those two.
This might come in handy to have different Anchor property settings depending on how you want your control to react to your form resize. Let's take three TextBox controls aligned horizontally with each other. Perhaps your longer field will be your object Description property located on horizontal-center of your form. Then, when you risize, you have to think what would make more sense on resize. If it is to make it longer on resize in order to fill your form width with all your control, then perhaps you want the DescriptionTextBox to get wider and wider, and the contraray should also be true, on form's resize, you probably want this field to be resized smaller too. Then, to make this happen, you have to set the Anchor property to Left, Right, so that the edge of your DescriptionTextBox control remains at the same very distance of your form's edge at any time.
Another thing is of concern in case of resizing to smaller window, is its MinimumSize property. One shall agree that there is use to have a form of size 34x34 pixels. So, setting your MinimumSize property to a certain size which makes sens for the form to exist, you will avoid display glitches of controls getting one over another.
For more details on the Anchor property: Control.Anchor Property
For more details on the MinimumSize property: Control.MinimumSize Property

How to disable a Grid (Panel) in XAML Metro app?

I want to emulate modal dialog in XAML Metro App.
So I was going to set .IsEnabled = false on all controls apart from the one which will pose as a modal dialog.
Apparently IsEnabled not in Grid not in Panel not in FrameworkElement. How to disable it not making a user control out of it?
I guess Sinofsky cut so many corners that the whole thing is now more like an Escher staircases. I am loosing my faith. Please help
Sorry, I am a little late to the party...
Here is how I created a modal popup - I used a popup dialog where the top and bottom portions are transparent so that anything behind it will show through. When the popup is opened, I set its size to cover the entire screen.
The top and bottom portions of the popup also are set to autosize (height = *), so that they fill up the entire top and bottom of the screen. This prevents any input from going into the grid underneath.
Here is a screen shot of my popup in Visual Studio:
The popup is a grid with 5 rows, 3 for the dialog itself and 2 for the transparent top and bottom.
Here is how the popup looks in my app. Obviously the grid shows through the transparent top and bottom. Since the popup fills the entire screen, any input (keyboard or mouse) goes to it rather than the grid underneath, making the popup act like a modal dialog.
Be warned though that with this strategy, you have to handle these events:
Screen resizes (full screen, snapped view, filled view) - you need to resize the popup to fit within each of the view states
Screen rotation - again, you have to handle resizing here
Keyboard popup - you need to shift the popup up so that the onscreen keyboard does not interfere with it.
Set IsHitTestVisible = false on the background content.
Additionally you could set focus to something in your modal layer root and set TabNavigation to Cycle on the modal layer root to make sure that users can't tab/shift+tab out of it. Also make sure the modal layer is all hit test-solid - e.g. Transparent or has some other fill so users can't click through it.
Also make sure no Popups show while your modal layer is visible.
Unfortunately no one seems to know (except Mr Skakun who gave wrong answer and never bothered to revise it).
Hence my solution (the simplest) is to make the element in question Hidden - I cant find any other ways to 'disable' a grid.
If I wanted to disable it correctly I would have to write a recursive function to find all FrameworkElements in the grid children and set IsEnabled = false though.

How to automatically expand textbox

When I expand the window, the textbox contained in it is not expanded. Can I expand it automatically when I expand whole app?
I can not find property for this
http://msdn.microsoft.com/en-us/library/system.windows.forms.textbox%28v=vs.71%29.aspx
The Anchor property in the designer. Set it to Left,Right,Top,Bottom. This will cause the size of the text box to be linked to the size of its parent control.
Anchor and Dock Properties
These two properties are especially useful when you are designing your form. Ensuring that a window doesn't become a mess to look at if the user decides to resize the window is far from trivial, and numerous lines of code have been written to achieve this. Many programs solve the problem by simply disallowing the window from being resized, which is clearly the easiest way around the problem, but not the best. The Anchor and Dock properties that have been introduced with .NET lets you solve this problem without writing a single line of code.
The Anchor property is used to to specify how the control behaves when a user resizes the window. You can specify if the control should resize itself, anchoring itself in proportion to its own edges, or stay the same size, anchoring its position relative to the window's edges.
The Dock property is related to the Anchor property. You can use it to specify that a control should dock to an edge of its container. If a user resizes the window, the control will continue to be docked to the edge of the window. If, for instance, you specify that a control should dock with the bottom of its container, the control will resize itself to always occupy the bottom part of the screen, no matter how the window is resized. The control will not be resized in the process; it simply stays docked to the edge of the window.
try using the property "Dock", if you are working with winforms

Tabpage Resizing

A disclaimer first! This might be a very fundamental question, but I have started learning Winforms Application Development on my own (.net 3.5,C#), and I have this resizing question.
I am developing a small Winforms application that has a standard tab control (along with many other controls) placed in the form. (It has 5 TabPages)
The AutoScroll property for the TabPage has been set to “True”. On reading up what I got to understand is that this will enable the scrollbars to show up at run time while resizing. i.e if the height of the form is reduced it will cause the vertical scrollbar to show up within the TabPage.
While the application is running, what I noticed is that if I reduce the height of the form using the little double headed arrow, the scroll bar does not stay on top, i.e if I adjust the height from below, the bottom end of the scrollbar is no longer there. More precisely I am just looking for a way to keep both ends of the scrollbar on top within a TabPage when the form containing the Tab control is resized.
It sounds like the problem is that the tabbed control will show scrollbars and may well autosize, but you haven't told the form what to do.
You might want to look at the 'Dock' property of controls, which causes a control to fill a specific area of the form (or other parent control), no matter what it is resized to.

Docking and Anchoring on a Windows Form application

I'm developing an app for Windows Mobile 5.0 and above, with C# and .NET Compact Framework 2.0 SP2.
I have a WinForm with two panels inside (upperPanel and bottomPanel). I want that upperPanel always fill 2/3 of form's height, and bottomPanel fills 1/3 of form's height. Both panels will fill completly form's width.
I've used this:
upperPanel.Dock = Fill;
bottomPanel.Dock = Bottom;
But upperPanel fills the form completly.
How can I do this? I want, more o less, the same gui on differents form factors and on landscape or protrait mode.
Thank you.
What you need to do is to put the bottom panel on first and set its Dock property to Bottom. Then set the panel's height to be 1/3 of the form's height. Finally, add a second panel and set its Dock property to Fill. The key here is that you want to add the control that will fill the remaining area to be added last. Alternatively, you can play around with the Bring to Front and Send to Back commands in Visual Studio to get the designer to cooperate.
You may also need to hook the OnSizeChanged event for the form and re-set the height of the bottom panel to account for layout changes. It's been a little while since I did compact framework programming, so I'm not sure.
Right click on the upperPanel and select Bring To Front. However, I don't think this will give you the result you want. When you resize, the bottom panel will remain the same height, while the upper panel will stretch to fill the form.
Using your docking settings, with this code might do the trick:
protected override void OnSizeChanged(EventArgs e)
{
base.OnSizeChanged(e);
this.bottomPanel.Height = Convert.ToInt32((double)this.Height / 3.0);
}
Set both panels to "not anchored". That is: Remove Dock-Value and clear the Anchor property. Then, move the controls so they are sized the way you'd like them to be sized.
After that, upon resizing the form, they should resize relatively.
EDIT
Oops, just tried it and sure it doesn't work. I mixed this up with a solution that automatically keeps controls centered within the window...
Well, I'd guess you then have to create a handler for the form's Resize event and manually align the controls after the form has been resized.
Go to Tools, Other Windows, Document Outline. Find the two panels, and swap the order of them. The control that has DockStyle.Fill has to come first for it to be docked correctly. (or last.. never sure which one it is, but it is one of them :p)
This won't solve the always 1/3 and 2/3 issue though... cause the bottom panel will have a fixed height (unless I am mistaken). I think maybe the TableLayoutPanel supports this though...
Update: As noted in the comments, that panel doesn't exist in the compact framework. So, I suppose the easiest solution to this problem would then try to use the docking, but update the height of the bottom panel whenever the size of the form changes.
If you want this to work perfectly you'll need to add some code to the Resize event of the Form which then specifically works out the relative sizes and places the controls in the correct place after a resize.
If you're not worried about losing precision and the forms aren't going to move much you can avoid this by using some relatively smart anchoring. Essentially you're going to have to select a "grower" (the part of the form that gets bigger, the bigger the form gets). In this scenario I would probably anchor the top part to Top | Left | Right and the bottom part to Top | Left | Right | Bottom. This would mean that the lower part of the form will get bigger if the form is expanded. In most cases this is acceptable. If it isn't use the Resize event and some code.
The easiest way to do this is to nest panels. Just set up panels for top bottom and fill. Then use panels within those panels to do the same. The only issues I've had therein are datagrid resizing, which is always a pain anyway. in that case, you have to use some code to resize the datagrid control on the form resize event.
I would like to add a point to #jasonh answer.
For the panel that occupies 2/3 of the form, you will have to set the AutoScroll property of the panel to true.
This will enable the panel to display scroll when the control size exceed the visibility to the user and also ensure the visibility of the smaller panel which is 1/3 of the forms height.
You can get the required design by using nested panels along with few setting with Anchoring and Docking Properties.Follow the following steps:
1) Add the Form and put a Panel1 on it. Set its Dock Property as 'Fill' and ResizeMode as 'Grow&Shrink'.
2) Add Second panel2 and set its Dock Property to 'Bottom', Set the Height and set the Anchor property to 'Top,Left'.
3)Add Third panel and set its Dock Property to 'None', Set the Height and set the Anchor property to 'Top,Bottom,Left,Right'.
Save and Compile. Now all the panels Would maintain their relative Positioning With resizing.

Categories

Resources