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
【说明】转载请标明出处,谢谢
反馈文章质量,你可以通过快速通道评论:
查看全文
相关阅读:
POJ 2251 Dungeon Master(BFS)
POJ 1321 棋盘问题 (DFS + 回溯)
POJ 3009 Curling 2.0(DFS + 模拟)
Codeforces 702D Road to Post Office(模拟 + 公式推导)
Codeforces 702A Maximum Increase(dp)
Codeforces 702C Cellular Network(二分)
Codeforces 702B Powers of Two
POJ 3083 Children of the Candy Corn (DFS + BFS + 模拟)
POJ 2488 A Knight's Journey (回溯法 | DFS)
POJ1094 Sorting It All Out (拓扑排序)
原文地址:https://www.cnblogs.com/virusswb/p/1175621.html
最新文章
socket网络(二)
socket网络
面向对象(二)
将ip加入到防火墙
ls -bash: ls: command not found
基于Centos7安装Docker-registry2.0
Centos7安装Docker1.9.1
安装phpldapadmin
OpenLDAP on Centos7
zabbix-agent安装
热门文章
tar
mv
cp
rm
计算机英语词汇331
ssh
MobaXterm
Daily record-July
多文件编译,全局变量
Debug method
Copyright © 2011-2022 走看看