C#新工程引用另一工程的函数


 void paint_CZ(double X, double Y, double c, double l, double[] xCoords, double[] yCoords, double[] zCoords, PaintEventArgs e)
        {
            // 获取用户输入的三角形左角点,边长
            double x1;
            double x2;
            double y2;
            double x3;
            double y3;
            if (c <= 0 || l <= 0)
            {
                MessageBox.Show("请输入大于0的数");
            }
            else
            {
                // 创建绘图对象
                Graphics g = e.Graphics;
                g.Clear(Color.White);

                // 获取坐标轴原点的坐标
                double originX = pictureBox1.Width / 2.0;
                double originY = pictureBox1.Height / 2.0;

                // 计算三角形的三个点坐标
                double angle = Math.PI / 3;
                double a = X + c;
                double b = c / 2.0 + X;
                double f = Math.Sin(angle) * c + Y;

                double[] bx = new double[4];
                double[] by = new double[4];
                bx[0] = X * scale + originX;
                by[0] = originY - Y * scale;

                bx[1] = a * scale + originX;
                by[1] = originY - Y * scale;

                bx[2] = b * scale + originX;
                by[2] = originY - f * scale;

                bx[3] = X * scale + originX; ;
                by[3] = originY - Y * scale;

                int i;
                PointF[] pointF = new PointF[4];
                for (i = 0; i < 4; i++)
                {
                    pointF[i] = new PointF((float)bx[i], (float)by[i]);
                }
                // 绘制三角形
                Pen Pen = new Pen(Color.Red, 2);
                g.DrawPolygon(Pen, pointF);


                //等分点坐标
                for (int j = 0; j <= c / l; j++)
                {
                    x1 = X + j * l;
                    x2 = X + c - Math.Cos(angle) * j * l;
                    y2 = Y + Math.Sin(angle) * l * j;
                    x3 = X + c / 2 - Math.Cos(angle) * j * l;
                    y3 = Y + Math.Sin(angle) * c - Math.Sin(angle) * l * j;
                    xCoords[j] = x1;
                    yCoords[j] = Y;
                    zCoords[j] = '0';
                    xCoords[(int)(j + (c / l) - 1)] = x2;
                    yCoords[(int)(j + (c / l) - 1)] = y2;
                    zCoords[(int)(j + (c / l) - 1)] = '0';
                    xCoords[(int)(j + 2 * (c / l) - 1)] = x3;
                    yCoords[(int)(j + 2 * (c / l) - 1)] = y3;
                    zCoords[(int)(j + 2 * (c / l) - 1)] = '0';
                }

            }

我想在另一工程引用paint_CZ,在另一工程该怎么写代码?重点是引用这个函数中的三个数组,初学者,求各位牛人指教,谢谢。

放在dll项目里,注意类和方法,都要public的,如果方法没有用到成员变量,可以定义成static的
另一个项目引用dll以后
using 第一个项目的命名空间
然后
你的类 c = new 你的类();
c.paint_CZ(...)

不知道你这个问题是否已经解决, 如果还没有解决的话:
  • 这篇博客: c# 实验五 图形设计中的 创建每个窗体时在事件位置,选择Paint,双击打开 部分也许能够解决你的问题, 你可以仔细阅读以下内容或者直接跳转源博客中阅读:

    在这里插入图片描述
    在第一题的Form3.cs中引用 using.System.Drawing.Drawing2D
    program.cs 中添加Form2、Form3、Form4
    在这里插入图片描述


如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^