Sizer for WinForms
カスタマイズ化

Sizer lets you customize the look of the Sizer control to change the appearance of your application. Let us discuss how to customize the appearance of Sizer control.

Apply 3-D Border

The Sizer control lets you customize the border of grid, rows, and columns by changing their style and color. You can create a styled border for the rows and columns of the Sizer control by using Paint event and Draw3DBorder method of the C1Sizer class. The Paint event repaints the control's rows and columns and DrawBorder3D method draws an etched three dimensional border around the rows and columns of the Sizer control.

The following image shows the Sizer control with 3-D Border.

Subscribe to Paint event of the C1Sizer class and add the following code to the C1Sizer_Paint Event Handler to create 3-D borders. This example uses the sample created in the Quick Start topic.

C#
コードのコピー
private void C1Sizer1_Paint(object? sender, PaintEventArgs e)
{
     //Sizer Grid の各セルに 3D 境界線を描画します
     foreach (Band row in this.c1Sizer1.Grid.Rows)
     {
         //行の境界を取得します
         Rectangle rcrow = row.Bounds;

         foreach (Band col in this.c1Sizer1.Grid.Columns)
         {
             //列の境界を取得します
             Rectangle rccol = col.Bounds;

             //行と列の交差する四角形を取得します
             Rectangle rccel = Rectangle.Intersect(rcrow, rccol);

             //交差する長方形の 3D 境界線を描画します
             ControlPaint.DrawBorder3D(e.Graphics, rccel, Border3DStyle.Etched);
         }
     }
}

Back to Top 

Resize Fonts in Sizer

By default, Sizer resizes the controls positioned within the grid but not their font. However, there may be a scenario where you need to resize the fonts as the controls gets resized. To achieve this, you can override the OnResizeEnd method to set the Font property.

The following GIF shows how the fonts and controls gets resized, when you resize the Sizer control.

To resize font in Sizer control, use the following code.

C#
コードのコピー
private Size _cs;
private float _fs;
        
public Form1()
{
  InitializeComponent();
  _fs = Font.Size;
  _cs = ClientSize;
  AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
}
protected override void OnResizeEnd(EventArgs e)
{
   var sz = ClientSize;
   var factor = Math.Min(sz.Width / (float)_cs.Width, sz.Height / (float)_cs.Height);
   //Font プロパティを明示的に更新します
   Font = new Font(Font.Name, (float)(_fs * factor));
   base.OnResizeEnd(e);
}

Back to Top