2010-09-30 71 views
1

我使用自定義控件代碼爲我的winforms應用程序創建自定義的彩色進度條。我可以構建它,並且工作正常,但是每次嘗試使用設計器時,它都會崩潰。 「解析EntityName時發生錯誤」Winforms設計器錯誤「分析EntityName時發生錯誤」

  • 如果我從工具箱中添加this is what I get

  • 如果我插入一個進度條,然後重新導入我的控件的代碼(替換progressBarprogressBarEx),然後this is what I get

代碼:

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

namespace Crystal 
{ 
public class ProgressBarEx : ProgressBar 
{ 
    private SolidBrush brush = null; 

    public ProgressBarEx() 
    { 
     this.SetStyle(ControlStyles.UserPaint, true); 
    } 

    protected override void OnPaint(PaintEventArgs e) 
    { 
     if (brush == null || brush.Color != this.ForeColor) 
      brush = new SolidBrush(this.ForeColor); 

     Rectangle rec = new Rectangle(0, 0, this.Width, this.Height); 
     if (ProgressBarRenderer.IsSupported) 
      ProgressBarRenderer.DrawHorizontalBar(e.Graphics, rec); 
     rec.Width = (int)(rec.Width * ((double)Value/Maximum)) - 4; 
     rec.Height = rec.Height - 4; 
     e.Graphics.FillRectangle(brush, 2, 2, rec.Width, rec.Height); 
    } 
} 

}

+0

您是否嘗試過重建解決方案,然後打開設計器? – Zuhaib 2010-09-30 07:33:52

+0

是的,幾次,刪除bin文件夾,關閉,重新打開sln。還搜索了'&'符號,因爲我在谷歌搜索這個問題,有人說這是由這個角色造成的,但我沒有找到任何。 – 2010-09-30 07:38:11

+1

嘗試讀取XML時發生了爆炸,那到底是什麼?您尚未提供所有代碼,至少缺少值和最大屬性。那裏還有什麼?它是否使用任何應用程序設置? – 2010-09-30 07:44:35

回答

4

多米尼克又名galaris在他自己的問題提供了他的答案。我清理它並將其移到此處:

解決方案可能是found here。問題是我的一個文件夾包含&字符。將項目移動到桌面文件夾解決了問題。