zoukankan
html css js c++ java
运行时通过拖拽动态改变控件的大小 Virus
using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Text;
using
System.Windows.Forms;
namespace
WindowsApplication11
{
public
partial
class
Form1 : Form
{
private
int
oldx;
private
int
oldy;
enum
mPosition
{
left,
right,
top,
bottom
}
private
mPosition adjust;
public
Form1()
{
InitializeComponent();
}
private
void
button1_MouseDown(
object
sender, MouseEventArgs e)
{
oldx
=
e.X;
oldy
=
e.Y;
}
private
void
button1_MouseMove(
object
sender, MouseEventArgs e)
{
Rectangle rectLeft
=
new
Rectangle(
0
,
2
,
2
, button1.Height
-
4
);
Rectangle rectRight
=
new
Rectangle(button1.Width
-
2
,
2
,
2
, button1.Width);
Rectangle rectTop
=
new
Rectangle(
2
,
0
, button1.Width
-
4
,
2
);
Rectangle rectBottom
=
new
Rectangle(
2
, button1.Height
-
2
, button1.Width
-
4
,
2
);
if
(rectLeft.Contains(e.X, e.Y))
{
adjust
=
mPosition.left;
button1.Cursor
=
Cursors.SizeWE;
}
else
if
(rectRight.Contains(e.X, e.Y))
{
adjust
=
mPosition.right;
button1.Cursor
=
Cursors.SizeWE;
}
else
if
(rectTop.Contains(e.X, e.Y))
{
adjust
=
mPosition.top;
button1.Cursor
=
Cursors.SizeNS;
}
else
if
(rectBottom.Contains(e.X, e.Y))
{
adjust
=
mPosition.bottom;
button1.Cursor
=
Cursors.SizeNS;
}
else
{
button1.Cursor
=
Cursors.Default;
}
}
private
void
button1_MouseUp(
object
sender, MouseEventArgs e)
{
if
(e.Button
==
System.Windows.Forms.MouseButtons.Left)
{
int
dx
=
e.X
-
oldx;
int
dy
=
e.Y
-
oldy;
switch
(adjust)
{
case
mPosition.left:
button1.Left
+=
dx;
button1.Width
-=
dy;
break
;
case
mPosition.right:
button1.Width
+=
dx;
break
;
case
mPosition.top:
button1.Top
+=
dy;
button1.Height
-=
dy;
break
;
case
mPosition.bottom:
button1.Height
+=
dy;
break
;
}
}
}
}
}
【Blog】
http://virusswb.cnblogs.com/
【MSN】
jorden008@hotmail.com
【说明】转载请标明出处,谢谢
反馈文章质量,你可以通过快速通道评论:
查看全文
相关阅读:
Windows系统环境变量path优先级测试报告
URI和URL的区别
智能引导式报错(Class file name must end with .class)
【Algorithm】冒泡排序
【C语言】练习2-9
【C语言】练习2-8
【C语言】练习2-1
【C语言】练习1-23
【C语言】练习1-22
【C语言】练习1-21
原文地址:https://www.cnblogs.com/virusswb/p/1175621.html
最新文章
Quartz.NET总结(四)Quartz 远程调度
Web API系列(一)设计经验与总结
ASP.NET MVC移动M站建设-使用51Degree 移动设备的识别
支持SQL Server数据库又支持MongoDB数据库的数据访问设计
在唯一密钥属性“name”设置为“ScriptHandlerFactory”时,无法添加类型为“add”的重复集合项
读书笔记3 Socket
读书笔记2:HTTP协议
读书笔记1: 资源地址—通用资源的标识符(URI)
MVC之URL路由
SqlServer中把结果集放到到临时表的方法
热门文章
一个游戏程序员的学习资料
在VS2010中,引用了同一解决方案的另一个项目的dll,却不能正常调用(转)
转载解决:错误的语法:”XXXX“必须是批处理中仅有的语句
关于java中Double类型的运算精度问题
JDK 1.6 写Webservice时,runtime modeler error: Wrapper class com.ws.jaxws.DoSomething is not found问题的解决办法
java.lang.CharSequence cannot be resolved
MyEclipse优化
成为高级程序员的 10 个步骤
Java经典问题:传值与传引用?
java.lang.SecurityException:Servlet of class org.apache.catalina.servlets.InvokerServlet is privileged
Copyright © 2011-2022 走看看