我按你的方法弄了我的窗体以后就不能从本地资源那里插入图片了,插入以后就显示不出来,是怎么回事啊 ?namespace MyQQ
{
    public partial class MainForm : Form
    {
        public LoginForm loginform;
        /// <summary>
        /// 表示鼠标按下并调整大小位置时的数据状态
        /// </summary>
        internal static class MState
        {
            private static int m_Left;
            private static int m_Top;
            private static int m_Right;
            private static int m_Bottom;
            private static int m_LastX;
            private static int m_LastY;
            private static MouseAction m_State;
            private static MouseAction m_LastState;
            /// <summary>
            /// 窗体的左坐标
            /// </summary>
            public static int Left
            {
                get { return MState.m_Left; }
            }
            /// <summary>
            /// 窗体的上坐标
            /// </summary>
            public static int Top
            {
                get { return MState.m_Top; }
            }
            /// <summary>
            /// 窗体的右坐标
            /// </summary>
            public static int Right
            {
                get { return MState.m_Right; }
            }
            /// <summary>
            /// 窗体的下坐标
            /// </summary>
            public static int Bottom
            {
                get { return MState.m_Bottom; }
            }
            /// <summary>
            /// 当前的鼠标状态
            /// </summary>
            public static MouseAction State
            {
                get { return MState.m_State; }
            }
            /// <summary>
            /// 鼠标按下时的Y坐标
            /// </summary>
            public static int LastX
            {
                get { return MState.m_LastX; }
            }
            /// <summary>
            /// 鼠标按下时的X坐标
            /// </summary>
            public static int LastY
            {
                get { return MState.m_LastY; }
            }
            /// <summary>
            /// 鼠标按下时的状态
            /// </summary>
            public static MouseAction LastState
            {
                get { return MState.m_LastState; }
            }
            /// <summary>
            /// 设置数据值
            /// </summary>
            /// <param name="bounds">窗体的大小位置</param>
            /// <param name="point">鼠标的位置</param>
            public static void SetData(Rectangle bounds, Point point)
            {
                m_Left = bounds.Left;
                m_Top = bounds.Top;
                m_Right = bounds.Right;
                m_Bottom = bounds.Bottom;
                m_LastX = point.X;
                m_LastY = point.Y;
                m_LastState = m_State;
            }
            /// <summary>
            /// 设置状态
            /// </summary>
            /// <param name="state">要设置的状态值</param>
            public static void SetState(MouseAction state)
            {
                m_State = state;
            }
            /// <summary>
            /// 重置状态
            /// </summary>
            public static void ResetState()
            {
                m_State = MouseAction.None;
                m_LastState = MouseAction.None;
            }
        }
        internal enum MouseAction
        {
            None,
            Left,
            LeftTop,
            Top,
            RightTop,
            Right,
            RightBottom,
            Bottom,
            LeftBottom
        }        [DllImport("user32.dll", EntryPoint = "GetWindowLong", CharSet = CharSet.Auto)]
        public static extern int GetWindowLong(HandleRef hWnd, int nIndex);
        [DllImport("user32.dll", EntryPoint = "SetWindowLong", CharSet = CharSet.Auto)]
        public static extern IntPtr SetWindowLong(HandleRef hWnd, int nIndex, int dwNewLong);        internal static int WM_NCHITTEST = 0x84; //移动鼠标,按住或释放鼠标时发生的系统消息
        internal static IntPtr HTCLIENT = (IntPtr)0x1;//工作区
        internal static IntPtr HTSYSMENU = (IntPtr)3;//系统菜单
        internal static IntPtr HTCAPTION = (IntPtr)0x2; //标题栏        private int m_BorderWidth = 4;
        private int m_CaptionHeight = 22;
        public MainForm()
        {
            this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw, true);
            InitializeComponent();
        }
        /// <summary>
        /// 重写以处理模拟鼠标系统处理
        /// </summary>
        /// <param name="m"></param>
        protected override void WndProc(ref Message m)
        {
            if (m.Msg == WM_NCHITTEST)
            {
                base.WndProc(ref m);
                if (DesignMode)
                {
                    return;
                }
                if (m.Result == HTCLIENT)
                {
                    m.HWnd = this.Handle;                    Rectangle rect = this.Bounds;
                    Point cp = Cursor.Position;
                    if (cp.Y > rect.Top + m_BorderWidth && cp.Y <= rect.Top + m_CaptionHeight + m_BorderWidth && cp.X > rect.Left + m_BorderWidth && cp.X < rect.Right - m_BorderWidth)
                    {
                        if ((cp.X <= rect.Left + m_BorderWidth + m_CaptionHeight))
                        {
                            m.Result = HTSYSMENU;//模拟系统菜单,双击可以关闭窗体
                        }
                        else
                        {
                            m.Result = HTCAPTION;//模拟标题栏,移动或双击可以最大或最小化窗体
                        }
                    }
                }
                return;
            }
            base.WndProc(ref m);
        }
        protected override void CreateHandle()
        {
            base.CreateHandle();
            int WS_SYSMENU = 0x00080000;
            SetWindowLong(new HandleRef(this, this.Handle), -16, GetWindowLong(new HandleRef(this, this.Handle), -16) | WS_SYSMENU);        }

解决方案 »

  1.   


            /// <summary>
            /// 重写以处理鼠标按钮准备调整窗体大小
            /// </summary>
            /// <param name="e"></param>
            protected override void OnMouseDown(MouseEventArgs e)
            {
                base.OnMouseDown(e);
                MState.SetData(this.Bounds, Cursor.Position);
            }
            /// <summary>
            /// 重写以处理鼠标抬起事件重置状态
            /// </summary>
            /// <param name="e"></param>
            protected override void OnMouseUp(MouseEventArgs e)
            {
                base.OnMouseUp(e);
                MState.ResetState();
            }
            /// <summary>
            /// 重写以处理鼠标移动调整窗体大小位置
            /// </summary>
            /// <param name="e"></param>
            protected override void OnMouseMove(MouseEventArgs e)
            {
                base.OnMouseMove(e);
                if (!this.Capture)
                {
                    MState.SetState(this.setMouse(e.Location));
                    return;
                }            int dx = 0;
                int dy = 0;
                int dr = 0;
                int db = 0;
                Point cp = Cursor.Position;
                if (MState.LastState == MouseAction.Left)//左
                {
                    dx = cp.X - MState.LastX;
                }
                else if (MState.LastState == MouseAction.Right)//右
                {
                    dr = cp.X - MState.LastX;
                }
                else if (MState.LastState == MouseAction.Top)//上
                {
                    dy = cp.Y - MState.LastY;
                }
                else if (MState.LastState == MouseAction.Bottom)//下
                {
                    db = cp.Y - MState.LastY;
                }
                else if (MState.LastState == MouseAction.LeftTop)
                {
                    dx = cp.X - MState.LastX;
                    dy = cp.Y - MState.LastY;
                }
                else if (MState.LastState == MouseAction.RightTop)
                {
                    dr = cp.X - MState.LastX;
                    dy = cp.Y - MState.LastY;
                }
                else if (MState.LastState == MouseAction.LeftBottom)
                {
                    dx = cp.X - MState.LastX;
                    db = cp.Y - MState.LastY;
                }
                else if (MState.LastState == MouseAction.RightBottom)
                {
                    dr = cp.X - MState.LastX;
                    db = cp.Y - MState.LastY;
                }
                this.Bounds = Rectangle.FromLTRB(MState.Left + dx, MState.Top + dy, MState.Right + dr, MState.Bottom + db);
                this.Invalidate();
            }
            /// <summary>
            /// 重写以处理重置鼠标光标信息
            /// </summary>
            /// <param name="e"></param>
            protected override void OnMouseLeave(EventArgs e)
            {
                base.OnMouseLeave(e);
                if (this.Bounds.Contains(Cursor.Position))
                {
                    this.Cursor = Cursors.Default;
                }
            }
            /// <summary>
            /// 由指定点设置鼠标动作
            /// </summary>
            /// <param name="point"></param>
            /// <returns></returns>
            private MouseAction setMouse(Point point)
            {
                Rectangle rect = this.ClientRectangle;            if ((point.X <= rect.Left + m_BorderWidth) && (point.Y <= rect.Top + m_BorderWidth))
                {
                    //左上
                    this.Cursor = Cursors.SizeNWSE;
                    return MouseAction.LeftTop;
                }
                else if ((point.X >= rect.Left + rect.Width - m_BorderWidth) && (point.Y <= rect.Top + m_BorderWidth))
                {
                    //右上
                    this.Cursor = Cursors.SizeNESW;
                    return MouseAction.RightTop;
                }
                else if ((point.X <= rect.Left + m_BorderWidth) && (point.Y >= rect.Top + rect.Height - m_BorderWidth))
                {
                    //左下
                    this.Cursor = Cursors.SizeNESW;
                                return MouseAction.LeftBottom;
                }
                else if ((point.X >= rect.Left + rect.Width - m_BorderWidth) && (point.Y >= rect.Top + rect.Height - m_BorderWidth))
                {
                    //右下
                    this.Cursor = Cursors.SizeNWSE;
                    return MouseAction.RightBottom;
    }
                else if ((point.X <= rect.Left + m_BorderWidth - 1))
                {
                    //左
                    this.Cursor = Cursors.SizeWE;
                    return MouseAction.Left;
                }
                else if ((point.X >= rect.Left + rect.Width - m_BorderWidth))
                {
                    //右
                    this.Cursor = Cursors.SizeWE;
                    return MouseAction.Right;
                }
                else if ((point.Y <= rect.Top + m_BorderWidth - 1))
                {
                    //上
                    this.Cursor = Cursors.SizeNS;
                    return MouseAction.Top;
                }
                else if ((point.Y >= rect.Top + rect.Height - m_BorderWidth))
                {
                    //下
                    this.Cursor = Cursors.SizeNS;
                    return MouseAction.Bottom;
                }
                this.Cursor = Cursors.Default;
                return MouseAction.None;
            }
      

  2.   

    ?在你的窗体上加上下面的两段代码:protected override void OnPaintBackground(PaintEventArgs e)
    {
    //base.OnPaintBackground(e);
    }
    protected override void OnPaint(PaintEventArgs e)
    {
    base.OnPaint(e);
    if (this.BackgroundImage != null)
    {
    e.Graphics.DrawImage(this.BackgroundImage, e.ClipRectangle, e.ClipRectangle, GraphicsUnit.Pixel);
    }
    }
      

  3.   

    我把            this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw, true); 
    这句话删了可以吗