一个method,比如:private void DrawPawn(Graphics paper, int x, int y, Color colour)
{
int offset = (SquareSize - PieceSize) / 2;
SolidBrush brush = new SolidBrush(colour);
paper.FillPolygon(brush, new Point[].......................
paper.DrawString(.............................);
}这样一个题目本身就给了的method,能够把它用到我的code中来吗?如何操作?题目中的原话是:“画各个图形的method已经给你们了,call them with the appropriate values.”  (我的疑问在于这个method没有return.....,所以不知道如何把它call进我的代码中来)?比如:
ifXXXXX
{   
    XXXXXXXXXXXXXXX;(我现在要在这里作出图,作图方法就是上面的那个method,请问该怎么写?)
}

解决方案 »

  1.   

    虽然没有返回,但是参数paper是可以修改的,paper在该方法中没有进行初始化,明显是需要由调用该方法的部分进行初始化再进行方法调用,否则就会报错。
    Graphics paper = new Graphics();
    DrawPawn(paper,x,y,Color.Black);
      

  2.   

    这个简单,因为此method 是不需要返回值的。使用时直接callifXXXXX
    {   
      DrawPawn(paper, x, y, colour);(我现在要在这里作出图,作图方法就是上面的那个method,请问该怎么写?)
    }
      

  3.   

    楼上两位,我试过了,不行额。x、y和colour下都有红线提示不存在于当前内容中。
      

  4.   

    Graphics paper = new Graphics();
    DrawPawn(paper,100,100,System.Drawing.Color.Black);
    试试这样
      

  5.   


    天哪,你能不能试一下,闭着眼睛瞎说!
    谁告诉你能这样创建 Graphics 对象?
    Graphics paper = new Graphics();
      

  6.   

    Graphics类没有new实例的构造方法。
    许多事件的参数里就带有Graphics对象//从Paint 事件的 PaintEventArgs 中获取对 Graphics 对象的引用
    private void Form1_Paint(object sender, 
       System.Windows.Forms.PaintEventArgs pe) 
    {
       Graphics g = pe.Graphics;
       // Insert code to paint the form here.
    }//当然也可以自己创建对象
    System.Drawing.Graphics paper=g = this.CreateGraphics();//从控件或窗体创建实例Graphics g = Graphics.FromImage(myBitmap);//从 Image 对象创建