C# 控件相对于Form位置不变
2010-05-27 22:00
288 查看
C# 控件相对于Form位置不变
保存控件的原先坐标
private void ResizeInit(Form fr)
{
foreach (Control ctrl in fr.Controls)
{
ctrl.Tag = ctrl.Left.ToString()+" "+ctrl.Top.ToString();
}
}
计算Form改变前与改变后的比例
fPreSize[0] = (float)this.Width;
fPreSize[1] = (float)this.Height;
this.WindowState = FormWindowState.Maximized;
this.Width = Screen.PrimaryScreen.WorkingArea.Width;
this.Height = Screen.PrimaryScreen.WorkingArea.Height;
fNowSize[0] = (float)this.Width / fPreSize[0];
fNowSize[1] = (float)this.Height / fPreSize[1];
3.改变控件位置
private void ResizeForm(Form fr)
{
int left, top;
foreach (Control ctrl in fr.Controls)
{
string [] sp = new string[1]{" "};
string [] pos =((string)ctrl.Tag).Split(sp, StringSplitOptions.RemoveEmptyEntries);
left = Convert.ToInt32(pos[0]);
top = Convert.ToInt32(pos[1]);
ctrl.Left = (int)(left * fNowSize[0]);
ctrl.Top = (int)(top * fNowSize[1]);
}
}
把1放到Form的构造函数中
把2放到Form_Load中
把3也放到Form_Load中
保存控件的原先坐标
private void ResizeInit(Form fr)
{
foreach (Control ctrl in fr.Controls)
{
ctrl.Tag = ctrl.Left.ToString()+" "+ctrl.Top.ToString();
}
}
计算Form改变前与改变后的比例
Form的原先大小 |
fPreSize[1] = (float)this.Height;
改变Form的大小 |
this.Width = Screen.PrimaryScreen.WorkingArea.Width;
this.Height = Screen.PrimaryScreen.WorkingArea.Height;
Form改变的比例 |
fNowSize[1] = (float)this.Height / fPreSize[1];
3.改变控件位置
private void ResizeForm(Form fr)
{
int left, top;
foreach (Control ctrl in fr.Controls)
{
string [] sp = new string[1]{" "};
string [] pos =((string)ctrl.Tag).Split(sp, StringSplitOptions.RemoveEmptyEntries);
left = Convert.ToInt32(pos[0]);
top = Convert.ToInt32(pos[1]);
ctrl.Left = (int)(left * fNowSize[0]);
ctrl.Top = (int)(top * fNowSize[1]);
}
}
把1放到Form的构造函数中
把2放到Form_Load中
把3也放到Form_Load中
相关文章推荐
- C# 控件相对于Form位置不变
- 窗体上的控件保持相对位置不变
- C# Winform 如何获得窗体上控件相对于屏幕的位置
- Delphi7 控件相对于form的绝对位置
- 功能: Form窗口最大化时,控件相对位置变化的问题 (学习日记2016-12-23)
- 让每次弹出的div随页面的卷动而保持相对位置不变
- C#中的静态函数,如何操作Form中的控件?
- Jquery如何序列化form表单数据为JSON对象 C# ADO.NET中设置Like模糊查询的参数 从客户端出现小于等于公式符号引发检测到有潜在危险的Request.Form 值 jquery调用iframe里面的方法 Js根据Ip地址自动判断是哪个城市 【我们一起写框架】MVVM的WPF框架(三)—数据控件 设计模式之简单工厂模式(C#语言描述)
- C#仿QQ皮肤----基窗体FormBase与基用户控件FormBase1的实现
- 调整数组顺序使奇数位于偶数前面,偶数和偶数之间的相对位置不变
- MFC中,如何获得对话框控件相对于父窗口(对话框窗口)的位置 及Invalidate(TRUE)的闪屏问题
- 利用C#更专业的实现运行时调整控件大小和位置
- 删除顺序表中所有值为x的元素(保持删除后元素相对位置不变)
- 获取控件间的相对位置 -- cnblog
- 用代码来控制自定义的控件 自动适应横竖屏时的相对位置
- 将一个数组中所有的奇数放左边,偶数放右边,且原来数字的相对位置不变
- 在运行时通过鼠标拖动移动控件位置(c#)
- 图片放大缩小并且文字与图片相对位置不变
- 调整数组 使得数组中负数排在前面正数排在后面,并且正数和负数的相对位置不变 (递归思路)
- .net c#拖动控件,移动控件位置