鼠标形状已经改变了符合要求,但是窗体大小怎么控制呢?半天也没整出来:(
代码如下:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace WindowsApplication5
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private CusLabel label1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
这样的话,只能重写一个panel的控件来实现,因为这时panel是当前接爱鼠标事件,当然你可以做成当panel有鼠标事件时让窗体得到,但是重写一个panel控件有时可能更有意思,我没有重写panel,但我重写了一个button的,代码我想只是它们继承的基类不一样罢了:代码大致如下:
using System;
using System.Windows.Forms;
using System.Drawing;
namespace MoveControlLocation
{
/// <summary>
///
/// </summary>
public class CusLabel: System.Windows.Forms.Button
{
public CusLabel()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
private const int WM_NCHITTEST = 0x84;
private const int WM_SIZING = 532;
private const int HTERROR = (-2);
private const int HTTRANSPARENT = (-1);
private const int HTNOWHERE = 0;
private const int HTCLIENT = 1;
private const int HTCAPTION = 2;
private const int HTSYSMENU = 3;
private const int HTGROWBOX = 4;
private const int HTSIZE = HTGROWBOX;
private const int HTMENU = 5;
private const int HTHSCROLL = 6;
private const int HTVSCROLL = 7;
private const int HTMINBUTTON = 8;
private const int HTMAXBUTTON = 9;
private const int HTLEFT = 10;
private const int HTRIGHT = 11;
private const int HTTOP = 12;
private const int HTTOPLEFT = 13;
private const int HTTOPRIGHT = 14;
private const int HTBOTTOM = 15;
private const int HTBOTTOMLEFT = 16;
private const int HTBOTTOMRIGHT = 17;
private const int HTBORDER = 18;
private const int HTREDUCE = HTMINBUTTON;
private const int HTZOOM = HTMAXBUTTON;
private const int HTSIZEFIRST = HTLEFT;
private const int HTSIZELAST = HTBOTTOMRIGHT;
/* WINVER >= 0x0400 */
private const int HTOBJECT = 19;
private const int HTCLOSE = 20;
private const int HTHELP = 21;
/* WINVER >= 0x0400 */
private const int BorderWidth = 3;
private int CaptionHeight = 17;
//可以调整窗体的大小和移动窗体的位置
protected override void WndProc(ref System.Windows.Forms.Message m)
{
switch(m.Msg)
{
case WM_NCHITTEST:
base.WndProc(ref m);
if (DesignMode)
{
return;
}
if ((int)m.Result == HTCLIENT)
{
m.HWnd = this.Handle;
int pLeft=0;
int pTop=0;
bool IsControl = true;
if (IsControl)
{
if ((this.Parent as Form).FormBorderStyle==FormBorderStyle.None)
{
pLeft=this.Parent.Left;
pTop=this.Parent.Top;
}
else
{
pLeft=this.Parent.Left+2;
CaptionHeight = this.Parent.Height-this.Parent.ClientRectangle.Height-2 * BorderWidth;
pTop=this.Parent.Top + CaptionHeight + BorderWidth-2;
}
}