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
【说明】转载请标明出处,谢谢
反馈文章质量,你可以通过快速通道评论:
查看全文
相关阅读:
UnitTest测试套件及运行器
DDT实现数据驱动
MySQL练习题部分答案(未完待续)
day58自我回顾版
Linux 下安装pip
wget用法汇总
Linux基础操作整理
pip安装django失败
利用"SQL"语句自动生成序号的两种方式
Python2.*与Python3.*共存问题
原文地址:https://www.cnblogs.com/virusswb/p/1175621.html
最新文章
单元测试-unittest
yaml
向excel中循环插入值
重写父类、多线程、多进程、logging模块
面向对象
自动发送邮箱
python基础-requests模块、异常处理、Django部署、内置函数、网络编程
Python ----pip安装模块提示“unknown or unsupported command install”的解决办法
解决Eclipse中文乱码
模块四 Bash编程语法
热门文章
模块三 linux三剑客与管道使用
20210121 直播课 python脚本编写
模块二linux常用命令
模块一 linux系统与shell环境准备
模块七 python输入与输出
模块八 python的错误与异常
模块九 面向对象编程
模块十二 python常用的第三方库
模块十一 python多线程处理
PO模式设计
Copyright © 2011-2022 走看看