C# 在子窗体中设置DoubleBuffered=true时,会在Program.cs(System.Drawing.dll)中抛出System.ArgumentException
我试图通过在用户单击主窗体中的按钮时打开的窗体中设置C# 在子窗体中设置DoubleBuffered=true时,会在Program.cs(System.Drawing.dll)中抛出System.ArgumentException,c#,winforms,C#,Winforms,我试图通过在用户单击主窗体中的按钮时打开的窗体中设置DoubleBuffered=true来解决绘制事件中的一些闪烁问题。然而,正如新表单加载一样,我在Program.cs中得到了异常 "System.ArgumentException occurred in System.Drawing.dll" "System.ArgumentException: 'Parameter is not valid.'" static class Program { /// <
DoubleBuffered=true
来解决绘制事件中的一些闪烁问题。然而,正如新表单加载一样,我在Program.cs中得到了异常
"System.ArgumentException occurred in System.Drawing.dll"
"System.ArgumentException: 'Parameter is not valid.'"
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1()); //Error pops up on this line
}
}
在Program.cs文件中
我可以确认,当错误弹出时,不会调用Paint方法,并且错误似乎是在表单的构造函数完成时发生的。
我正在设计器属性中设置DoubleBuffered=True
第一个表单调用第二个表单(Form1.cs)
“我们能看到记号吗?”TaW补充道。它只包含Refresh()来调用绘制,但在错误发生之前不会调用此函数如果使用Visual Studio,请转到Debug->Exceptions并在引发异常时将System.ArgumentException标记为break。这将在异常发生时捕获异常,而不是在处理异常时捕获异常。@o_weisman启用此功能后,它似乎仍然在该行(Application.Run(new Form1()))上完全中断,而没有新信息(我将更新OP以了解我忘记说的内容)您的代码中是否有一个OnPaint处理程序,并且您正在处理它的一个参数,例如:?timer\u updatePaint我们可以看到勾号吗?@TaW添加了它。它只包含Refresh()来调用绘制,但在错误发生之前不会调用此函数如果使用Visual Studio,请转到Debug->Exceptions并在引发异常时将System.ArgumentException标记为break。这将在异常发生时捕获异常,而不是在处理异常时捕获异常。@o_weisman启用此功能后,它似乎仍然在该行(Application.Run(new Form1()))上完全中断,而没有新信息(我将更新OP以了解我忘记说的内容)您的代码中是否有一个OnPaint处理程序,并且您是否像下面这样处理它的一个参数:?
public LEDSimulate(string pathScript, string pathPython, Form1 formInst, List<Section> sections, int mon, int numThreads)
{
InitializeComponent();
instance = this;
this.TransparencyKey = (BackColor);
this.sections = sections;
this.procs = new List<Process>();
this.formInst = formInst;
//Initialize timer to tick every 30 seconds to update UI
timer_updatePaint.Interval = 33;
//Load with dummy data to update later
Pen dummy_pen = new Pen(Color.FromArgb(0, 0, 0, 0));
foreach (Section s in sections)
{
for(int i = 0; i<s.subSections; i++)
{
paintList.Add(new PaintForm(dummy_pen, 0, 0, 0, 0));
}
}
Console.WriteLine("Finished adding and starting");
timer_updatePaint.Start();
//-----Once this is done, the error occurs------
}
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1()); //Error pops up on this line
}
}
private void timer_updatePaint_Tick(object sender, EventArgs e)
{
this.Refresh();
}
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x02000000; // Turn on WS_EX_COMPOSITED
return cp;
}
}