Form設定為最大化,單純看Form裏頭控制項的變化
程式介面:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace 解析度
{
public partial class Form1 : Form
{
float sel_w = 0, sel_h = 0;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (radioButton1.Checked)
{
foreach (Control c in panel1.Controls)
{
c.Scale(sel_w / 1024, sel_h / 768);
Single currentSize = c.Font.Size * (sel_h / 768);
c.Font = new Font("微軟正黑體", currentSize);
}
sel_w = 1024;
sel_h = 768;
}
else
{
foreach (Control c in panel1.Controls)
{
c.Scale(sel_w / 1280, sel_h / 1024);
Single currentSize = c.Font.Size * (sel_h / 1024);
c.Font = new Font("微軟正黑體", currentSize);
}
sel_w = 1280;
sel_h = 1024;
}
label1.Text = "button1.Width:" + button1.Width + "\nbutton1.Height:" + button1.Height + "\nbutton1.Top:" + button1.Top + "\nbutton1.Left:" + button1.Left;
}
private void Form1_Load(object sender, EventArgs e)
{
radioButton1.Checked = true;
sel_w = Screen.PrimaryScreen.Bounds.Width;
sel_h = Screen.PrimaryScreen.Bounds.Height;
}
}
}
程式結果:


沒有留言:
張貼留言