Hello, I had posted this to the C# group but then realised here might be
more relevant.

This seems like it should be simple - on the double-click event of a
tablelayoutpanel, I want to know which cell was double clicked in. I can't
see any of the properties that look relevant to this, could someone give me
a pointer where to look? I can see various properties to give me the cell of
a certain control and so on, but some cells might not have a control in yet
(by double clicking the user will instigate the creation of a control in
that cell - or at least that's the plan!)
Thanks!
James

Re: TableLayoutPanel - get cell clicked by AHadiA

AHadiA
Fri Feb 24 14:45:17 CST 2006

Hi James,
You can use MouseDoubleClick and GetWidths & GetHeights methods :


private void tableLayoutPanel1_MouseDoubleClick(object sender,
MouseEventArgs e)
{
int[] widths=tableLayoutPanel1.GetColumnWidths();
int[] heights = tableLayoutPanel1.GetRowHeights();

int col = -1;
int left = e.X;
for(int i=0;i<widths.Length;i++)
{
if (left < widths[i])
{
col = i;

break;
}
else
left -= widths[i];
}

int row = -1;
int top = e.Y;
for (int i = 0; i < heights.Length; i++)
{
if (top < heights[i])
{
row = i;
break;
}
else
top -= heights[i];
}

MessageBox.Show(string.Format( "Col {0},Row {1}",col,row));
}

Best Regards,
A.Hadi


Re: TableLayoutPanel - get cell clicked by JamesB

JamesB
Sat Feb 25 03:35:33 CST 2006


<AHadiA@gmail.com> wrote in message
news:1140813917.800296.229820@v46g2000cwv.googlegroups.com...
> Hi James,
> You can use MouseDoubleClick and GetWidths & GetHeights methods :
>
>
> private void tableLayoutPanel1_MouseDoubleClick(object sender,
> MouseEventArgs e)
> {
> int[] widths=tableLayoutPanel1.GetColumnWidths();
> int[] heights = tableLayoutPanel1.GetRowHeights();
>
> int col = -1;
> int left = e.X;
> for(int i=0;i<widths.Length;i++)
> {
> if (left < widths[i])
> {
> col = i;
>
> break;
> }
> else
> left -= widths[i];
> }
>
> int row = -1;
> int top = e.Y;
> for (int i = 0; i < heights.Length; i++)
> {
> if (top < heights[i])
> {
> row = i;
> break;
> }
> else
> top -= heights[i];
> }
>
> MessageBox.Show(string.Format( "Col {0},Row {1}",col,row));
> }
>
> Best Regards,
> A.Hadi
>

Many thanks for that, will take a look at it later on today!
James