C#根据窗体大小改变控件大小
2014-12-10 16:10
274 查看
首先定义全局变量
<span style="white-space:pre"></span><pre name="code" class="csharp">int label1_width, label1_height, label1_left, label1_top;
int label2_width, label2_height, label2_left, label2_top;
int label4_width, label4_height, label4_left, label4_top;
int textBox1_width, textBox1_height, textBox1_left, textBox1_top;
int textBox2_width, textBox2_height, textBox2_left, textBox2_top;
int textBox3_width, textBox3_height, textBox3_left, textBox3_top;
int textBox4_width, textBox4_height, textBox4_left, textBox4_top;
int button1_width, button1_height, button1_left, button1_top;
int button2_width, button2_height, button2_left, button2_top;
int button3_width, button3_height, button3_left, button3_top;<span style="font-family: Arial, Helvetica, sans-serif;"> </span>
然后在private void Form1_Load(object sender, EventArgs e)函数里边
label1_width = label1.Width;
label1_height = label1.Height;
label1_left = label1.Left;
label1_top = label1.Top;
label2_width = label2.Width;
label2_height = label2.Height;
label2_left = label2.Left;
label2_top = label2.Top;
label4_width = label4.Width;
label4_height = label4.Height;
label4_left = label4.Left;
label4_top = label4.Top;
textBox1_width = textBox1.Width;
textBox1_height = textBox1.Height;
textBox1_left = textBox1.Left;
textBox1_top = textBox1.Top;
textBox2_width = textBox2.Width;
textBox2_height = textBox2.Height;
textBox2_left = textBox2.Left;
textBox2_top = textBox2.Top;
textBox3_width = textBox3.Width;
textBox3_height = textBox3.Height;
textBox3_left = textBox3.Left;
textBox3_top = textBox3.Top;
textBox4_width = textBox4.Width;
textBox4_height = textBox4.Height;
textBox4_left = textBox4.Left;
textBox4_top = textBox4.Top;
button1_width = button1.Width;
button1_height = button1.Height;
button1_left = button1.Left;
button1_top = button1.Top;
button2_width = button2.Width;
button2_height = button2.Height;
button2_left = button2.Left;
button2_top = button2.Top;
button3_width = button3.Width;
button3_height = button3.Height;
button3_left = button3.Left;
button3_top = button3.Top;
写函数
private void SizeRefresh()
{
label1.Left = label1_left * this.Width / form1_width;
label1.Top = label1_top * this.Height / form1_height;
label1.Width = label1_width * this.Width / form1_width;
label1.Height = label1_height * this.Height / form1_height;
label2.Left = label2_left * this.Width / form1_width;
label2.Top = label2_top * this.Height / form1_height;
label2.Width = label2_width * this.Width / form1_width;
label2.Height = label2_height * this.Height / form1_height;
label4.Left = label4_left * this.Width / form1_width;
label4.Top = label4_top * this.Height / form1_height;
label4.Width = label4_width * this.Width / form1_width;
label4.Height = label4_height * this.Height / form1_height;
textBox1.Left = textBox1_left * this.Width / form1_width;
textBox1.Top = textBox1_top * this.Height / form1_height;
textBox1.Width = textBox1_width * this.Width / form1_width;
textBox1.Height = textBox1_height * this.Height / form1_height;
textBox2.Left = textBox2_left * this.Width / form1_width;
textBox2.Top = textBox2_top * this.Height / form1_height;
textBox2.Width = textBox2_width * this.Width / form1_width;
textBox2.Height = textBox2_height * this.Height / form1_height;
textBox3.Left = textBox3_left * this.Width / form1_width;
textBox3.Top = textBox3_top * this.Height / form1_height;
textBox3.Width = textBox3_width * this.Width / form1_width;
textBox3.Height = textBox3_height * this.Height / form1_height;
textBox4.Left = textBox4_left * this.Width / form1_width;
textBox4.Top = textBox4_top * this.Height / form1_height;
textBox4.Width = textBox4_width * this.Width / form1_width;
textBox4.Height = textBox4_height * this.Height / form1_height;
button1.Left = button1_left * this.Width / form1_width;
button1.Top = button1_top * this.Height / form1_height;
button1.Width = button1_width * this.Width / form1_width;
button1.Height = button1_height * this.Height / form1_height;
button2.Left = button2_left * this.Width / form1_width;
button2.Top = button2_top * this.Height / form1_height;
button2.Width = button2_width * this.Width / form1_width;
button2.Height = button2_height * this.Height / form1_height;
button3.Left = button3_left * this.Width / form1_width;
button3.Top = button3_top * this.Height / form1_height;
button3.Width = button3_width * this.Width / form1_width;
button3.Height = button3_height * this.Height / form1_height;
}
调用函数
protected override void OnPaint(PaintEventArgs e) //主要重绘在这里体现
{
SizeRefresh();
}
将窗体的DoubleBufferfd改为True,否则会卡。
<span style="white-space:pre"></span><pre name="code" class="csharp">int label1_width, label1_height, label1_left, label1_top;
int label2_width, label2_height, label2_left, label2_top;
int label4_width, label4_height, label4_left, label4_top;
int textBox1_width, textBox1_height, textBox1_left, textBox1_top;
int textBox2_width, textBox2_height, textBox2_left, textBox2_top;
int textBox3_width, textBox3_height, textBox3_left, textBox3_top;
int textBox4_width, textBox4_height, textBox4_left, textBox4_top;
int button1_width, button1_height, button1_left, button1_top;
int button2_width, button2_height, button2_left, button2_top;
int button3_width, button3_height, button3_left, button3_top;<span style="font-family: Arial, Helvetica, sans-serif;"> </span>
然后在private void Form1_Load(object sender, EventArgs e)函数里边
label1_width = label1.Width;
label1_height = label1.Height;
label1_left = label1.Left;
label1_top = label1.Top;
label2_width = label2.Width;
label2_height = label2.Height;
label2_left = label2.Left;
label2_top = label2.Top;
label4_width = label4.Width;
label4_height = label4.Height;
label4_left = label4.Left;
label4_top = label4.Top;
textBox1_width = textBox1.Width;
textBox1_height = textBox1.Height;
textBox1_left = textBox1.Left;
textBox1_top = textBox1.Top;
textBox2_width = textBox2.Width;
textBox2_height = textBox2.Height;
textBox2_left = textBox2.Left;
textBox2_top = textBox2.Top;
textBox3_width = textBox3.Width;
textBox3_height = textBox3.Height;
textBox3_left = textBox3.Left;
textBox3_top = textBox3.Top;
textBox4_width = textBox4.Width;
textBox4_height = textBox4.Height;
textBox4_left = textBox4.Left;
textBox4_top = textBox4.Top;
button1_width = button1.Width;
button1_height = button1.Height;
button1_left = button1.Left;
button1_top = button1.Top;
button2_width = button2.Width;
button2_height = button2.Height;
button2_left = button2.Left;
button2_top = button2.Top;
button3_width = button3.Width;
button3_height = button3.Height;
button3_left = button3.Left;
button3_top = button3.Top;
写函数
private void SizeRefresh()
{
label1.Left = label1_left * this.Width / form1_width;
label1.Top = label1_top * this.Height / form1_height;
label1.Width = label1_width * this.Width / form1_width;
label1.Height = label1_height * this.Height / form1_height;
label2.Left = label2_left * this.Width / form1_width;
label2.Top = label2_top * this.Height / form1_height;
label2.Width = label2_width * this.Width / form1_width;
label2.Height = label2_height * this.Height / form1_height;
label4.Left = label4_left * this.Width / form1_width;
label4.Top = label4_top * this.Height / form1_height;
label4.Width = label4_width * this.Width / form1_width;
label4.Height = label4_height * this.Height / form1_height;
textBox1.Left = textBox1_left * this.Width / form1_width;
textBox1.Top = textBox1_top * this.Height / form1_height;
textBox1.Width = textBox1_width * this.Width / form1_width;
textBox1.Height = textBox1_height * this.Height / form1_height;
textBox2.Left = textBox2_left * this.Width / form1_width;
textBox2.Top = textBox2_top * this.Height / form1_height;
textBox2.Width = textBox2_width * this.Width / form1_width;
textBox2.Height = textBox2_height * this.Height / form1_height;
textBox3.Left = textBox3_left * this.Width / form1_width;
textBox3.Top = textBox3_top * this.Height / form1_height;
textBox3.Width = textBox3_width * this.Width / form1_width;
textBox3.Height = textBox3_height * this.Height / form1_height;
textBox4.Left = textBox4_left * this.Width / form1_width;
textBox4.Top = textBox4_top * this.Height / form1_height;
textBox4.Width = textBox4_width * this.Width / form1_width;
textBox4.Height = textBox4_height * this.Height / form1_height;
button1.Left = button1_left * this.Width / form1_width;
button1.Top = button1_top * this.Height / form1_height;
button1.Width = button1_width * this.Width / form1_width;
button1.Height = button1_height * this.Height / form1_height;
button2.Left = button2_left * this.Width / form1_width;
button2.Top = button2_top * this.Height / form1_height;
button2.Width = button2_width * this.Width / form1_width;
button2.Height = button2_height * this.Height / form1_height;
button3.Left = button3_left * this.Width / form1_width;
button3.Top = button3_top * this.Height / form1_height;
button3.Width = button3_width * this.Width / form1_width;
button3.Height = button3_height * this.Height / form1_height;
}
调用函数
protected override void OnPaint(PaintEventArgs e) //主要重绘在这里体现
{
SizeRefresh();
}
将窗体的DoubleBufferfd改为True,否则会卡。
相关文章推荐
- C#实现窗体控件随窗体大小改变(包括字体大小)
- C#实现窗体控件随窗体大小改变(包括字体大小)
- C#当窗体大小改变时,窗体中的控件大小也随之改变
- MFC控件大小随窗体改变而改变
- C# 窗体控件随窗体改变大小
- C#里WinForm开发中如何实现控件随窗体大小的改变而自动适应其改变
- C# WinForm (笨方法)根据不同的样式配置 设置窗体相关控件的背景 以改变窗体风格
- 当窗体改变大小时控件大小随之改变(使用函数)
- 窗体控件随窗体大小改变(包括字体大小)
- 当窗体最大化后,如何让窗体里面的控件也随之改变大小和位置
- C# WinForm (笨方法)根据不同的样式配置 设置窗体相关控件的背景 以改变窗体风格
- C#当窗体大小改变时,窗体中的控件大小也随之改变
- vb 中控件随窗体的改变成比例改变大小
- Winform 控件随窗体大小改变而变化
- 怎样实现控件随窗体大小而改变!!
- C#实现窗体控件随窗体大小改变(包括字体大小)
- VC 控件根据窗口大小变化改变大小和位置。(EasySize)
- vb 中控件随窗体的改变成比例改变大小
- c#中控件随窗体大小改变的代码(winform开发)
- 让控件随窗体大小改变而改变