重写Form的OnPaint方法. 把绘制代码贴到那里面去.ms-help://MS.VSCC/MS.MSDNVS.2052/cpref/html/frlrfSystemWindowsFormsFormClassOnPaintTopic.htm

解决方案 »

  1.   

    在你的程序中加上
    protected override void OnPaint(PaintEventArgs e)
    {
        base.OnPaint(e);//这行必须要
        //调用你的绘制方法
        .....
        .....}
      

  2.   

    但是我要在mousedown事件里面交互实现绘制阿
    能不能给各详细点的例子我的代码:
    private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
    {
    Bitmap bmpWhite=new Bitmap(Application.StartupPath+@"\white1.gif");
    Bitmap bmpBlack=new Bitmap(Application.StartupPath+@"\black1.gif");
    Graphics g=this.CreateGraphics();

    int x=e.X-40 ;
    int y=e.Y-40 ;
    int i, j , vi, vj;
    i=x/26;
    j=y/26;
    vi=x%26;
    vj=y%26;
    if(vi>13) i++;
    if(vj>13) j++;
    this.Text=i.ToString() +j.ToString ()  ;
    if( i>=0 && j>=0 && i<=14 && j<=14)
    {
    if(isblackturn==true)
    {
    g.DrawImage(bmpBlack,40+26*i-bmpBlack.Width/2 ,40+26*j-bmpBlack.Height/2  ,bmpBlack.Width,bmpBlack.Height);
    isblackturn=!isblackturn;
    }
    else
    {
    g.DrawImage(bmpWhite,40+26*i-bmpWhite.Width/2 ,40+26*j-bmpWhite.Height/2  ,bmpWhite.Width,bmpWhite.Height);
    isblackturn=!isblackturn;
    }
    }
    }
      

  3.   

    你可以把
    g.DrawImage(bmpBlack,40+26*i-bmpBlack.Width/2 ,40+26*j-bmpBlack.Height/2  ,bmpBlack.Width,bmpBlack.Height);
    isblackturn=!isblackturn;
    这些写成一个方法或者类,然后根据一些全局变量(如isblackturn)在onPaint中调用