{"id":298414,"date":"2020-02-09T09:00:11","date_gmt":"2020-02-09T09:00:11","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=298414"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2020-02-09T09:00:11","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=298414","title":{"rendered":"\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u043d\u0430 C# \u0434\u043b\u044f Windows Form"},"content":{"rendered":"\n<div class=\"post__text post__text-html\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/487616\/\">\u0414\u043e\u0431\u0440\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0441\u0443\u0442\u043e\u043a! <\/p>\n<p>  \u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043e\u043f\u0438\u0448\u0443 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u0432\u043e\u0438\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0434\u043b\u044f C# Windows Form.<\/p>\n<p>  \u0414\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0431\u0443\u0434\u0443 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0441\u043e \u0432\u0441\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u043e\u043c DataGridView. \u041f\u043e\u0437\u0436\u0435 \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043d\u0430 \u0441\u0432\u043e\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b. \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0440\u0430\u0437\u043e\u0431\u044c\u0435\u043c \u043d\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0443\u0440\u043e\u043a\u043e\u0432. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0443\u0440\u043e\u043a\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043c \u043e\u0442 \u0440\u0438\u0441\u043e\u0432\u043a\u0443 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u0430 \u0442\u0430\u043a\u0436\u0435: \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432, \u0441\u0442\u0440\u043e\u043a, \u044f\u0447\u0435\u0435\u043a.<\/p>\n<p>  \u0414\u043b\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c .Net FrameWork 4.7.x, \u0441\u0440\u0435\u0434\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 Visual Studio 2019.<\/p>\n<p>  \u0412 \u043f\u0435\u0440\u0432\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 Windows Form. \u0414\u0443\u043c\u0430\u044e \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u044d\u0442\u043e \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c. \u0410 \u0443\u0436\u0435 \u043f\u043e\u0442\u043e\u043c \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442 \u00ab\u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f Windows Form\u00bb(\u041d\u0430\u0437\u043e\u0432\u0435\u043c \u0435\u0433\u043e CustomControl).<\/p>\n<p>  \u0414\u0430\u043b\u0435\u0435 \u0443 \u043d\u0430\u0441 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u043d \u0444\u0430\u0439\u043b UserControl.cs. \u0423\u0434\u0430\u043b\u044f\u0435\u043c \u0435\u0433\u043e \u0438 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 TableCustoms.cs.\u041d\u0430\u0448 \u043a\u043b\u0430\u0441\u0441 \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043e\u0442 \u043a\u043b\u0430\u0441\u0441\u0430 Control.<br \/>  <a name=\"habracut\"><\/a><br \/>   \u0414\u0430\u043b\u0435\u0435 \u0432 \u044d\u0442\u043e\u043c \u0436\u0435 \u0444\u0430\u0439\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0435\u0449\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043a\u043b\u0430\u0441\u0441\u043e\u0432, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e:Column,Row,Cell. \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u0430\u0436\u0434\u044b\u0439 \u043f\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438. \u041d\u0430\u0447\u043d\u0435\u043c \u0441 Column:<\/p>\n<pre><code class=\"cs\">    [Serializable]     public class Column     {         public string Name { get; set; } = &quot;NameColumn&quot;;\/\/\u041d\u0430\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u0435 \u0421\u0442\u043e\u043b\u0431\u0446\u0430          public string Caption { get; set; } = &quot;CaptionColumn&quot;;\/\/\u0422\u0435\u043a\u0441\u0442 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430         public int Width { get; set; } = 100;\/\/\u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0430\u044f \u0448\u0438\u0440\u0438\u043d\u0430         public Color Back { get; set; } = Color.White;\/\/\u0426\u0432\u0435\u0442 \u0444\u043e\u043d\u0430                  public Column()         {                   }     } <\/code><\/pre>\n<p>  \u041a\u043b\u0430\u0441\u0441 Row:<\/p>\n<pre><code class=\"cs\">    [Serializable]     public class Row     {         public int Heigth { get; set; } = 20;\/\/ \u0412\u044b\u0441\u043e\u0442\u0430 \u0441\u0442\u0440\u043e\u043a\u0438         public List&lt;Cell&gt; Cells { get; set; } = new List&lt;Cell&gt;();\/\/\u0441\u043f\u0438\u0441\u043e\u043a \u044f\u0447\u0435\u0435\u043a         public Row()         {           }         public Row(List&lt;Cell&gt; cells)         {             Cells = cells;         }      } <\/code><\/pre>\n<p>   \u041a\u043b\u0430\u0441\u0441 Cell(\u0414\u043b\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 ICloneable):<\/p>\n<pre><code class=\"cs\">    [Serializable]     public class Cell : ICloneable     {         public object Value { get; set; } = null;\/\/\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u044f\u0447\u0435\u0439\u043a\u0438          public Cell()         {         }         public object Clone()         {             return MemberwiseClone();         }     } <\/code><\/pre>\n<p>   \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u043c \u043d\u0430\u0448 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043a\u043b\u0430\u0441\u0441 TableCustoms:<\/p>\n<pre><code class=\"cs\">   public class TableCustoms : Control     {         #region \u041f\u0435\u0440\u0435\u043c\u0435\u043d\u0435\u043d\u043d\u044b\u0435         public ObservableCollection&lt;Column&gt; Columns { get; set; } = new ObservableCollection&lt;Column&gt;();\/\/\u0421\u043f\u0438\u0441\u043e\u043a \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u044b         private ObservableCollection&lt;Row&gt; rows = new ObservableCollection&lt;Row&gt;();\/\/\u0421\u043f\u0438\u0441\u043e\u043a \u0441\u0442\u0440\u043e\u043a         private int countRow = 0;\/\/\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0442\u0440\u043e\u043a         #endregion         #region \u0421\u0432\u043e\u0439\u0441\u0442\u0432\u0430         public int CountRow \/\/ \u0433\u0435\u0442\u0435\u0440 \u0438 \u0441\u0435\u0442\u0435\u0440 \u043f\u0440\u0438 \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u043d\u0430 N \u0440\u0430\u0437         {             get { return countRow; }             set             {                 \/\/\u041f\u0440\u0438 \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c                  if (value &gt; countRow)                 {                     int iteration = value - countRow;                     for (int i = 0; i &lt; iteration; i++)                     {                         rows.Add(new Row());                     }                 }                 \/\/\u043f\u0440\u0438 \u0443\u043c\u0435\u043d\u044c\u0448\u0435\u043d\u0438\u0438 \u0443\u0434\u0430\u043b\u044f\u0435\u043c \u0441 \u043a\u043e\u043d\u0446\u0430                 if (value &lt; countRow)                 {                     int iteration = countRow - value;                     for (int i = 0; i &lt; iteration; i++)                     {                         rows.Remove(rows[rows.Count - 1]);                     }                 }                  countRow = value;             }         }         \/\/\u0433\u0435\u0442\u0435\u0440 \u0438 \u0441\u0435\u0442\u0435\u0440 \u0434\u043b\u044f \u0441\u043f\u0438\u0441\u043a\u0430 \u0441\u0442\u0440\u043e\u043a, \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u043e\u0437\u0436\u0435         public ObservableCollection&lt;Row&gt; Rows         {             get { return rows; }             set { }         }          public int ColumnHeaderHeigth { get; set; } = 20;\/\/\u0432\u044b\u0441\u043e\u0442\u0430 \u0448\u0430\u043f\u043a\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u044b         public int RowHeaderWidth { get; set; } = 20;\/\/\u0432\u044b\u0441\u043e\u0442\u0430 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u043e\u0432 \u0441\u0442\u0440\u043e\u043a         public Color ColumnHeaderBack { get; set; } = SystemColors.Control;\/\/\u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0446\u0432\u0435\u0442 \u0444\u043e\u043d\u0430 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u043e\u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u044b         public Color BorderColor { get; set; } = Color.Black;\/\/\u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u0446\u0432\u0435\u0442 \u0433\u0440\u0430\u043d\u0438\u0446 \u0442\u0430\u0431\u043b\u0438\u0446\u044b         public bool NumerableRows { get; set; } = false;\/\/\u0424\u043b\u0430\u0433 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043d\u0443\u043c\u0435\u0440\u0430\u0446\u0438\u0438         #endregion         \/\/\u041c\u0435\u0442\u043e\u0434\u0430 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432, \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0443\u0440\u043e\u043a\u0435         private void EditColumn()         {          }         \/\/\u041c\u0435\u0442\u043e\u0434 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0441\u0442\u0440\u043e\u043a         private void EditRows()         {             if (countRow &lt; rows.Count)\/\/\u0423\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0441\u0442\u0440\u043e\u043a             {                 rows[rows.Count - 1].Cells = CreatCells(Columns.Count);\/\/\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u0443\u0441\u0442\u044b\u0445 \u044f\u0447\u0435\u0435\u043a \u0432 \u0441\u0442\u0440\u043e\u043a\u0443                 countRow++;             }             if (CountRow &gt; rows.Count)\/\/\u0443\u043c\u0435\u043d\u044c\u0448\u0435\u043d\u0438\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0441\u0442\u0440\u043e\u043a             {                 countRow--;             }          }         \/\/\u043c\u0435\u0442\u043e\u0434 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f N \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u044f\u0447\u0435\u0435\u043a         private List&lt;Cell&gt; CreatCells(int Count)         {             \/\/ return Enumerable.Repeat(new Cell(), Count).ToList();             List&lt;Cell&gt; result = new List&lt;Cell&gt;();             for (int i = 0; i &lt; Count; i++)             {                 result.Add(new Cell());             }             return result;         }         public TableCustoms()         {             rows.CollectionChanged += (e, v) =&gt; EditRows();\/\/\u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0441\u043f\u0438\u0441\u043a\u0430             Columns.CollectionChanged += (e, v) =&gt; EditColumn();\/\/\u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0441\u043f\u0438\u0441\u043a\u0430             BackColor = SystemColors.AppWorkspace;\/\/\u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u0444\u043e\u043d             PanelTable panelTable = new PanelTable(this);\/\/\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043f\u0430\u043d\u0435\u043b\u0438             panelTable.Dock = DockStyle.Fill;\/\/\u0420\u0430\u0441\u0442\u044f\u0433\u0438\u0432\u0430\u0435\u043c \u043e\u0441\u043d\u043e\u0432\u043d\u0443\u044e \u043f\u0430\u043d\u0435\u043b\u044c \u043f\u043e Control             Controls.Add(panelTable);\/\/\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043d\u0435\u043b\u0438 \u043d\u0430 Control         }     } <\/code><\/pre>\n<p>   \u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0443 \u043d\u0430\u0441 \u0431\u044b\u043b\u0438 \u043f\u043e\u043b\u043e\u0441\u044b \u043f\u0440\u043e\u043a\u0440\u0443\u0442\u043a\u0438 \u043d\u0443\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c ScrollableControl, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043b\u0430\u0441\u0441 PanelTable \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u043c ScrollableControl \u0438 \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u043c \u0435\u0433\u043e \u043d\u0430 Control(\u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0443\u0440\u043e\u043a\u0435 \u043e\u0431\u044a\u044f\u0441\u043d\u044e \u043f\u043e\u0447\u0435\u043c\u0443 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0434\u0432\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0430, \u0430 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0441\u0440\u0430\u0437\u0443 ScrollableControl):<\/p>\n<pre><code class=\"cs\"> internal class PanelTable : ScrollableControl\/\/Control \u0441\u043e ScrolLbar         {             private TableCustoms BParent;\/\/\u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430, \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u043c\u0438             public PanelTable(TableCustoms bParent)             {                 HScroll = true;\/\/\u041e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u0437\u0443\u043d\u043a\u0430 \u043f\u043e \u0433\u043e\u0440\u0438\u0437\u043e\u043d\u0442\u0430\u043b\u0438                 VScroll = true;\/\/\u041e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u0437\u0443\u043d\u043a\u0430 \u043f\u043e \u0432\u0435\u0440\u0442\u0438\u043a\u0430\u043b\u0438                 AutoScroll = true;\/\/\u0410\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u043e\u0441 \u043f\u0440\u043e\u043a\u0440\u0443\u0442\u043a\u0438                 BParent = bParent;             }             \/\/\u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u0430             protected override void OnPaint(PaintEventArgs e)             {                 Matrix m = new Matrix();                 m.Translate(this.AutoScrollPosition.X, this.AutoScrollPosition.Y, MatrixOrder.Append);                 e.Graphics.Transform = m;                 Graphics graf = e.Graphics;                 int maxWidth = 0;\/\/\u0412\u044b\u0441\u043e\u0442\u0430 AutoScrollMinSize                 int maxHeight = 0;\/\/\u0428\u0438\u0440\u0438\u043d\u0430 AutoScrollMinSize                                   \/\/\u0440\u0430\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c \u0448\u0438\u0440\u0438\u043d\u0443                 foreach (Column item in BParent.Columns)                 {                     maxWidth += item.Width;                 }                 \/\/\u0440\u0430\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c \u0432\u044b\u0441\u043e\u0442\u0443                 foreach (Row item in BParent.Rows)                 {                     maxHeight += item.Heigth;                 }                 AutoScrollMinSize = new Size(maxWidth + 100, maxHeight + 100);\/\/\u043d\u0430\u0437\u043d\u0430\u0447\u0430\u0435\u043c AutoScrollMinSize \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u044d\u0442\u043e\u0433\u043e \u0431\u0443\u0434\u0443\u0442 \u043f\u043e\u044f\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u043f\u043e\u043b\u043e\u0441\u044b \u043f\u0440\u043e\u043a\u0440\u0443\u0442\u043a\u0438                 graf.Clear(BParent.BackColor);                 DrawHeaderColumns(graf);\/\/\u041e\u0442\u0440\u0438\u0441\u043e\u0432\u043a\u0430 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u043e\u0432 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u044b                 DrawHeaderRows(graf);\/\/\u041e\u0442\u0440\u0438\u0441\u043e\u0432\u043a\u0430 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u043e\u0432 \u0441\u0442\u0440\u043e\u043a \u0442\u0430\u0431\u043b\u0438\u0446\u044b                 DrawCells(graf);\/\/\u041e\u0442\u0440\u0438\u0441\u043e\u0432\u043a\u0430 \u044f\u0447\u0435\u0435\u043a                 base.OnPaint(e);             }             \/\/\/ &lt;summary&gt;             \/\/\/ \u041e\u0442\u0440\u0438\u0441\u043e\u043a\u0430 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u043e\u0432 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432             \/\/\/ &lt;\/summary&gt;             \/\/\/ &lt;param name=&quot;graf&quot;&gt;&lt;\/param&gt;             private void DrawHeaderColumns(Graphics graf)             {                 int x = 2;                 Rectangle rect;                 rect = new Rectangle(x, 1, BParent.RowHeaderWidth, BParent.ColumnHeaderHeigth);                 graf.DrawRectangle(new Pen(BParent.BorderColor), rect);                 graf.FillRectangle(new SolidBrush(BParent.ColumnHeaderBack), rect);                 x += BParent.RowHeaderWidth + 1;                 foreach (Column item in BParent.Columns)                 {                     rect = new Rectangle(x, 1, item.Width, BParent.ColumnHeaderHeigth);                     graf.DrawRectangle(new Pen(BParent.BorderColor), rect);                     graf.FillRectangle(new SolidBrush(BParent.ColumnHeaderBack), rect);                     if (item.Caption.Length != 0)                     {                         StringFormat sf = new StringFormat();                         sf.Alignment = StringAlignment.Center;                         sf.LineAlignment = StringAlignment.Center;                         graf.DrawString(item.Caption, new Font(&quot;Times&quot;, 9), Brushes.Black, rect, sf);                     }                     x += item.Width + 1;                 }             }             \/\/\u041e\u0442\u0440\u0438\u0441\u043e\u0432\u043a\u0430 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u043e\u0432 \u0441\u0442\u0440\u043e\u043a             private void DrawHeaderRows(Graphics graf)             {                 int y = 1;                 int i = 0;                 Rectangle rect;                 y += BParent.RowHeaderWidth + 1;                 foreach (Row item in BParent.Rows)                 {                     rect = new Rectangle(2, y, BParent.RowHeaderWidth, item.Heigth);                     graf.DrawRectangle(new Pen(BParent.BorderColor), rect);                     graf.FillRectangle(new SolidBrush(BParent.ColumnHeaderBack), rect);                     if (BParent.NumerableRows)                     {                         StringFormat sf = new StringFormat();                         sf.Alignment = StringAlignment.Center;                         sf.LineAlignment = StringAlignment.Center;                         graf.DrawString(i.ToString(), new Font(&quot;Times&quot;, 9), Brushes.Black, rect, sf);                     }                     i++;                     y += item.Heigth + 1;                 }             }             \/\/\u043e\u0442\u0440\u0438\u0441\u043e\u0432\u043a\u0430 \u044f\u0447\u0435\u0435\u043a             private void DrawCells(Graphics graf)             {                  int x = 2 + BParent.RowHeaderWidth + 1;                 int y = 2 + BParent.ColumnHeaderHeigth;                 Rectangle rect;                 int i = 0;                 foreach (Row itemRow in BParent.Rows)                 {                     foreach (Column itemColumn in BParent.Columns)                     {                         rect = new Rectangle(x, y, itemColumn.Width, itemRow.Heigth);                         graf.DrawRectangle(new Pen(BParent.BorderColor), rect);                         graf.FillRectangle(new SolidBrush(Color.White), rect);                         if (itemRow.Cells[i].Value != null)                         {                             StringFormat sf = new StringFormat();                             sf.Alignment = StringAlignment.Center;                             sf.LineAlignment = StringAlignment.Center;                             graf.DrawString(itemRow.Cells[i].Value.ToString(), new Font(&quot;Times&quot;, 9), Brushes.Black, rect, sf);                         }                         x += itemColumn.Width + 1;                         i++;                     }                     i = 0;                     y += itemRow.Heigth + 1;                     x = 2 + BParent.RowHeaderWidth + 1;                 }             }         } <\/code><\/pre>\n<p>   \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u00ab\u041f\u0435\u0440\u0435\u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u00bb \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043d\u0430 \u0444\u043e\u0440\u043c\u0443(\u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435):<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/ipic.su\/img\/img7\/fs\/1.1581000991.png\" alt=\"image\"\/><\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u043c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u043d\u0430\u0448\u0435\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430:<\/p>\n<pre><code class=\"cs\">  public partial class Form1 : Form     {         public Form1()         {             InitializeComponent();              tableCustoms1.Rows.Add(new Row());\/\/\u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u0442\u0440\u043e\u043a\u0438              tableCustoms1.Rows.Add(new Row());              tableCustoms1.Rows[0].Cells[0].Value = &quot;1&quot;;\/\/\u0418\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u044f\u0447\u0435\u0439\u043a\u0438              tableCustoms1.Rows[1].Cells[1].Value = &quot;2&quot;;             tableCustoms1.CountRow++;\/\/\u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u0435 \u0447\u0438\u0441\u043b\u0430 \u0441\u0442\u0440\u043e\u043a             tableCustoms1.Rows[0].Cells[0].Value = &quot;\u043f\u0440\u0438\u0432\u0435\u0442&quot;;         }     } <\/code><\/pre>\n<p>   \u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043d\u0430\u0448 \u043f\u0440\u043e\u0435\u043a\u0442:<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/ipic.su\/img\/img7\/fs\/2.1581001223.png\" alt=\"image\"\/><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/487616\/\"> https:\/\/habr.com\/ru\/post\/487616\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/487616\/\">\u0414\u043e\u0431\u0440\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0441\u0443\u0442\u043e\u043a! <\/p>\n<p>  \u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043e\u043f\u0438\u0448\u0443 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u0432\u043e\u0438\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0434\u043b\u044f C# Windows Form.<\/p>\n<p>  \u0414\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0431\u0443\u0434\u0443 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0441\u043e \u0432\u0441\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u043e\u043c DataGridView. \u041f\u043e\u0437\u0436\u0435 \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043d\u0430 \u0441\u0432\u043e\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b. \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0440\u0430\u0437\u043e\u0431\u044c\u0435\u043c \u043d\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0443\u0440\u043e\u043a\u043e\u0432. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0443\u0440\u043e\u043a\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043c \u043e\u0442 \u0440\u0438\u0441\u043e\u0432\u043a\u0443 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u0430 \u0442\u0430\u043a\u0436\u0435: \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432, \u0441\u0442\u0440\u043e\u043a, \u044f\u0447\u0435\u0435\u043a.<\/p>\n<p>  \u0414\u043b\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c .Net FrameWork 4.7.x, \u0441\u0440\u0435\u0434\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 Visual Studio 2019.<\/p>\n<p>  \u0412 \u043f\u0435\u0440\u0432\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 Windows Form. \u0414\u0443\u043c\u0430\u044e \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u044d\u0442\u043e \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c. \u0410 \u0443\u0436\u0435 \u043f\u043e\u0442\u043e\u043c \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442 \u00ab\u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f Windows Form\u00bb(\u041d\u0430\u0437\u043e\u0432\u0435\u043c \u0435\u0433\u043e CustomControl).<\/p>\n<p>  \u0414\u0430\u043b\u0435\u0435 \u0443 \u043d\u0430\u0441 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u043d \u0444\u0430\u0439\u043b UserControl.cs. \u0423\u0434\u0430\u043b\u044f\u0435\u043c \u0435\u0433\u043e \u0438 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 TableCustoms.cs.\u041d\u0430\u0448 \u043a\u043b\u0430\u0441\u0441 \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043e\u0442 \u043a\u043b\u0430\u0441\u0441\u0430 Control.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-298414","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/298414","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=298414"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/298414\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=298414"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=298414"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=298414"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}