簡體   English   中英

WFA 進度條 背景顏色或紋理(不是前景)

[英]WFA Progress bar Background color or texture (not foreground)

這個解決方案找了很久了

我想,我的小圖可以說明一切:

http://screenshot.cz/WT5KO/progbar.png

現在,我正在使用此代碼繪制自定義欄,您可以在上面看到。 是否可以將后台編輯代碼組合到我的構造函數代碼中?

 public class NewProgressBar : ProgressBar
{
    public NewProgressBar()
    {
        this.SetStyle(ControlStyles.UserPaint, true);

    }

    protected override void OnPaintBackground(PaintEventArgs pevent)
    {
        // None... Helps control the flicker.
    }

    protected override void OnPaint(PaintEventArgs e)
    {
        const int inset = 0; // A single inset value to control teh sizing of the inner rect.

        using (Image offscreenImage = new Bitmap(this.Width, this.Height))
        {
            using (Graphics offscreen = Graphics.FromImage(offscreenImage))
            {


                Rectangle rect = new Rectangle(0, 0, this.Width, this.Height);


                if (ProgressBarRenderer.IsSupported)
                    ProgressBarRenderer.DrawHorizontalBar(offscreen, rect);

                rect.Inflate(new Size(-inset, -inset)); // Deflate inner rect.
                rect.Width = (int)(rect.Width * ((double)this.Value / this.Maximum));
                if (rect.Width == 0) rect.Width = 1; // Can't draw rec with width of 0.
                TextureBrush mybrush = new TextureBrush(Properties.Resources.loading);
                LinearGradientBrush brush = new LinearGradientBrush(rect, Color.DarkGoldenrod, Color.Gold, LinearGradientMode.Vertical);
                offscreen.FillRectangle(mybrush, inset, inset, rect.Width, rect.Height);

                e.Graphics.DrawImage(offscreenImage, 0, 0);
                offscreenImage.Dispose();
            }
        }
    }
}

我在 .NET 4.5 下使用 WFA 模板

提前致謝

您在自定義進度條上使用視覺進度條樣式,因為您在課堂上將控件聲明為進度條。

public class NewProgressBar : ProgressBar

如果您想自己制作,請將您的自定義控件類聲明切換為 Control

public class NewProgressBar : Control

那么您將能夠使用 BackColor 但您需要自己編寫“值、最小值/最大值”以使該進度條正常工作

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM