I have a form with status strip. Form has auto-scroll on. When required, scrollbars appear and user can scroll.
However when the content is bigger than form size and user has to scroll down to see other parts of the content, he/she has to scroll all the way down also to see the status strip.
I want to keep the status strip on the bottom of the form whatever the size and scroll position is. How do I do that?
Why can I not put everything on a panel and set panel.AutoScroll = true?
Because I draw everything on this panel (with GDI+), then resize it, then form displays scrollbars. Now if I set autoscroll on in the panel no scroll bars are shown because there are no controls on panel, only GDI+ drawings.
Put everything that needs scrolling inside a panel and set auto-scroll on the panel. Your status strip should go outside the panel.
If you are doing extensive drawing with GDI+, there are two good options that I can think of to replace your design.
If the user must interact with your graphics, consider creating a custom control to encapsulate the functionality and graphics.
If it is nothing but a display of some data, you can draw your graphics to a Bitmap and view it in a PictureBox.
I don't know what you are trying to accomplish, so I can't say what is the correct solution.
It sounds like you are doing things backwards. The "Form" shouldn't be showing the scrollbars, the panel should be.
If the "content" of your panel is larger than your panel, and you are doing all of this drawing inside the panel, then you need to set the panel's AutoScrollMinSize to the size of your content, not keep enlarging the size of the panel.
Set the size of your panel's content (example):
panel1.AutoScrollMinSize = new Size(500, 500);
Then in your panel's paint event, apply the transformation:
private void panel1_Paint(object sender, PaintEventArgs e) {
e.Graphics.TranslateTransform(panel1.AutoScrollPosition.X, panel1.AutoScrollPosition.Y);
// do your normal painting here
}
Use a Double-Buffered panel to avoid flicker.
Your StatusStrip should just be docked to the bottom of the form, not interfering with the panel.
Related
I have a navigation panel on the left hand side of my program and I'd like it to always stay where it is when scrolling the window content. Is there a way to do that?
I've thought about trying to do a get/set for its position but there's only a size property.
In the example above, the information in the top left is in a panel. Is there a way to keep it anchored there as the user scrolls down?
You currently appear to have the Autoscroll option enabled on the Form. Set that to false, then set up two panels, one for the toolbar/navigation and the other for the scrollable content.
Set the toolbar panel to be anchored to Top, Bottom, Left. Set the content panel to be anchored to all four sides. Set both panels to Autoscroll=True, then put the content in each panel. When each panel gets too small to contain their contents they will scroll - independently - which will in most cases mean that the toolbar/navigation will stay put while the content will be scrollable. If the toolbar panel also gets too small then it will be scrollable too:
I have a panel and I need to draw a horizontal chart on it. But sometimes the chart can be too long for the panel, even the form has maximum size. So I want to make a horizontal bar on panel to enable the user to see the remaining part of the drawing that is out of the bounds.
Chart is something like this:
As you can see, the chart is out of the panel's bounds and form's too. I don't have any idea how can it be done, so I have no code to show. So how can I do it using a basic method?
Yes, the solution is pretty basic, as long as the size you want to draw won't go over 32k pixels width:
Put your Panel inside another one.
The outer Panel has AutoScroll=true
The inner one where you draw has the size of your drawing.
You need to draw in the Paint event, as you should anyway (!)
Now the outer Panel shows a horizontal scrollbar and the user can scroll right and left and see all parts of the drawing..
One alternative would be to add a dummy control that enforces the AutoScroll of your drawing Panel to work, but I find using two Panels the cleaner way to go..
Note: You should either use a PictureBox or at least a double-buffered Panel subclass to avoid flicker and tearing:
class DrawPanel : Panel
{
public DrawPanel()
{ DoubleBuffered = true; }
}
Update: Instead of a Panel, which is a Container control and not really meant to draw onto you can use a Picturebox or a Label (with Autosize=false); both have the DoubleBuffered property turned on out of the box and support drawing better than Panels do.
I have 2 items FlowLayoutPanel each includes some buttons and has autosize property. Then I have a simple Panel docked to left. My FlowLayotPanels docked inside that panel one to top, second to bottom. I dont want to set static width to docked to left panel, but if I set autosize to that panel, it shrinks to zero. Somehow it doesnt "see" sizes of autosized FlowLayoutPanenls inside of it.
How to force Panel to see size of FlowLayoutPanel inside?
Assuming that your inner panels do have content, or at least a fixed minimal size, the only thing i can imagine without some code is that you did not set the hierarch properly... You can do that by MyParentPanel.Controls.Add(MyChildPanel1);
I am attempting to add three panels to a window using a Devexpress Docking manager and dockable panels. Here are the current results:
The three panels are placed and sized how I would like them however their contents will not correctly resize as I resize the window. This first image indicates this by the Picturebox that fails to fill the window. My current attempt to regulate this is: (Panel3 refers to a panel that contains pictureBox1. which in turn is contained by dp3.)
void dp3_SizeChanged(object sender, EventArgs e)
{
panel3.Size = panel3.Parent.Size;
pictureBox1.Width = dp3.Width;
pictureBox1.Height = dp3.Height;
}
The Same is true for the Controls Window. I have controls that do not appear unless the window is grossly oversized.
The controls are contained in 4 seperate panels that are themselves contained in the dockable window.
How do I make things appear the correct size and location whendocking and resizing?
Go throught this DevX article - Designing Resizable Windows Forms in
Visual Studio .NET-2,
that i like most for understanding about layout in Winforms.
You should set the Anchor and Dock properties on the controls in the forms.
The Anchor property controls which edges of a control are "bound" or "tied" to the corresponding edges of its form.
For example, if you set Anchor to Bottom, the distance between the control's bottom edge and the bottom of its parent will not change, so the control will move down as you resize the form.
If you set Anchor to Top | Bottom, the control will resize vertically as you resize the form.
To make a control resize with the form, set the Anchor to all four sides, or set Dock to Fill.
You can set the control's Dock property to Fill. This will cause the control to fill it's parent container.
You may still need to write some code to handle laying out the child controls. You can either do this by handling the Resize event, or by using a container that supports resizing for you (such as FlowLayoutPanel or TableLayoutPanel).
Use your Control's Anchor property. You'll probably need to set it to all sides, Top, Bottom, Left, Right, if you want it to resize according to parent control in all four directions
If you want to Maintain the controls Aspect Ratio on Resize, You'll need to store off the aspect ratio somehow, whether it's something known to you at design time or if you just want to calculate it in the constructor of the form after InitializeComponent(). In your form's Resize event,
I'm new to Windows Forms in Visual Studio, and I am wondering how to automaticly resize controls to the window size.
Say, I have 2 controls in a panel, a List Box and a Button. I want the button to dock to the bottom, and I want the List Box to fit the rest of the space. when the window resizes, the button should be at the bottom (as expected with docking), and the list box should stretch down to the button.
Is there a way to do this without any code?
Thanks.
Dock is pretty easy to use, but I recommend using the Anchor properties instead. Resize your form to a reasonable size in the Designer. Then, place your controls to look the way you want. Then, decide which controls should resize with the form and set the Anchor property as follows:
If you want the control to resize with the form in width, set the Right anchor.
If you want to resize height, set the Bottom anchor.
If you want the control to stay right when the form resizes, unset the Left anchor.
If you want the control to stay bottom when the form resizes, unset the Top anchor.
The problem I have with Docks is that they sometimes act funny when controls are not declared in a specific order, and to get the effect you want, sometimes you have to create extraneous panels just to hold controls.
It really gets messy when you want to maintain the aspect ratio of each control. One way, which is not really up to the mark if you want to get into fixing the details, is to use TableLayoutPanel and use Dock and Anchor wisely to achieve what you want.
Use the dock and fill options on the controls. Look under properties for each object, and containers if they are in any.
You can use SplitContainer
Google for examples. Here is one
Try setting your ListBox's Dock property to Fill.
You'll need to watch for one thing though: by default the ListBox will size itself to display whole list items. If you resize the control so that it displays a partial item it will adjust itself so it will display a complete item. This can make the control appear to lose its 'Dock'ing behavior. The solution for this is to set the ListBox's IntegralHeight property to false, which specifies that the control not resize itself to fit complete items.