C#实现窗口拖动时各个控件同比自己主动放缩大小
实现方式主要是利用panel控件为主题。对于每一个控件的大小位置和字体这几个属性进行记录。
然后依据窗口改变的大小同一时候放缩。
简要过程例如以下:
1 创建C#窗口程序项目。
2 Panel放置到窗口。
3 设置属性dock为fill。
4 注意MinnumSize不能设置为0, 改成大于0都行。
public partial class FrmDemo : Form
{
double dFrmWidth;
double dFrmHeight;
double dZoomHorizon;
double dZoomVerticality;
Dictionary<string, string> dicControlsAttribute = new Dictionary<string, string>(); protected void GetAllInitiateContrlInfo(Control CrlContainer)
{
if (CrlContainer.Parent == this)
{
dFrmWidth = Convert.ToDouble(CrlContainer.Width);
dFrmHeight = Convert.ToDouble(CrlContainer.Height);
}
foreach (Control item in CrlContainer.Controls)
{
if (item.Name.Trim() != "")
dicControlsAttribute.Add(item.Name, (item.Left + item.Width / 2) + "," + (item.Top + item.Height / 2)
+ "," + item.Width + "," + item.Height + "," + item.Font.Size);
if ((item as UserControl) == null && item.Controls.Count > 0)
GetAllInitiateContrlInfo(item);
}
} private void ChangeControlsInitiate(Control CrlContainer)
{
dZoomHorizon = (Convert.ToDouble(CrlContainer.Width) / dFrmWidth);
dZoomVerticality = (Convert.ToDouble(CrlContainer.Height) / dFrmHeight);
} private void ChangeCurrentControlAttr(Control CrlContainer)
{
double[] dPosition = new double[5];
foreach (Control item in CrlContainer.Controls)
{
if (item.Name.Trim() != "")
{
if ((item as UserControl) == null && item.Controls.Count > 0)
ChangeCurrentControlAttr(item);
string[] strs = dicControlsAttribute[item.Name].Split(',');
for (int j = 0; j < 5; j++)
{
dPosition[j] = Convert.ToDouble(strs[j]);
}
double itemWidth = dPosition[2] * dZoomHorizon;
double itemHeight = dPosition[3] * dZoomVerticality;
item.Left = Convert.ToInt32(dPosition[0] * dZoomHorizon - itemWidth / 2);
item.Top = Convert.ToInt32(dPosition[1] * dZoomVerticality - itemHeight / 2);
item.Width = Convert.ToInt32(itemWidth);
item.Height = Convert.ToInt32(itemHeight);
//item.Font = new Font(item.Font.Name, float.Parse
//((dPosition[4] * Math.Min(dZoomHorizon, dZoomVerticality)).ToString()));
//字体也能够实现同比放缩。
}
}
}
protected override void OnSizeChanged(EventArgs e)
{
base.OnSizeChanged(e);
if (dicControlsAttribute.Count > 0)
{
ChangeControlsInitiate(this.Controls[0]);
ChangeCurrentControlAttr(this.Controls[0]);
}
} public FrmDemo()
{
InitializeComponent();
GetAllInitiateContrlInfo(this.Controls[0]);//构造函数里面调用就可以。
}
}
5 效果測试
C#实现窗口拖动时各个控件同比自己主动放缩大小的更多相关文章
- 在C#中子线程如何操作主窗口线程上的控件
在C#中子线程怎样操作主线程中窗口上控件 在C#中,直接在子线程中对窗口上的控件操作是会出现异常,这是因为子线程和运行窗口的线程是不同的空间,因此想要在子线程来操作窗口上的控件.是不可能简单的通过控件 ...
- WPF 程序如何跨窗口/跨进程设置控件焦点
原文:WPF 程序如何跨窗口/跨进程设置控件焦点 WPF 程序提供了 Focus 方法和 TraversalRequest 来在 WPF 焦点范围内转移焦点.但如果 WPF 窗口中嵌入了其他框架的 U ...
- 基于MVC4+EasyUI的Web开发框架经验总结(13)--DataGrid控件实现自己主动适应宽带高度
在默认情况下,EasyUI的DataGrid好像都没有具备自己主动宽度的适应功能,通常是指定像素宽度的.可是使用的人员计算机的屏幕分辨率可能不一样,因此导致有些地方显示太大或者太小,总是不能达到好的预 ...
- 运行时改变控件的大小(点击后立刻ReleaseCapture,然后计算位移,最后发消息改变位置)——最有趣的是TPanel其实也有窗口标题,因此可发HTCAPTION消息
//光标在控件不同位置时的样式 // 由于拐角这点手动精确实在困难 所以用范围 范围+3 这样很容易就找到这一点了 procedure CtrlMouseMove(Ctrl: TWinControl; ...
- Python pyQt4/pyQt5 学习笔记1(空白窗口,按钮,控件事件,控件提示,窗体显示到屏幕中间,messagebox)
PyQt4是用来编写有图形界面程序(GUI applications)的一个工具包.PyQt4作为一个Python模块来使用,它有440个类和超过6000种函数和方法.同时它也是一个可以在几乎所有主流 ...
- C语言Windows程序开发—Windows窗口样式与常用控件样式【第04天】
(一)Windows窗口(MDICLIENT)样式介绍 /* Windows窗口样式 */ WS_BORDER //带有边框的窗口 WS_CAPTION //带有标题栏的窗口 WS_CHILD //子 ...
- C# winform中使用Panel调节窗口变化是各控件的位置(转)
我的目的是在窗口上有些控件,在窗口大小变化时,上面的控件位置不动,大小也不动.下面的控件随着窗口的大小变化而变大. 做法是用两个panel,panelTop和panelFill.上面的控件都放到pan ...
- 第十一篇 -- 如何实现MFC窗口的最大化以及控件随最大化
这一篇介绍的是怎么实现MFC窗口的最大最小化,以及里面控件大小也随之改变 第一步:实现窗口最大最小化 首先右击窗口空白处,打开properties,将里面的MaximizeBox和MinimizeBo ...
- WEB开发时Browser控件得到C:\fakepath\ 的解决方式
IE9中JS获得文件上传控件的路径不对,为:C:\fakepath\ 原来要修改: 工具 -> Internet选项 -> 安全 -> 自定义级别 -> 将本地文件上载至服务 ...
随机推荐
- redis作为缓存场景使用,内存耗尽时,突然出现大量的逐出,在这个逐出的过程中阻塞正常的读写请求,导致 redis 短时间不可用
redis 突然大量逐出导致读写请求block 内容目录: 现象 背景 原因 解决方案 ref 现象 redis作为缓存场景使用,内存耗尽时,突然出现大量的逐出,在这个逐出的过程中阻塞正常的读写请 ...
- sicily 1003. hash
Description 请用HASH链式法来解决冲突,且规定链表在链表头插入新元素. 规定HASH函数为:h(x) = x % 11,即哈希数组下标为0-10. 给定两种操作: I 操作,插入一个新的 ...
- BZOJ 2342 Manacher
思路: 首先用manacher可以求出以i和i+1中间为对称轴,最长回文串能扩增的长度p[i]. 然后4*(y-x)能更新答案,当且仅当y≤x+p[x]/2且y-p[y]≤x. 按i-p[i]将所有点 ...
- SSD-tensorflow-1 demo
一.简易识别 用最简单的已训练好的模型对20类目标做检测. 你电脑的tensorflow + CUDA + CUDNN环境都是OK的, 同时python需要安装cv2库 { 'aeropla ...
- tensorboard 使用
TensorBoard是TensorFlow 的可视化工具.主要为了更方便用户理解 TensorFlow 程序.调试与优化,用户可以用 TensorBoard 来展现 TensorFlow 图像,绘制 ...
- java 基于 bootstrap_datagrid 分页
1.首先引入datagrid js ,css $("#datagrid").bootstrap_datagrid({ url : "<%=path%>/us ...
- vmware启动虚拟机报错VMware Workstation has paused this virtual machine because the disk on which the virtual machine is stored is almost full. To continue, free an additional 1.4 GB of disk space.
报错VMware Workstation has paused this virtual machine because the disk on which the virtual machine i ...
- Spring Tool Suit安装virgo server插件、virgo的下载
virgo-tomcat原先是Spring DM Server,后来转eclipse社区维护 安装教程:http://osgi.com.cn/article/7289514 virgo-tomcat各 ...
- [CSSinJS] Convert Sass (SCSS) Styled Button to CSSinJS with JavaScript Templates and Variables
This is an introduction to CSSinJS that doesn't require any JavaScript knowledge, just a basic CSS. ...
- Class C++
为了尽量降低全局变量的使用并提供用户自己定义类型的功能.C++语言提供了一种新的语言机制---类(class).并以类作为构造程序的基本单位 #include<iostream> usin ...