4

I have a winform in .net and I place too many controls and set the height and width of form. But when I compile the form and decrease the size of form my controls are not visible. When I increase the size of form the controls are visible at their own places.

I want a scroll bar to appear when I decrease the size of form and the scroll bar to disappear when we increase the form size.

Spectre87
  • 2,374
  • 1
  • 24
  • 37
user1448783
  • 263
  • 3
  • 5
  • 9
  • 3
    Please, please, please, use shorter sentences. It's really difficult to understand your question... – Treb Sep 07 '12 at 07:17

6 Answers6

6

You need to use the Panel control as container of your child controls and set "AutoScroll" property to true.

Sethu
  • 236
  • 2
  • 5
5

Set true to AutoScroll property of Form.

KV Prajapati
  • 93,659
  • 19
  • 148
  • 186
1

Write this code in your Form LOAD EVENT, and you will get your scroll bar, like i am writting it here in my Form Load Event.

private void Form1_Load(object sender, EventArgs e)
{    
    Panel my_panel = new Panel();
    VScrollBar vScroller = new VScrollBar();
    vScroller.Dock = DockStyle.Right;
    vScroller.Width = 30;
    vScroller.Height = 200;
    vScroller.Name = "VScrollBar1";
    my_panel.Controls.Add(vScroller);
}
Kaz
  • 1,047
  • 8
  • 18
Pir Fahim Shah
  • 10,505
  • 1
  • 82
  • 81
0

You can use Panel, TabControl or SplitContainer control as container and place all of you contros into it. Set the AutoScroll property of Panel control to true for getting scroll bar on the form. Dock the Panel control to Fill so that it appear on entire form.

Thanks.

Nitesh Kumar
  • 1,774
  • 4
  • 19
  • 26
0

Add all control of your windows form in a panel, write the following code in your window form Load event and set the auto scroll property of your window form to true.

private void Form1_Load(object sender, EventArgs e)
{
    Panel my_panel = new Panel();
    VScrollBar vScroller = new VScrollBar();
    vScroller.Dock = DockStyle.Right;
    vScroller.Width = 30;
    vScroller.Height = 200;
    vScroller.Name = "VScrollBar1";
    my_panel.Controls.Add(vScroller);
}
Kaz
  • 1,047
  • 8
  • 18
0

There is one thing which have to be remember is that,

Set true to AutoScroll property of Form.

is run, when forms have controls till end of height, If end of forms doesn't contain any control and there is only space on it, then this AutoScroll Property doesn't work.

Faraz Ahmed
  • 1,467
  • 2
  • 18
  • 33