在方法内部调用函数 [英] To call a function inside method
问题描述
我在控制台应用程序中开发了应用程序。我想在另一个方法中调用mainform函数。我已经尝试但错误抛出
错误2'System.Drawing.Graphics'是'类型'但是像'变量'一样使用
private void MainForm_Paint( object sender,PaintEventArgs e)
{
Render_Plot(e.Graphics, 0 跨度>);
}
private void timer1_Tick(< span class =code-keyword> object sender,EventArgs e)
{
Render_Plot(Graphics, 0 ); // 错误 - 如何在此处调用render_plot函数
}
我的尝试:
< pre lang =c#> private void MainForm_Paint( object sender,PaintEventArgs e)
{
Render_Plot(e.Graphics, 0 );
}
private void timer1_Tick(< span class =code-keyword> object sender,EventArgs e)
{
Render_Plot(Graphics, 0 ); // 错误 - 如何在此处调用render_plot函数
}
不要。你可以这样做 - 但这意味着你自己创建和处理Graphics上下文,这可能会限制你可以做的其他事情。相反,在Tick事件处理程序中,只需调用Invalidate:
private void MainForm_Paint( object sender,PaintEventArgs e)
{
Render_Plot(e.Graphics, 0 跨度>);
}
private void timer1_Tick( object sender,EventArgs e)
{
Invalidate();
}
这将导致系统发出一个Paint请求,它将触发您的Paint事件处理程序。
I have developed application in console application. I want to call mainform function inside another method. i have tried but error throws as
"Error 2 'System.Drawing.Graphics' is a 'type' but is used like a 'variable'"
private void MainForm_Paint(object sender, PaintEventArgs e)
{
Render_Plot(e.Graphics, 0);
}
private void timer1_Tick(object sender, EventArgs e)
{
Render_Plot(Graphics, 0); //Error--how to call render_plot function here
}
What I have tried:
private void MainForm_Paint(object sender, PaintEventArgs e)
{
Render_Plot(e.Graphics, 0);
}
private void timer1_Tick(object sender, EventArgs e)
{
Render_Plot(Graphics, 0); //Error--how to call render_plot function here
}
Don't. You could do it - but it means creating and disposing the Graphics context yourself, and that may limit what else you can do. Instead, in your Tick event handler, just call Invalidate:
private void MainForm_Paint(object sender, PaintEventArgs e) { Render_Plot(e.Graphics, 0); } private void timer1_Tick(object sender, EventArgs e) { Invalidate(); }
That will cause the system to issue a Paint request, which will trigger your Paint event handler.
这篇关于在方法内部调用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!