Skip to main content
 首页 » 编程设计

c#之Winforms 设计器错误 "An error occured while parsing EntityName"

2024年02月24日24虾米哥

我正在为我的 winforms 应用程序使用自定义控制代码来创建自定义彩色进度条。我可以构建它,它工作正常,但每次我尝试使用设计器时,它都会崩溃。 “解析 EntityName 时出错”

  • 如果我从工具箱中添加,this is what I get .

  • 如果我插入一个进度条,然后重新编写我的控件的代码(将 progressBar 替换为 progressBarEx),那么 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); 
    } 
} 

请您参考如下方法:

Dominik aka galaris 在他自己的问题中提供了答案。我把它清理干净并移到这里:

解决方案可以是found here .问题是我的其中一个文件夹包含& 字符。将项目移动到桌面文件夹解决了问题。