2016-04-15 38 views
0

是否可以通過編程禁用Application.EnableVisualStyles();?我想關閉我的應用程序的某個部分的視覺樣式,我可以有一個彩色進度條。我知道你可以使用System.Drawing來繪製它,但如果我可以暫時關閉它,這會更加簡單。這是可能的還是我將不得不繪製它?c#WinForms - 以編程方式禁用Application.EnableVisualStyles()方法?

+0

我不這麼認爲 – Rahul

+0

我不知道你正在嘗試做的,但是這可能幫助 – GreatJobBob

+0

https://msdn.microsoft.com/en-us/library/system.windows.forms.visualstyles .visualstylestate%28V = vs.110%29.aspx – GreatJobBob

回答

0

積分轉到GreatJobBob鏈接我的MSDN頁面,下面達到了我所期待的。

using System.Windows.Forms.VisualStyles; 

    Application.VisualStyleState = VisualStyleState.NonClientAreaEnabled; 

這讓我改變我的進度條的顏色而不改變我的控件和窗體的其餘部分。

0

創建您自己的進度欄類。禁用Application.EnableVisualStyles將導致其他用戶界面(如MessageBox)出現問題。這裏有一個基本的課程,讓你開始,只需將forecolor改爲你想要的就可以了。

using System; 
using System.Drawing; 
using System.Windows.Forms; 

class MyProgressBar : Control 
{ 
public MyProgressBar() 
{ 
    this.SetStyle(ControlStyles.ResizeRedraw, true); 
    this.SetStyle(ControlStyles.Selectable, false); 
    Maximum = 100; 
    this.ForeColor = Color.Red; //This is where you choose your color 
    this.BackColor = Color.White; 
} 
public decimal Minimum { get; set; } 
public decimal Maximum { get; set; } 

private decimal mValue; 
public decimal Value 
{ 
    get { return mValue; } 
    set { mValue = value; Invalidate(); } 
} 

protected override void OnPaint(PaintEventArgs e) 
{ 
    var rc = new RectangleF(0, 0, (float)(this.Width * (Value - Minimum)/Maximum), this.Height); 
    using (var br = new SolidBrush(this.ForeColor)) 
    { 
     e.Graphics.FillRectangle(br, rc); 
    } 
    base.OnPaint(e); 
} 
}