当前位置:编程学习 > C#/ASP.NET >>

C#重绘窗体

有没有好点的窗体代码?
或好点的方法,谢谢
补充:重绘整个窗体,窗体的标题栏上的最小化,最大化、关闭按钮等,

能够根据不同的图片绘制不 同的 外观。

呵呵,分不多,讲究一下,简单点的绘制自己会点 ,复杂的就不知道如何下手了 。

希望能提供一下解决问题的思路或办法 谢谢

答案:不知道你要哪一种重绘的代码,圆角矩形窗体的要吗?

重绘后可托动窗体,能实现窗体的立体效果,这是整个重载Form的类,就发给你了吧。。

 

 

public partial class form : Form
    {
       
        public form()
        {
            InitializeComponent();
            SetStyle(
                ControlStyles.UserPaint |
                ControlStyles.AllPaintingInWmPaint |
                ControlStyles.OptimizedDoubleBuffer |
                ControlStyles.ResizeRedraw |
                ControlStyles.SupportsTransparentBackColor, true);
            this.BackColor = Color.Transparent;
            this.FormBorderStyle = FormBorderStyle.None;
        }
       Color baseColor= Color.FromArgb(51, 161, 224);
       private Point mypoint;

       protected override void OnMouseDown(MouseEventArgs e)  //可以手动托动
       {
           mypoint = new Point(-e.X, -e.Y);
           base.OnMouseDown(e);
       }
       protected override void OnMouseMove(MouseEventArgs e)
       {
           if (e.Button == MouseButtons.Left)
           {
               Point mypoint2 = Control.MousePosition;
               mypoint2.Offset(mypoint);
               this.DesktopLocation = mypoint2;
           }
           base.OnMouseMove(e);
       }
        protected override void OnPaint(PaintEventArgs e)   //主要重绘在这里体现
        {
            Graphics g = e.Graphics;
            Brush brush = Brushes.YellowGreen;
            GraphicsPath path = CreatePath(new Rectangle(0, 0, 200, 200), 10);
            this.Region = new Region(path);
            g.DrawPath(new Pen(Brushes.YellowGreen), path);

            //以下这段用来实现窗体有立体感
            LinearGradientBrush brus = new LinearGradientBrush(ClientRectangle, Color.Transparent, Color.Transparent, LinearGradientMode.Vertical);
            Color[] colors = new Color[4];
            colors[0] = GetColor(baseColor, 0, 35, 24, 9);
            colors[1] = GetColor(baseColor, 0, 13, 8, 3);
            colors[2] = baseColor;
            colors[3] = GetColor(baseColor, 0, 68, 69, 54);
            ColorBlend blend = new ColorBlend();
            blend.Colors = colors;
            blend.Positions = new float[] { 0.0f, 0.3f, 0.35f, 1.0f };
            brus.InterpolationColors = blend;
            g.FillPath(brus, path);
           
            base.OnPaint(e);
        }
        private Color GetColor(Color colorBase, int a, int r, int g, int b)
        {
            int a0 = colorBase.A;
            int r0 = colorBase.R;
            int g0 = colorBase.G;
            int b0 = colorBase.B;

            if (a + a0 > 255) { a = 255; } else { a = Math.Max(a + a0, 0); }
            if (r + r0 > 255) { r = 255; } else { r = Math.Max(r + r0, 0); }
            if (g + g0 > 255) { g = 255; } else { g = Math.Max(g + g0, 0); }
            if (b + b0 > 255) { b = 255; } else { b = Math.Max(b + b0, 0); }

            return Color.FromArgb(a, r, g, b);
        }
        public static GraphicsPath CreatePath(    //这里是创建一个圆角矩形窗体
           Rectangle rect, int radius
         
            )
        {
            GraphicsPath path = new GraphicsPath();
            int radiusCorrection = 1;// correction ? 1 : 0;

            path.AddArc(rect.X, rect.Y, radius, radius, 180, 90);
            path.AddArc(
                rect.Right - radius - radiusCorrection,
                rect.Y,
                radius,
                radius,
                270,
                90);
            path.AddArc(
  

上一个:C#截图源代码
下一个:c# dataGridView联动输入

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,