winform左右滑动
public static class FormTransform
{
public static void TransformSize(Form frm, int newWidth, int newHeight)
{
TransformSize(frm, new Size(newWidth, newHeight));
} public static void TransformSize(Control ctl, int newWidth, int newHeight)
{
TransformSize(ctl, new Size(newWidth, newHeight));
} public static void TransformSize(object frm, Size newSize)
{
ParameterizedThreadStart threadStart = new ParameterizedThreadStart(RunTransformation);
Thread transformThread = new Thread(threadStart);
transformThread.Start(new object[] { frm, newSize });
} private delegate void RunTransformationDelegate(object paramaters);
private static void RunTransformation(object parameters)
{
//Form boder = (Form)((object[])parameters)[0];
Panel boder = (Panel)((object[])parameters)[];
if (boder.InvokeRequired)
{
RunTransformationDelegate del = new RunTransformationDelegate(RunTransformation);
boder.Invoke(del, parameters);
}
else
{
//动画的变量参数
double FPS = 300.0;
long interval = (long)(Stopwatch.Frequency / FPS);
long ticks1 = ;
long ticks2 = ; //传进来的新的窗体的大小
Size size = (Size)((object[])parameters)[]; int xDiff = Math.Abs(boder.Width - size.Width);
int yDiff = Math.Abs(boder.Height - size.Height); int step = ; int xDirection = boder.Width < size.Width ? : -;
int yDirection = boder.Height < size.Height ? : -; int xStep = step * xDirection;
int yStep = step * yDirection; //要调整的窗体的宽度是否在步长之内
bool widthOff = IsWidthOff(boder.Width, size.Width, xStep);
//要调整的窗体的高度是否在步长之内
bool heightOff = IsHeightOff(boder.Height, size.Height, yStep); while (widthOff || heightOff)
{
//获取当前的时间戳
ticks2 = Stopwatch.GetTimestamp();
//允许调整大小仅在有足够的时间来刷新窗体的时候
if (ticks2 >= ticks1 + interval)
{
//调整窗体的大小
if (widthOff)
boder.Width += xStep; if (heightOff)
boder.Height += yStep; widthOff = IsWidthOff(boder.Width, size.Width, xStep);
heightOff = IsHeightOff(boder.Height, size.Height, yStep); //允许窗体刷新
Application.DoEvents(); //保存当前的时间戳
ticks1 = Stopwatch.GetTimestamp();
} Thread.Sleep();
} }
} private static bool IsWidthOff(int currentWidth, int targetWidth, int step)
{
//目标宽度与当前宽度是否在步长之内,如果是,返回false
if (Math.Abs(currentWidth - targetWidth) <= Math.Abs(step)) return false; return (step > && currentWidth < targetWidth) ||
(step < && currentWidth > targetWidth);
} private static bool IsHeightOff(int currentHeight, int targetHeight, int step)
{
//目标高度与当前高度是否在步长之内,如果是,返回false
if (Math.Abs(currentHeight - targetHeight) <= Math.Abs(step)) return false; return (step > && currentHeight < targetHeight) ||
(step < && currentHeight > targetHeight);
}
}
//调用代码
FormTransform.TransformSize(this, width, height);
winform左右滑动的更多相关文章
- 在winform中,禁止combobox随着鼠标一起滑动!
在winform中,如果form上或者是控件上有一个combobox控件,当你选择这个控件,当你鼠标移动其他地方,滑动鼠标时,这时combobox的选择值就会随之鼠标一起变化,如果你不想让comboB ...
- winform实现图片的滑动效果
使用winform实现图片的滑动效果(类似网站首页图片滑动切换效果),结果实现了,但是效果其实不是很理想.也许有更好的方法. Timer timerSlide = null; //当前 ...
- winform 实现类似于TrackBar的自定义滑动条,功能更全
功能很全,随便列几个 1.可以设置滑块的大小,边框颜色.背景色.形状等等吧 2.可以设置轨道的方向.边框颜色.背景色.阴影等等 ... 效果图: 下载链接https://download.csdn.n ...
- WPF 自定义BarChartControl(可左右滑动的柱状图)
自定义可左右滑动.拖拽滑动的平面柱状图 在做这种样式控件之前,可先浏览我之前预研的控件: A.自定义左右滑动ScrollViewer(可拖动滑动) B.自定义Bar柱状图 OK,现在说下控件具体设计过 ...
- winform右下角弹窗
网页是否经常在电脑右下角弹窗显示消息?其实Winform也是可以实现的.下面介绍两种方法. 第一步:设计窗体 第二步:实现代码 第一种方法 引用user32 声明常量 窗体Load事件 窗体FormC ...
- Winform实现右下角弹窗_提示信息
网页是否经常在电脑右下角弹窗显示消息?其实Winform也是可以实现的.下面介绍两种方法. 第一步:设计窗体 第二步:实现代码 第一种方法 引用user32 声明常量 窗体Load事件 窗体FormC ...
- 关于WinForm/Web如何使用缓存Cach
原文链接:http://www.cnblogs.com/zfanlong1314/archive/2013/03/28/2986403.html Cache 的绝对到期与滑动到期 绝对到期:设置绝对过 ...
- WinForm实现类似QQ停靠,显示隐藏过程添加特效效果
原文:WinForm实现类似QQ停靠,显示隐藏过程添加特效效果 这可能是个老题长谈的问题了,只是在项目中会用到这个效果,所以今天做个记录.大家见了别喷我.在项目中的需求是这样的. 打开程序,在屏幕的右 ...
- winform界面特效470多例
一共470多例winform 界面特效的源码. 实例030 窗口颜色的渐变 实例说明 在程序设计时,可以通过设置窗体的BackColor属性来改变窗口的背景颜色.但是这个属性改变后整个窗体的客户区都会 ...
随机推荐
- GCD与LCM
求最大公约数(GCD)和求最小公倍数(LCM): 首先是求最大公约数,我们可以利用辗转相除法来求 1 int gcd(int a,int b) 2 { 3 if(b==0) 4 return a; 5 ...
- ajax原生
let xml; let url="http://localhost:3333"; let data={name:'lishishi',age:'22'} if(window.XM ...
- UML关系实现、泛化,依赖、组合
图片via<大话设计模式> UML一目了然
- Android100【申明:来源于网络】
Android100[申明:来源于网络] 地址:http://www.android100.org/html/201406/11/23770.html
- matlab知识
matlab中cumsum函数通常用于计算一个数组各行的累加值. 调用格式及说明 matlab中cumsum函数通常用于计算一个数组各行的累加值.在matlab的命令窗口中输入doc cumsum或者 ...
- Unified Temporal and Spatial Calibration for Multi-Sensor Systems
下载链接:点击 为了提高机器人状态估计的准确性和鲁棒性,越来越多的应用依赖于来自多个互补传感器的数据. 为了在传感器融合中获得最佳性能,这些不同的传感器必须在空间上和时间上相互对准.为此,已经开发了许 ...
- 用java代码解决excel打开csv文件乱码问题
Java 读取csv文件后,再保存到磁盘上,然后直接用Excel打开,你会发现里面都是乱码. 贴上代码: public class Test { public static void main(S ...
- Docker入门1------概念和安装
关于docker的介绍: https://www.cnblogs.com/neptunemoon/p/6512121.html docker入门教程:http://www.docker.org.cn/ ...
- array 和 alloc init 以及 new 区别
当你使用new.alloc或copy方法创建一个对象时,该对象的引用计数器值为1.当不再使用该对象时,你要负责向该对象发送一条release或autorelease消息.这样,该对象将在其使用寿命结束 ...
- Centos7.1环境下搭建BugFree
环境准备: 系统 配置 IP Centos7.1 1核2G+60GB硬盘 10.10.28.204 1. 安装apache yum install httpd 2. 安装mysql yum inst ...