Click here to Skip to main content
15,064,665 members
Please Sign up or sign in to vote.
1.44/5 (2 votes)
See more:
I'm "trying" to create a TableLayoutPanel that the user can resize at runtime like the behavior of the SplitContainer. This is a WinForm project...I've found some code that partially does this but it's incomplete. Can someone please help me out here?

Thanks in advance,
-DA

This is the code I have so far that comes from a thread I found here on CodeProject. The only thing different that I've done in my own is create a customTableLayoutPanel that inherits from TableLayoutPanel. Here is the link TableLayout Panel resize[^]
public partial class Form1 : Form
{
    bool resizing = false;
    TableLayoutRowStyleCollection rowStyles;
    TableLayoutColumnStyleCollection columnStyles;
 
    public Form1()
    {
        InitializeComponent();
    }
 
    private void Form1_Load(object sender, EventArgs e)
    {
        rowStyles = tableLayoutPanel1.RowStyles;
        columnStyles = tableLayoutPanel1.ColumnStyles;
    }
 
    private void tableLayoutPanel1_MouseDown(object sender, MouseEventArgs e)
    {
        if (e.Button == System.Windows.Forms.MouseButtons.Left)
        {
            resizing = true;
        }
    }
 
    private void tableLayoutPanel1_MouseMove(object sender, MouseEventArgs e)
    {
        if (resizing)
        {
            columnStyles[0].SizeType = SizeType.Absolute;
            rowStyles[0].SizeType = SizeType.Absolute;
            rowStyles[0].Height = e.Y;
            columnStyles[0].Width = e.X;
        }
    }
 
    private void tableLayoutPanel1_MouseUp(object sender, MouseEventArgs e)
    {
        if (e.Button == System.Windows.Forms.MouseButtons.Left)
        {
            resizing = false;
        }
    }
}
Posted
Updated 18-Jun-13 13:48pm
v3
Comments
CHill60 18-Jun-13 19:29pm
   
It would help if you either gave the code or where you got it from. "incomplete" does not constitute a question so it is very difficult for us to "try" to help you
d.allen101 18-Jun-13 19:48pm
   
Good point! Sorry about that.
koleraba 19-Jun-13 21:39pm
   
Can you be more specific than code is incomplete. What is missing?
d.allen101 20-Jun-13 7:26am
   
it doesn't work lol. if i have multiple rows and columns i can't figure how to identify which columnStyles item to resize or identify which cellBorder (horizontal or veritcal) is being moved to assign the correct cursor (HSplit or VSlpit), etc...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900