c# - How to make TableLayoutPanel with resizable cells like using Splitter -


got tablelayoutpanel 1 column , n rows needed cells resizable somthing splitter component between cells. without using splitcontainer.

may other idea without tablelayoutpanel?

it depends on want it: datagridview brings interactivity, cells neither controls nor containers..

you can try if tablelayoutpanel subclass want:

public partial class splittablepanel : tablelayoutpanel {     public int splittersize { get; set; }      int sizingrow = -1;     int currentrow = -1;     point mdown = point.empty;     int oldheight = -1;     bool isnormal = false;     list<rectanglef> tlprows = new list<rectanglef>();     int[] rowheights = new int[0];      public splittablepanel()     {         initializecomponent();         this.mousedown += splittablepanel_mousedown;         this.mousemove += splittablepanel_mousemove;         this.mouseup += splittablepanel_mouseup;         this.mouseleave += splittablepanel_mouseleave;         splittersize = 6;     }      void splittablepanel_mouseleave(object sender, eventargs e)     {         cursor = cursors.default;     }       void splittablepanel_mouseup(object sender, mouseeventargs e)     {         getrowrectangles(splittersize);     }      void splittablepanel_mousemove(object sender, mouseeventargs e)     {         if (!isnormal) nomalizerowstyles();         if (tlprows.count <= 0) getrowrectangles(splittersize);         if (rowheights.length <= 0) rowheights = getrowheights();          if (e.button == system.windows.forms.mousebuttons.left)         {             if (sizingrow < 0) return;             int newheight = oldheight + e.y - mdown.y;             sizerow(sizingrow, newheight);         }         else         {             currentrow = -1;             (int = 0; < tlprows.count; i++)                 if (tlprows[i].contains(e.location)) { currentrow = i; break;}             cursor = currentrow >= 0 ? cursors.sizens : cursors.default;         }     }      void splittablepanel_mousedown(object sender, mouseeventargs e)     {         mdown = point.empty;         sizingrow = -1;         if (currentrow < 0) return;         sizingrow = currentrow;         oldheight = rowheights[sizingrow];         mdown = e.location;     }       void getrowrectangles(float size)     {   // list of mouse sensitive rectangles         float sz = size / 2f;         float y = 0f;         int w = clientsize.width;         int[] rw = getrowheights();          tlprows.clear();         (int = 0; < rw.length - 1; i++)         {             y += rw[i];             tlprows.add(new rectanglef(0, y - sz, w, size));         }      }      void sizerow(int row, int newheight)     {   // change height of 1 row         if (newheight == 0) return;         if (sizingrow < 0) return;         suspendlayout();         rowheights = getrowheights();         if (sizingrow >= rowheights.length) return;          if (newheight > 0)              rowstyles[sizingrow] = new rowstyle(sizetype.absolute, newheight);         resumelayout();         rowheights = getrowheights();         getrowrectangles(splittersize);     }      void nomalizerowstyles()     {   // set rows absolute , last 1 percent=100!         if (rowheights.length <= 0) return;         rowheights = getrowheights();         rowstyles.clear();         (int = 0; < rowcount - 1; i++)         {             rowstyle cs = new rowstyle(sizetype.absolute, rowheights[i]);             rowstyles.add(cs);         }         rowstyles.add ( new rowstyle(sizetype.percent, 100) );         isnormal = true;     } } } 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -