1

I have a splitContainer. I want to resize the form inside the splitContaner's panel to scale with when I move the splitter as below. But my form doesn't get redrawn. Any suggestion, thank so much!

    private void splitContainer1_SplitterMoved(System.Object sender, System.Windows.Forms.SplitterEventArgs e)
    {
        // Define what happens when the splitter is no longer moving.
        Cursor.Current = System.Windows.Forms.Cursors.Default;
        statictisTableDisplayForm1.ClientSize = new Size(statictisTableDisplayForm1.Width, splitContainer1.SplitterDistance);
        statictisTableDisplayForm1.Invalidate();
        statictisTableDisplayForm1.Refresh();
        Refresh();
    }
Sergey Berezovskiy
  • 232,247
  • 41
  • 429
  • 459
LN22
  • 133
  • 10
  • You are saying that you want to resize control inside split container, but your code sets size of some form. Can you please describe in details what controls do you have, how these controls are located and what you want to happen after splitter is moved – Sergey Berezovskiy May 29 '17 at 15:34
  • Oh, sorry! my control inside a splitContainer panel 1 is a form. I want when moved up the splitter the form will be resize smaller instead of trunked by the splitter – LN22 May 29 '17 at 15:40
  • Why put a Form there and not a Panel??? And how? Here this results in an error. 'Top-level controls cannot be added here'. For a Panel or a UserControl etc you would set Dock=Fill, btw.. – TaW May 29 '17 at 15:45
  • Just set your Form to Maximized and it will resize with its container... – Idle_Mind May 29 '17 at 16:07

1 Answers1

1
  1. Form supposed to be a top-level control which represents a window of your application. You should not embed forms as controls into other forms (well, unless there is no other option).
  2. Usually, you should not resize and/or move controls manually. There are several layout options which allow automatic resizing of controls when the size of their container changes: Anchor, Dock.

So better create a UserControl which will contain controls and logic of your StatictisTableDisplayForm and place it to SplitContainer panel with Dock set to Fill. That will automatically resize user control when you move the splitter.

Note: if you have to use StatictisTableDisplayForm on it's own too, then just place same user control to this form.

Sergey Berezovskiy
  • 232,247
  • 41
  • 429
  • 459