向右拉伸的例子:
private int x0, y0;
private Point localtion;
private void button1_MouseMove(object sender, MouseEventArgs e)
{
int i =button1.Width-e.X;
if (i > 0 && i < 5)
{
this.Cursor = Cursors.SizeWE;
}
}
private void button1_MouseDown(object sender, MouseEventArgs e)
{
int i = button1.Width - e.X;
if (i > 0 && i < 5)
{
BeganDrag = true;
localtion = new Point(button1.Location.X, button1.Location.Y);
x0 = e.X;
y0 = e.Y;
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using Sinxsoft.NotePrinter.Forms.Design;
namespace Sinxsoft.NotePrinter
{
public class ControlMove
{
#region private定义
private const int MIN_SIZE = 10; //对控缩放的最小值
private const int BOX_SIZE = 7; //调整大小触模柄方框大小
public bool _IsCtrlKey = false;
private TextBox _textbox;
private Control _MControl = null;
private bool _IsMouseDown = false;
private Point _oPointClicked;
private Color BOX_COLOR = Color.White;
private Label[] _lbl = new Label[8];
private int _startl, _startt, _startw, _starth;
private bool _dragging;
private Cursor[] _arrArrow =
new Cursor[] {Cursors.SizeNWSE, Cursors.SizeNS,
Cursors.SizeNESW, Cursors.SizeWE, Cursors.SizeNWSE, Cursors.SizeNS,
Cursors.SizeNESW, Cursors.SizeWE};
private NoteDoc _noteDoc = null;
#endregion
#region 构造函数
/**/
/// <summary>
/// 构造控件拖动对象
/// </summary>
/// <param name="moveControl">需要拖动的控件</param>
public ControlMove(Control moveControl)
{
//
// TODO: 在此处添加构造函数逻辑
//
_MControl = moveControl;
_MControl.MouseDown += new MouseEventHandler(this.Control_MouseDown);
_MControl.MouseUp += new MouseEventHandler(this.Control_MouseUp);
_MControl.MouseMove += new MouseEventHandler(this.Control_MouseMove);
_MControl.Click += new System.EventHandler(this.Control_Click);
//构造8个调整大小触模柄
for (int i = 0; i < 8; i++)
{
_lbl[i] = new Label();
_lbl[i].TabIndex = i;
_lbl[i].FlatStyle = 0;
_lbl[i].BorderStyle = BorderStyle.FixedSingle;
_lbl[i].BackColor = BOX_COLOR;
_lbl[i].Cursor = _arrArrow[i];
_lbl[i].Text = "";
_lbl[i].BringToFront();
_lbl[i].MouseDown += new MouseEventHandler(this.handle_MouseDown);
_lbl[i].MouseMove += new MouseEventHandler(this.handle_MouseMove);
_lbl[i].MouseUp += new MouseEventHandler(this.handle_MouseUp);
}
if (e.KeyValue == 46)
{
for (int i = 0; i < 8; i++)
{
_MControl.Parent.Controls.Remove(_lbl[i]);
}
_MControl.Parent.Controls.Remove(_MControl);
_textbox.Parent.Controls.Remove(_textbox);
}