How do I dynamically resize portion of form with WinForms splitter control on it.

J

JDeats

I have a simple WinForm with a WinForms splitter down the middle. I
would like to make it so when the user clicks on a button inside the
left portion of the screen (the panel to the splitters left) that
portion of the form is reduced in size by about 90% (I want to shrink
this area of the of the form).

The splitter doesn't appear to have any methods for programmatic
resizing, I tried changing it's width settings and the splitter moved
without moving the controls inside it.
 
J

justin creasy

I have a simple WinForm with a WinForms splitter down the middle. I
would like to make it so when the user clicks on a button inside the
left portion of the screen (the panel to the splitters left) that
portion of the form is reduced in size by about 90% (I want to shrink
this area of the of the form).

The splitter doesn't appear to have any methods for programmatic
resizing, I tried changing it's width settings and the splitter moved
without moving the controls inside it.

To resize a Splitter you can use the Splitters "SplitPosition"
attribute. You can increase or decrease this value to move the
splitter different directions depending on how it is docked to your
form. If you want to reduce a panel that is controlled by a splitter
by 90% I would do the following.

splitter1.SplitPosition = (int)((double)splitter1.SplitPosition * .1);

and that will reduce it by 90% assuming this isn't less than the
MinSize of the splitter. Let me know if you have any problems using
this code.

~ Justin Creasy
www.immergetech.com
www.immergecomm.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top