Set ClientSize to change the form window size : Form Frame Window « GUI Windows Form « C# / C Sharp






Set ClientSize to change the form window size

 
using System;
using System.Drawing;
using System.Windows.Forms;
   
class AutoScaleDemo: Form
{
     public static void Main()
     {
          Application.Run(new AutoScaleDemo());
     }
     public AutoScaleDemo()
     {
          Font = new Font("Arial", 12);
          FormBorderStyle = FormBorderStyle.FixedSingle;
   
          int[] aiPointSize = { 8, 12, 16, 24, 32 };
   
          for (int i = 0; i < aiPointSize.Length; i++)
          {
               Button btn    = new Button();
               btn.Parent    = this;
               btn.Text      = "Use " + aiPointSize[i] + "-point font";
               btn.Tag       = aiPointSize[i];
               btn.Location  = new Point(4, 16 + 24 * i);
               btn.Size      = new Size(80, 16);
               btn.Click    += new EventHandler(ButtonOnClick);
          }
          ClientSize = new Size(88, 16 + 24 * aiPointSize.Length);
          AutoScaleBaseSize = new Size(4, 8);
     }
     protected override void OnPaint(PaintEventArgs pea)
     {
          pea.Graphics.DrawString(Text, Font, new SolidBrush(ForeColor), 0, 0);
     }
     void ButtonOnClick(object obj, EventArgs ea)
     {
          Button btn = (Button) obj;
   
          SizeF sizefOld = GetAutoScaleSize(Font);
          Font = new Font(Font.FontFamily, (int) btn.Tag);
          SizeF sizefNew = GetAutoScaleSize(Font);
   
          Scale(sizefNew.Width  / sizefOld.Width,sizefNew.Height / sizefOld.Height);
     }
}

 








Related examples in the same category

1.Print out Form size and position related information
2.Use Font from Form to paint string on a form
3.Set ResizeRedraw property
4.FormStartPosition.CenterScreen
5.Form hideForm hide
6.Change Form window ownershipChange Form window ownership
7.Create Graphics Object from form window handleCreate Graphics Object from form window handle
8.Center form windowCenter form window
9.Assign Form window default valueAssign Form window default value
10.Change the background and text colors of a form using Color DialogChange the background and text colors of a form using Color Dialog
11.Draw image based on the window sizeDraw image based on the window size
12.Auto scroll form windowAuto scroll form window
13.Set Form window title and center the Form window on the desktopSet Form window title and center the Form window on the desktop
14.Add control to a form windowAdd control to a form window
15.Change Form window backgroundChange Form window background
16.Simplest form code: set window titleSimplest form code: set window title
17.Login fromLogin from
18.makes a new window out of a graphics path that has been traced on this forms spacemakes a new window out of a graphics path that has been traced on this forms space
19.Windows Forms Getting StartedWindows Forms Getting Started
20.A form-based Windows SkeletonA form-based Windows Skeleton
21.Simple formSimple form
22.Add controls to a formAdd controls to a form
23.Form for data inputForm for data input
24.Demonstrates creating a form in a console programDemonstrates creating a form in a console program
25.AutoScrollPosition