我会搞定的 2022-03-14 23:38 采纳率: 100%
浏览 27
已结题

C#窗体中我自定义类中的数据为什么传不到form里

Chess类里的pointlist中的点为什么传不到form类里的paint函数中,画不出来图形啊?有谁可以解答下吗

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace C_例_69_五子棋_窗体应用
{
public enum ChessState
{
BLANK,
BLACK,
WHITE
}

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    public int start = 0;
    public const int forever = 10;
    public bool fupan = false;
    public int count = forever;

    private void Form1_Paint(object sender, PaintEventArgs e)
    {
        Chess c1 = new Chess();

        Graphics g = e.Graphics;
        SolidBrush w = new SolidBrush(Color.White);
        SolidBrush b = new SolidBrush(Color.Black);

        for (int i = 0; i < c1.pointlist.Count; i++)
        {
            if (i % 2 == 0)
            {
                g.FillEllipse(w, x - 15, y - 15, 28, 28);
              
            if (i % 2 == 1)
            {
                g.FillEllipse(b, x - 15, y - 15, 28, 28);
                
            }
        }
    }

    private void Form1_MouseDown(object sender, MouseEventArgs e)
    {
        Chess c2 = new Chess();
        if (start == 1)
        {
            if (e.Location.X > 55 && e.Location.X < 505 && e.Location.Y > 65 && e.Location.Y < 515)
            {
                Point p1 = new Point();
                p1.X = e.Location.X; p1.Y = e.Location.Y;
                c2.pointlist.Add(p1);
                Invalidate();
            }
        }
       
    }

    private void rrstart_Click(object sender, EventArgs e)
    {
        Chess c = new Chess();
        c.pointlist.Clear();
        Invalidate();
        start = 1;
    }

  }

public struct Point
{
public int X;
public int Y;
}
class Chess
{
public int width = 640;
public int height = 600;

    public ChessState[,] qipan = new ChessState[15, 15];
    public List<Point> pointlist = new List<Point>(500);

  
}

}

  • 写回答

3条回答 默认 最新

  • 关注

    Form1再定义一个传参的构造函数,通过构造函数传参进去就可以了。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 3月23日
  • 已采纳回答 3月15日
  • 创建了问题 3月14日

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)