Windows Develop Bookmark and Share   
 index > Windows Forms Sample Applications > Problem with SplitContainer control
 

Problem with SplitContainer control

Hello,

I have developed one user control using SplitContainer.
It is simply like two textboxes connected to each other with splitter in between them.

Whenever I increase width of the control
1. By dragging it with right edge, I want the splitter and the left textbox to remain fixed and
2. By dragging it with left edge, I want the splitter and the right textbox to remain fixed.

We can set only one of the panels as FixedPanel.

Initially i set splitContainer.FixedPanel = FixedPanel.None;

then at runtime in event handlers for

1. panel1 : in splitContainer_Panel1_Resize
{
splitContainer.FixedPanel = FixedPanel.Panel2;
}
2. panel2 : splitContainer_Panel2_Resize
{
splitContainer.FixedPanel = FixedPanel.Panel1;
}

but whether I resize from right edge or left edge the event handler for Panel1 is always getting called first and then for second. And these both event handlers get called multiple times so this is not working.

How can this problem be solved?????

Regards
Abhishek
Kulabhishek  Friday, February 20, 2009 9:29 AM
Hi Kulabhishek,

I can reproduce the problems. However, the result of mine is a bit different for you. I don't know if the sequence of the Panels is the same with you. In my splitContainer control, panel1 is in the left, and panel2 is in the right. The test result is the resize event of the panel2 is always getting called first.

Try to control the fired sequence of these two events is really hard. Additionally, these two events may get fired many times during the resizing period. So I think a better way to get around this is handling the resize event of the Form instead.

Please try the following code, it works well on my side.

publicpartialclassForm1:Form
{
PointoldFormLocation;
Directiondir;
enumDirection
{
Left,
Right
}
publicForm1()
{
InitializeComponent();
this.splitContainer1.IsSplitterFixed=true;
oldFormLocation=this.Location;
this.Resize+=newEventHandler(Form1_Resize);
}
voidForm1_Resize(objectsender,EventArgse)
{
if(this.Location.X!=oldFormLocation.X)
{
dir=Direction.Left;
}
else
{
dir=Direction.Right;
}
if(dir==Direction.Left)
{
this.splitContainer1.FixedPanel=FixedPanel.Panel2;
}
if(dir==Direction.Right)
{
this.splitContainer1.FixedPanel=FixedPanel.Panel1;
}
this.oldFormLocation=this.Location;
}
}

Note that panel1 is in the left, and panel2 is in the right.

If you have any problem, please feel free to let me know.

Best regards,
Bruce Zhou

Please mark the replies as answers if they help and unmark if they don't.
Bruce.Zhou  Monday, February 23, 2009 9:09 AM
Hi Kulabhishek,

I can reproduce the problems. However, the result of mine is a bit different for you. I don't know if the sequence of the Panels is the same with you. In my splitContainer control, panel1 is in the left, and panel2 is in the right. The test result is the resize event of the panel2 is always getting called first.

Try to control the fired sequence of these two events is really hard. Additionally, these two events may get fired many times during the resizing period. So I think a better way to get around this is handling the resize event of the Form instead.

Please try the following code, it works well on my side.

publicpartialclassForm1:Form
{
PointoldFormLocation;
Directiondir;
enumDirection
{
Left,
Right
}
publicForm1()
{
InitializeComponent();
this.splitContainer1.IsSplitterFixed=true;
oldFormLocation=this.Location;
this.Resize+=newEventHandler(Form1_Resize);
}
voidForm1_Resize(objectsender,EventArgse)
{
if(this.Location.X!=oldFormLocation.X)
{
dir=Direction.Left;
}
else
{
dir=Direction.Right;
}
if(dir==Direction.Left)
{
this.splitContainer1.FixedPanel=FixedPanel.Panel2;
}
if(dir==Direction.Right)
{
this.splitContainer1.FixedPanel=FixedPanel.Panel1;
}
this.oldFormLocation=this.Location;
}
}

Note that panel1 is in the left, and panel2 is in the right.

If you have any problem, please feel free to let me know.

Best regards,
Bruce Zhou

Please mark the replies as answers if they help and unmark if they don't.
Bruce.Zhou  Monday, February 23, 2009 9:09 AM

You can use google to search for other answers

Custom Search

More Threads

• Questions about connecting to SQL Server & Web Services
• namespace could not be found
• Issue Vision served us well
• Terrarium Servers Back Up!
• Background gradient
• Sync Lookup Tables in IssueVision
• Altering Task Vision Source
• Cannot find "file:///D://.....". Make sure the path or the internet address is correct.
• Error on compiling and running taskvision
• Datagrid Columns