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 phone 中使用原生代码开发程序(native code)
C# 操作系统防火墙转载
WP7Windows Phone的Isolated Storage Explorer使用指南
如何让wp7真机调试时候保持屏幕高亮不锁屏
利用C#检测证书是否存在,并安装证书
WPF设置附加属性的值
wpf值转换器IValueConverter转载
ADO.NET一些内幕
怎样将数据库中所有表中含有numeric(18,2)字段改成numeric(18,10)及将float改成numeric
原文地址:https://www.cnblogs.com/virusswb/p/1175621.html
最新文章
用鸡蛋和蜡烛自制水晶灯
在sqlinsert中使用自定义的存储过程
分布式编程必须知道的几个基本概念
Perl诗歌
Widget
J2ME内存占用详解及优化方法
朋友你好~
J2ME游戏帧数和屏幕刷新控制
9招教你防止电脑辐射
查看80端口被占用
热门文章
SQL的数据类型
php 检查电子邮件函数
mysql 添加字段
关于mysql 自动更新时间的 类型说明
万恶的英语
sql server 2008 时间操作函数
php的时间
sql server datetime和字符串转化
AppDomain与Assembly的加载与卸载
C#实现一个简单的HTTP服务器
Copyright © 2011-2022 走看看