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属性来改变窗口的背景颜色.但是这个属性改变后整个窗体的客户区都会 ...
随机推荐
- jquery操作checkBox 一次取消选中后不能再选中
$("input[type='checkbox']").each(function(){ $(this).attr("checked","checke ...
- JavaScript基础知识(Number的方法)
Number的方法 number : 数字 正数 负数 0 NaN 小数; NaN : not a number; 不是一个数字,但是属于数字类型的: 1.typeof :检测当前的数据类型的: 首先 ...
- stm32f769ni-discovery编译例程需要修改
找不到cmsis_os.h: 方法:在pack文件夹下找cmsis_os.h文件,有四个,选RTOS2文件夹下的. 原因:cmsis_os2.h是新版本,cmsis_os.h封装了cmsis_os2. ...
- SQL Server (MSSQLSERVER) 服务由于下列服务特定错误而终止: %%17051
问题出现:今天在给客户调试项目的时候,发现无法连接SQL server数据库 解决过程:1.在cmd命令窗口输入services.msc,打开服务窗口,找到SQL Server (MSSQLSERVE ...
- 5、 LwIP协议栈规范翻译——操作系统仿真层
为了使lwIP可移植,操作系统特定的函数调用和数据结构不直接在协议的代码中使用.相反,当需要这样的函数调用和数据结构时,直接使用操作系统仿真层. 操作系统仿真层为操作系统服务提供统一的接口,如定时器, ...
- threw exception [Handler processing failed; nested exception is java.lang.NoClassDefFoundError: com/dyuproject/protostuff/MapSchema$MessageFactory] with root cause
错误记录 前几天朋友问我一个错误,顺便记录一下,关于redis 工具类,protostuff序列化报错. threw exception [Handler processing failed; nes ...
- [js]js中函数传参判断
1,通过|| function fun(x,y){ x=x||0; y=y||1; alert(x+y); } fun(); 2.通过undefined对比 function fun(x,y){ if ...
- ubuntu12.04下编译Linux tina 2.1/android经验
用的是osboxes下的vdi. 编译Linux 1. 不能在root用户下操作 2. 执行 make kernel_menuconfig 报错,需要 apt-get install zlib1g z ...
- iOS UI基础-21 WKWebView
WKWebView,直接显示网页,需要引入第三方类:https://github.com/marcuswestin/WebViewJavascriptBridge 加上进度条代码,很完美使用 webV ...
- Cocos Creator 触摸点击事件
触摸事件// 使用枚举类型来注册枚举对象定义 对应的事件名 事件触发的时机cc.Node.EventType.TOUCH_START 'touchstart' 当手指触点落在目标节点区域内时cc.No ...