9

I find the table layout panel in c# (.net 2.0) to be very primitive. I wanted to allow my users to resize the columns in a table layout panel but there are no ready made options to do so. Is there a way atleast to find out whether the cursor is directly over any borders of a cell and if so, which cell is beneath it ?? May be having this information, we can atleast try resizing that row/column thru' code. Help me finding,

  • whether the cursor is directly over any borders of a cell
  • which cell is beneath it (applicable only if the first question has an answer)

Many Thanks,

Sudarsan Srinivasan

sudarsanyes
  • 3,156
  • 8
  • 42
  • 52
  • hey sudarsanyes did you ever solve this issue? I'm now facing the same problem. the user of my app needs to be able resize rows and columns in my app's tableLayoutPanel during runtime – Max Eisenhardt Jul 02 '13 at 20:36

3 Answers3

12

If your layout is not overly complex, maybe you can achieve what you want by using SplitContainer controls? Unfortunately, each SplitContainer will have only two "cells", but you can embed a SplitContainer in another SplitContiner panel to get more resizable cells:

┌──────────────────┐
│┌─────┬──────────┐│
││     │          ││
││     │          ││
│└─────┴──────────┘│
├──────────────────┤
│┌──────────┬─────┐│
││          │     ││
││          │     ││
│└──────────┴─────┘│
└──────────────────┘

OK, so ASCII art was never one of my stronger skills, but I think you get the point ;o)

Jazimov
  • 12,626
  • 9
  • 52
  • 59
Fredrik Mörk
  • 155,851
  • 29
  • 291
  • 343
  • Won't that be very complex and costly?? [you are really good in ASCII arts than me:D] – sudarsanyes Jun 11 '09 at 11:14
  • Ugly, yes, but considerably less complex and costly that trying to handle events in a table layout panel, I'd say. – Benjol Jun 11 '09 at 11:25
  • This is the workaround I use, but I don't think there is a (simple) way to enforce keeping the tabular view, because the moment the user resizes an inner split container, it is out of sync with the other split containers in your table. Perhaps with coding event handlers. – tsemer Nov 23 '17 at 12:26
1

Building on top of @Fredrik Mörk's solution:

After embedding another SplitContainer(s), the only drawback is that they don't automatically resize together, so you quickly lose the tabular view. A solution could be to set up a SplitterMoved event handler for every applicable SplitContainer:

private void mySplitContainer_SplitterMoved(object sender, SplitterEventArgs e) {
  mOtherySplitContainer.SplitterDistance = e.SplitX;
}

If your SplitContainer is horizontal use e.SplitX, if it's vertical use e.SplitY.

tsemer
  • 2,959
  • 3
  • 29
  • 26
0

One can achieve this (at least .Net above 4.x) using the splitter control. For example use a panel, drop a button, set it to dock left. Drop a splitter, drop another button set it to dock fill. Then the size of these buttons within the control can be set by the user at runtime.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 17 '23 at 20:54