窗体的代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
WindowsApplication1.Instance.InitInstance(this);
}
}
}
实现方法的类:
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
namespace WindowsApplication1
{
public class Instance
{
public static void InitInstance(System.Windows.Forms.Form form)
{
form.Size = new Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
Screen sc = Screen.PrimaryScreen;
float w = sc.Bounds.Width;
float h = sc.Bounds.Height;
foreach (Control c in form.Controls)
{
c.Size = new Size((int)(c.Width * w / 1024),(int) (c.Height * h / 768));
c.Location = new Point((int)(c.Left * w / 1024),(int)( c.Top * h / 768));
Single size = Convert.ToSingle(c.Font.Size *h/768);
c.Font = new Font(c.Font.Name,size,c.Font.Style,c.Font.Unit);
}
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
WindowsApplication1.Instance.InitInstance(this);
}
}
}
实现方法的类:
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
namespace WindowsApplication1
{
public class Instance
{
public static void InitInstance(System.Windows.Forms.Form form)
{
form.Size = new Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
Screen sc = Screen.PrimaryScreen;
float w = sc.Bounds.Width;
float h = sc.Bounds.Height;
foreach (Control c in form.Controls)
{
c.Size = new Size((int)(c.Width * w / 1024),(int) (c.Height * h / 768));
c.Location = new Point((int)(c.Left * w / 1024),(int)( c.Top * h / 768));
Single size = Convert.ToSingle(c.Font.Size *h/768);
c.Font = new Font(c.Font.Name,size,c.Font.Style,c.Font.Unit);
}
}
}
}