如何更改程序以使形状为三角形?

时间:2019-02-20 10:27:41

标签: c# winforms

下面是我的代码,我已经为三角形的第二行和第三行分配了一个值,但是正在努力将它们与其余代码集成在一起。请问我在其他地方应该实施什么方面的建议。

public partial class Form1 : Form
{

    Graphics graphics;
    int ax = 150;
    int ay = 100;
    int bx = 25;
    int by = 50;
    int cx = 10;
    int cy = 90;
    int dx = 3;
    int dy = 2;

    public Form1()
    {
        InitializeComponent();
        this.Paint += new PaintEventHandler(triangle);
        this.DoubleBuffered = true;
    }

    private void triangle(object sender, PaintEventArgs e)
    {
        graphics = e.Graphics;
        SolidBrush brush = new SolidBrush(Color.Black);
        graphics.FillEllipse(brush, ax, ay, 10, 10);
    }

    private void movetriangle()
    {
        int newposition_x = ax + dx;
        int newposition_y = ay + dy;

        if (newposition_x < -5 || newposition_x > this.ClientSize.Width) dx = -dx;
        if (newposition_y < 0 || newposition_y > this.ClientSize.Height) dy = -dy;

        ax += dx;
        ay += dy;
        Invalidate();
    }
    private void Form1_Load(object sender, EventArgs e)
    {

    }

    private void timer1_Tick_1(object sender, EventArgs e)
    {
        movetriangle();
    }
}

0 个答案:

没有答案