中国IT动力,最新最全的IT技术教程
最新100篇 | 推荐100篇 | 专题100篇 | 排行榜 | 搜索 | 在线API文档 | 网通镜像
首 页 | 程序开发 | 操作系统 | 软件应用 | 图形图象 | 网络应用 | 精文荟萃 | 教育认证 | 硬件维护 | 未整理篇 | 站长教程
ASP JS PHP工程 ASP.NET 网站建设 UML J2EESUN .NET VC VB VFP 网络维护 数据库 DB2 SQL2000 Oracle Mysql
服务器 Win2000 Office C DreamWeaver FireWorks Flash PhotoShop 上网宝典 CorelDraw 协议大全 网络安全 微软认证
硬件维护  CPU  主板  硬盘  内存  显卡  显示器  键盘鼠标  声卡音箱  打印机  机箱电源  BIOS  网卡  C#  Java  Delphi  vs.net2005
  当前位置:> 程序开发 > 编程语言 > .NET > 临时文章
手柄控件
作者:未知 时间:2004-12-09 12:12 出处:Blog 责编:chinaitpower
              摘要:暂无

在StatusBar上有一个可以拖动窗体大小的手柄,鼠标在其上拖动时就可以调整当前窗体的大小,如何自己来仿制一个呢,我作了一个小控件就可以实现了,只是效果上相似,至于系统里到底是怎么来实现的,我是不知道的了,下面是控件的代码,没有写注释,因为怕有人笑我,呵呵,其实简单的不用写注释了:

using System;
using System.Drawing;
using System.Windows.Forms;

namespace Size_MoveCtr
{
 /// <summary>
 /// Mover 的摘要说明。
 /// </summary>
 public class SizeGrip: System.Windows.Forms.Control
 {
  private const int WM_NCHITTEST = 0x84;
  private const int WM_NCLBUTTONDOWN = 0xa1;

  private const int HTCLIENT =  1;
  private const int HTBOTTOMRIGHT = 17;
 
  private System.Drawing.Drawing2D.GraphicsPath m_Path;

  [System.Runtime.InteropServices.DllImport("user32.dll")]
  public static extern int SendMessage( IntPtr hWnd,
   int Msg,
   IntPtr wParam,
   IntPtr lParam
   );

  public SizeGrip()
  {
   this.m_Path = new System.Drawing.Drawing2D.GraphicsPath();

   this.m_Path.StartFigure();
   this.m_Path.AddLines(new Point[]{new Point(this.Width, 0),new Point(this.Width-this.Height, this.Height), new Point(this.Width, this.Height)});
   this.m_Path.CloseFigure();
  }

  protected override void OnPaint(PaintEventArgs e)
  {
   base.OnPaint (e);
   ControlPaint.DrawSizeGrip(this.CreateGraphics(), System.Drawing.SystemColors.Control, this.Width-this.Height, 0, this.Height, this.Height);

  }

  protected override void OnSizeChanged(EventArgs e)
  {
   System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
   path.StartFigure();
   path.AddLines(new Point[]{new Point(this.Width, 0),new Point(this.Width-this.Height, this.Height), new Point(this.Width, this.Height)});
   path.CloseFigure();

   Region reReg = new Region(path);
   reReg.Complement(m_Path);

   this.Invalidate(reReg);

   base.OnSizeChanged(e);
   this.m_Path = path;

   ControlPaint.DrawSizeGrip(this.CreateGraphics(), System.Drawing.SystemColors.Control, this.Width-this.Height, 0, this.Height, this.Height);
  }

  protected override void WndProc(ref Message m)
  {
   if (this.DesignMode)
   {
    base.WndProc(ref m);
    return;
   }

   switch (m.Msg)
   {
    case WM_NCHITTEST:
     SendMessage(this.Parent.Handle, m.Msg, m.WParam, m.LParam);
     base.WndProc(ref m);
     if ((int)m.Result == HTCLIENT)
     {
      m.Result = (IntPtr)HTBOTTOMRIGHT;//右下
     }
     break;
    case WM_NCLBUTTONDOWN:
     SendMessage(this.Parent.Handle, m.Msg, m.WParam, m.LParam);
     break;
    default:
     base.WndProc(ref m);
     break;
   }
  }
 }
}

关闭本页
 
首页 | 投资与合作 | 服务条款 | 隐私政策 | 收藏本站 | 设为首页 | 新用户注册 | 免责声明 | 使用帮助
Copyright ©2005-2008 chinaitpower.com All rights reserved. www.chinaitpower.com 版权所有