C#:嵌入的语句不能是声明或标记语句
private void Form2_Paint(object sender, PaintEventArgs e){
if(isCustomStyle)
System.Drawing.Drawing2D.GraphicsPath formShape=
new System.Drawing.Drawing2D.GraphicsPath ();
formShape.AddEllipse(0,0,this.Width ,this.Height);
this.Region =new Region(formShape);
}
运行时if下面的语句报错,错误 CS1023: 嵌入的语句不能是声明或标记语句
C# --------------------编程问答-------------------- http://blog.csdn.net/zyzqx2009/article/details/5627285 --------------------编程问答--------------------
--------------------编程问答-------------------- 明白了,谢谢 --------------------编程问答--------------------
private void Form2_Paint(object sender, PaintEventArgs e)
{
if(isCustomStyle)
{
System.Drawing.Drawing2D.GraphicsPath formShape=
new System.Drawing.Drawing2D.GraphicsPath ();
formShape.AddEllipse(0,0,this.Width ,this.Height);
this.Region =new Region(formShape);
}
}
请搞清楚什么不用{}之后的代码块和用了{}之后的代码块..
private void Form2_Paint(object sender, PaintEventArgs e)
{
if(isCustomStyle)
{
System.Drawing.Drawing2D.GraphicsPath formShape=
new System.Drawing.Drawing2D.GraphicsPath ();
}
formShape.AddEllipse(0,0,this.Width ,this.Height);
this.Region =new Region(formShape);
}
你那样的写法是相当于这样,你的formShape在if里面声明的,在if外面肯定用不了.
补充:.NET技术 , C#