0

Есть форма с кодом:

    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 Тема4_1
{
    public partial class Form1 : Form
    {
        Form2 f2 = new Form2();
        int sec = 0;
        int w = 80, h = 80;
        int x = 1, y = 1;
        int speed = 1;
        enum STATUS { Left, Right }; 
        STATUS flag; 
        SolidBrush brush = new SolidBrush(Color.Red);
        Rectangle rc;
        public Form1()
        {
            InitializeComponent();
        }
        private void Button1_Click(object sender, EventArgs e)
        {   
            timer1.Enabled = timer1.Enabled ? false : true;
        }
        private void Button1_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyData == Keys.P)
            {
                button1.PerformClick();
            }
            if (e.KeyData == Keys.O)
            {
                f2.Visible = f2.Visible ? false : true;
            }
        }   
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            PointF point1 = new PointF(x+4, y+40);
            PointF point2 = new PointF(x+75, y+40);
            PointF point3 = new PointF(x+40, y+4);
            PointF[] curvePoints = {point1, point2, point3};
            e.Graphics.FillPolygon(brush, curvePoints);
        }
        private void Timer1_Tick(object sender, EventArgs e)
        {
            label1.Text = Convert.ToString(color);
            sec++; // секунды
            speed = f2.NumberSpeed;
            rc = new Rectangle(x, y, w, h);
            this.Invalidate(rc, true);
            if (flag == STATUS.Left)
            {
                x -= speed;
                y -= speed;
            }
            if (flag == STATUS.Right)
            {
                x += speed;
                y += speed;
            }
            if (x >= (this.ClientSize.Width - w))
            {
                flag = STATUS.Left;
            }
            else
            if (x <= 1)
            {
                flag = STATUS.Right;
            }
            rc = new Rectangle(x, y, w, h); 
            this.Invalidate(rc, true); 
        }
    }
}

Тут задаю цвет фигуры(Красный):

SolidBrush brush = new SolidBrush(Color.Red);

А тут нужно как то изменить цвет фигуры с красного на желтый:

private void Timer1_Tick(object sender, EventArgs e)
        {
            label1.Text = Convert.ToString(color);
            sec++; // секунды
            speed = f2.NumberSpeed;
            rc = new Rectangle(x, y, w, h);
            this.Invalidate(rc, true);
            if (flag == STATUS.Left)
            {
                x -= speed;
                y -= speed;
            }
            if (flag == STATUS.Right)
            {
                x += speed;
                y += speed;
            }
            if (x >= (this.ClientSize.Width - w))
            {
                flag = STATUS.Left;
            }
            else
            if (x <= 1)
            {
                flag = STATUS.Right;
            }
            rc = new Rectangle(x, y, w, h); 
            this.Invalidate(rc, true); 
        }

Именно в этой части:

if (flag == STATUS.Left)
            {
                x -= speed;
                y -= speed;
            }

Подскажите как это сделать.

1 ответ 1

1

Думаю, что так

brush.Color = Colors.Yelow;

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.