我想在PictureBox的MouseMove事件中改变PictureBox的边框颜色,怎么弄?
PictureBox  FixedSingle

解决方案 »

  1.   

    没法改的,搂住需要把边界设置为None,然后自己在Paint事件中绘制边框
    然后在鼠标移动过程中,调用Invalidate方法不断重绘即可。
      

  2.   

    结合样式调整。 STYLE  赋予你的样式,或许可以。
      

  3.   

    帮搂主写了一个,鼠标移动过程中,随机改变颜色和边界宽度的代码:private Random m_Random = new Random();
    private Color m_BorderColor = Color.DodgerBlue;
    private int m_BorderWidth = 1;private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
    {
        //随机颜色
        int A = this.m_Random.Next(0, 255);
        int R = this.m_Random.Next(0, 255);
        int G = this.m_Random.Next(0, 255);
        int B = this.m_Random.Next(0, 255);
        this.m_BorderColor = Color.FromArgb(A, R, G, B);    //随机宽度
        this.m_BorderWidth = this.m_Random.Next(1, 5);    //刷新边界
        this.pictureBox1.Invalidate();
    }private void pictureBox1_Paint(object sender, PaintEventArgs e)
    {
        Pen pen = new Pen(this.m_BorderColor);
        pen.Width = this.m_BorderWidth;
        e.Graphics.DrawRectangle(pen, 0, 0
            , this.pictureBox1.Width - this.m_BorderWidth
            , this.pictureBox1.Height - this.m_BorderWidth);
    }
      

  4.   

    this.m_BorderColor = Color.FromArgb(A, R, G, B); 
      

  5.   

    这个是自己定义的,上面代码中也有这个定义的搂主可以直接Copy代码,后添加好代码中的两个MouseMove和Paint事件,可以直接看看效果