请问一下这个panel的边框是怎么设置的?

解决方案 »

  1.   

    如果确有虚线,自己画的,OnPaint中画个巨型,极其简单
      

  2.   

    没有外面那个虚线,那个事截图的效果
    只是里面的那个panel的白色的那个边框
      

  3.   


    ControlPaint.DrawBorder(e.Graphics, panel.ClientRectangle,Color.Gray,3,
                             ButtonBorderStyle.Solid,Color.Gray,3,
                             ButtonBorderStyle.Solid,Color.Gray,3,
                             ButtonBorderStyle.Solid,Color.Gray,3,
                             ButtonBorderStyle.Solid);
    你是说这样么?
    可是达不到那种有点立体的边框效果啊
      

  4.   


    // 楼主需要一件事情,那就是:任何控件所呈现的外观都是画出来的。
    // 所以,边框当然也是画出来的。
    // 楼主可以自己写一个 Class,继承自 Control 类,然后重写 OnPaint 事件。
    // 建议在 base.OnPaint(e) 之后写自己的 Custom 代码。protected override void OnPaint(PaintEventArgs e)
    {
        base.OnPaint(e);
        // your code
    }// 楼主的图看的不是很清楚,根据自己的分析,下面画出来的这个效果应该可以满足楼主的需要。
    protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
    {
        base.OnPaint(e);    Color color1 = Color.FromArgb(173, 170, 173);
        Color color2 = Color.White;    int border1 = 1;
        int border2 = 2;    Rectangle rect1 = new Rectangle(0, 0, ClientSize.Width - 3, ClientSize.Height - 3);
        Rectangle rect2 = new Rectangle(0, 0, ClientSize.Width - 1, ClientSize.Height - 1);    using (var pen1 = new Pen(color1))
        using (var pen2 = new Pen(color2, 2.0F) { Alignment = PenAlignment.Inset })
        {
            e.Graphics.DrawRectangle(pen2, rect2);
            e.Graphics.DrawRectangle(pen1, rect1);
        }
    }
      

  5.   


    恩,楼上的看起来应该可以满足我的需求,不过我还没有试过。我刚刚这样子基本上实现了我的要求 private void panel1_Paint(object sender, PaintEventArgs e)
            {
                Panel pnl = (Panel)sender;
                var BorderWidth = 2;            //BevelOuter (bvLowered)   
                e.Graphics.DrawLine(new Pen(SystemColors.ControlDark), 0, 0, 0, pnl.Height - 0);
                e.Graphics.DrawLine(new Pen(SystemColors.ControlDark), 0, 0, pnl.Width - 0, 0);
                e.Graphics.DrawLine(new Pen(SystemColors.ControlLightLight), pnl.Width - 1, pnl.Height - 1, 0, pnl.Height - 1);
                e.Graphics.DrawLine(new Pen(SystemColors.ControlLightLight), pnl.Width - 1, pnl.Height - 1, pnl.Width - 1, 0);            if (BorderWidth > 0)
                {
                    //BevelInner (bvRaised)   
                    e.Graphics.DrawLine(new Pen(SystemColors.ControlLightLight), BorderWidth, BorderWidth, BorderWidth, pnl.Height - BorderWidth);
                    e.Graphics.DrawLine(new Pen(SystemColors.ControlLightLight), BorderWidth, BorderWidth, pnl.Width - BorderWidth, BorderWidth);
                    e.Graphics.DrawLine(new Pen(SystemColors.ControlDark), pnl.Width - (BorderWidth + 1), pnl.Height - (BorderWidth + 1), BorderWidth, pnl.Height - (BorderWidth + 1));
                    e.Graphics.DrawLine(new Pen(SystemColors.ControlDark), pnl.Width - (BorderWidth + 1), pnl.Height - (BorderWidth + 1), pnl.Width - (BorderWidth + 1), BorderWidth);
                }   
    }