从usercontrol继承的
楼上的说得没错,就是这个意思。
我现在遇到的主要问题是在拖动时如何绘制窗体轮廓,具体是不知道如何获取全屏绘画(而不是仅仅在窗体客户区)的graphics对象,以及绘制方法:第一次绘画显示线条,第二次在原位同样绘制就是擦除刚绘制的图象,而对背景没有影响,这个我不知道用什么pen或者brush。

解决方案 »

  1.   

    楼主是要这个效果吗?
    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;namespace WindowsApplication1
    {
    /// <summary>
    /// Form1 的摘要说明。
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
    /// <summary>
    /// 必需的设计器变量。
    /// </summary>
    private System.ComponentModel.Container components = null; [System.Runtime.InteropServices.DllImport("user32.dll")]
    public static extern bool ReleaseCapture();
    [System.Runtime.InteropServices.DllImport("user32.dll")]
    public static extern bool SendMessage(IntPtr hwnd,int wMsg,int wParam,int lParam);  
    public const int WM_SYSCOMMAND=0x0112;
    public const int SC_MOVE=0xF010;
    private System.Windows.Forms.Label label1;
    public const int HTCAPTION=0x0002;
    public Form1()
    {
    //
    // Windows 窗体设计器支持所必需的
    //
    InitializeComponent(); //
    // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
    //
    } /// <summary>
    /// 清理所有正在使用的资源。
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if (components != null) 
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    } #region Windows 窗体设计器生成的代码
    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {
    this.label1 = new System.Windows.Forms.Label();
    this.SuspendLayout();
    // 
    // label1
    // 
    this.label1.BackColor = System.Drawing.SystemColors.Desktop;
    this.label1.Location = new System.Drawing.Point(48, 72);
    this.label1.Name = "label1";
    this.label1.Size = new System.Drawing.Size(152, 23);
    this.label1.TabIndex = 0;
    this.label1.Text = "label1";
    this.label1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.label1_MouseDown);
    // 
    // Form1
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
    this.ClientSize = new System.Drawing.Size(292, 273);
    this.Controls.Add(this.label1);
    this.Name = "Form1";
    this.Text = "Form1";
    this.ResumeLayout(false); }
    #endregion /// <summary>
    /// 应用程序的主入口点。
    /// </summary>
    [STAThread]
    static void Main() 
    {
    Application.Run(new Form1());
    } private void label1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
    {

    ReleaseCapture();
    SendMessage(this.Handle,WM_SYSCOMMAND,SC_MOVE+HTCAPTION, 0);
    }
    }
    }
      

  2.   

    是的,效果差不多,你的实现是通过发送系统消息,但只是实现了移动,要实现RESIZE是不是会复杂些?也可以用类似的方法实现吗?恳请大侠不吝赐教!
      

  3.   

    http://dev.csdn.net/develop/article/49/49700.shtm自己改改  估计差不多 。
      

  4.   

    我还是需要自己绘制轮廓,因为需要在拖动的过程中根据所遇到的对象不同而改变轮廓的形状,就象VS.NET IDE中的属性、类浏览器等窗体,在拖动时遇到边缘或者同类窗体,它的轮廓会即时变化。