2
Answers

Color object with keyboard

albert albert

albert albert

13y
1.2k
1
HI everyone,

I have this:

[code]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;

namespace ColorCircleApp
{
  public partial class Form1 : Form
  {
  private Point[] circle = { new Point(50, 100), new Point(100, 50), new Point(150, 100) };
  private GraphicsPath p = new GraphicsPath();
  private Region region;
  private int oldX = 100;
  private int oldY = 75;
  private bool inside = false;
  public const int SLOW = 2;
  public const int FAST = 4;
  private int deltaTax = SLOW;
 

  public Form1()
  {
  InitializeComponent();
  Size = new Size(500, 300);
  Text = "Draw a circle";
  BackColor = Color.White;
  p.AddPolygon(circle);
  region = new Region(p);

  Paint +=new PaintEventHandler(DrawGraphics);
 

  }

  protected override void OnPaint(PaintEventArgs e)
  {
  Graphics g = e.Graphics;
  Pen blue = new Pen(Color.Blue, 3);
  g.DrawEllipse(blue, 10, 100, 100, 50);
  g.FillRegion(Brushes.Blue, region);
  Rectangle dot = new Rectangle(oldX, oldY, 50, 50);
 
  //g.DrawString(region.ToString(), blue, Brushes.Blue, x, y);
  //g.FillEllipse(Brushes.Blue, 150, 100, 100, 50);
  base.OnPaint(e);
  }
  protected void DrawGraphics(object sender, PaintEventArgs p)
  {
  Rectangle mySprite = new Rectangle(oldX, oldY, 50, 50);
  SolidBrush whiteBrush = new SolidBrush(Color.Black);
  //p.Graphics.FillRectangle(whiteBrush, mySprite);
  }

  protected override void OnKeyDown(KeyEventArgs e)
  {
  if (e.Control)
  deltaTax = SLOW;
  if (e.KeyCode == Keys.R)
  {
 
 
  //if (region.GetBounds(CreateGraphics()))
  //{

 
  // }
  //deltaTax = FAST; 
  }
  base.OnKeyDown(e);
  }//End method 
  }
}

[/code]


I want to change the color of the blue circle if u press the 'R' on the keyboard to Red.

How to do this?

THX for helping!!
Answers (2)