如题

解决方案 »

  1.   

    很简单吧!!把双击事件弄出来,里面写不会出现错误,有不会执行的东西 就OK了,比如写一个不可能的判断句,赋值i=0判断在i==1时出提示框
      

  2.   


    把你窗体的FormBorderStyle改为FixedDialog试试
      

  3.   

    关键在于为什么双击之后你的窗体会移动,默认情况下它会移动吗,这是一个需要额外处理的行为。如果你指的是双击标题栏后窗体会放大的话,去掉标题栏就是了:form.FormBorderStyle=FormBorderStyle.None;
      

  4.   

    把窗体的MaxinizeBox和MixinizeBox设为false
      

  5.   

    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;
    using System.Drawing.Imaging;
    namespace CustomForm
    {
    /// <summary>
    /// Form1 的摘要说明。
    /// </summary>
    public class CustomForm : System.Windows.Forms.Form
    {
    public CustomForm()
    {
    InitializeComponent();
    } Image backBitmap=null;
    Form frm2=new Form();
    bool isMove=true;
    private const int WM_NCHITTEST = 0x84; 
    private const int HTCLIENT = 0x1; 
    private const int HTCAPTION = 0x2; 
    public override Image BackgroundImage
    {
    get
    {
    return backBitmap;
    }
    set
    {
    backBitmap=value;
    SetBackground(this.backBitmap);
    this.Width=value.Width;
    this.Height=value.Height;
    }
    } protected override void WndProc(ref Message m) 

    switch(m.Msg) 

    case WM_NCHITTEST: 
    base.WndProc(ref m); 
    if ((int)m.Result == HTCLIENT&&isMove) 
    m.Result = (IntPtr)HTCAPTION; 
    return; 
    break; 

    base.WndProc(ref m); 
    }  public bool IsMoveForm
    {
    get
    {
    return isMove;
    }
    set
    {
    isMove=value;
    }
    } private void SetBackground(Image img)
    {
    try
    {
    Bitmap bitmap = (Bitmap) img;
    if (bitmap.PixelFormat != PixelFormat.Format32bppArgb)
    {
    throw new ApplicationException("图片必须为32位图像");
    }
    IntPtr hObject = IntPtr.Zero;
    IntPtr zero = IntPtr.Zero;
    IntPtr hDC = Win32.GetDC(IntPtr.Zero);
    IntPtr ptr2 = Win32.CreateCompatibleDC(hDC);
    try
    {
    hObject = bitmap.GetHbitmap(Color.FromArgb(0));
    zero = Win32.SelectObject(ptr2, hObject);
    Win32.Size size2 = new Win32.Size(bitmap.Width, bitmap.Height);
    Win32.Size psize = size2;
    Win32.Point point3 = new Win32.Point(0, 0);
    Win32.Point pprSrc = point3;
    point3 = new Win32.Point(base.Left, base.Top);
    Win32.Point pptDst = point3;
    Win32.BLENDFUNCTION pblend = new Win32.BLENDFUNCTION();
    pblend.BlendOp = 0;
    pblend.BlendFlags = 0;
    pblend.SourceConstantAlpha = 0xff;
    pblend.AlphaFormat = 1;
    Win32.UpdateLayeredWindow(this.Handle, hDC, ref pptDst, ref psize, ptr2, ref pprSrc, 0, ref pblend, 2);
    }
    catch (Exception exception1)
    {
    Exception exception = exception1;
    throw exception;
    }
    finally
    {
    Win32.ReleaseDC(IntPtr.Zero, hDC);
    if (hObject != IntPtr.Zero)
    {
    Win32.SelectObject(ptr2, zero);
    Win32.DeleteObject(hObject);
    }
    Win32.DeleteDC(ptr2);
    }
    }
    catch (ApplicationException exception4)
    {
    ApplicationException exception2 = exception4;
    MessageBox.Show(exception2.Message, "请检测你的PNG文件");
    }
    catch (Exception exception5)
    {
    Exception exception3 = exception5;
    MessageBox.Show(exception3.Message, "无法打开PNG文件.");
    }
    } protected override System.Windows.Forms.CreateParams CreateParams
    {
    get
    {
    System.Windows.Forms.CreateParams createParams = base.CreateParams;
    createParams.ExStyle |= 0x80000;
    return createParams;
    }
    } private void CustomForm_Move(object sender, EventArgs e)
    {
                frm2.Location = this.Location;
    } private void CustomForm_Resize(object sender, EventArgs e)
    {
                frm2.SetBounds(this.Left, this.Top, this.Width, this.Height);
    } private void CustomForm_ControlAdded(object sender, ControlEventArgs e)
    {
                frm2.Controls.Add(e.Control);
    } private void InitializeComponent()
    {
    // 
    // CustomForm
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
    this.ClientSize = new System.Drawing.Size(536, 358);
    base.Move+=new EventHandler(CustomForm_Move);
    base.Resize+=new EventHandler(CustomForm_Resize);
    this.ControlAdded+=new ControlEventHandler(CustomForm_ControlAdded);
    base.FormBorderStyle=FormBorderStyle.None;
    base.ClientSize = new System.Drawing.Size(560, 446);
    //base.StartPosition=FormStartPosition.CenterScreen;

    base.ControlBox=false;
                frm2.ShowInTaskbar = false;
                frm2.TransparencyKey = Color.Red;
                frm2.BackColor = Color.Red;
                frm2.FormBorderStyle = FormBorderStyle.None;
                frm2.ControlBox = false;
                //frm2.TopMost=true;
                //this.TopMost=true;
                frm2.Owner = this;
                frm2.Opacity = this.Opacity;
                frm2.MaximizeBox = false;
                frm2.MouseDoubleClick += new MouseEventHandler(frm2_MouseDoubleClick);
                frm2.DoubleClick += new EventHandler(frm2_DoubleClick);
              
                frm2.Closing += new CancelEventHandler(frm2_Closing);
                frm2.Show(); }        void frm2_DoubleClick(object sender, EventArgs e)
            {
                throw new NotImplementedException();
            }        void frm2_MouseDoubleClick(object sender, MouseEventArgs e)
            {
                throw new NotImplementedException();
            }

    private void frm2_Closing(object sender, CancelEventArgs e)
    {
    this.Close();
    }
    }
    }
    继承的这个窗体类 楼上朋友们说的 不行 呵呵 不过还是谢谢你们
      

  6.   

    不会啊 指教 就是png透明效果 图片哪里透明窗体就哪里透明
    前辈 急啊
    我这个也是网上下的
      

  7.   

            protected override void WndProc(ref Message m)
            {
              base.WndProc(ref m);
              if(m.Msg == 0x84 && m.Result == (IntPtr)2) // 不让拖动标题栏
              {
                m.Result = (IntPtr)1;
              }
              if (m.Msg == 0xA3)                         // 双击标题栏无反应
              {
                m.WParam = System.IntPtr.Zero;
              }
            }
      

  8.   

    重寫窗體雙擊事件,直接把裏邊的的base.ondoublick()屏掉就行了
      

  9.   

    B M W 是正解!
    顶下!