Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.Windows.Forms;
- namespace R802DeteccionClickFigura
- {
- public partial class Principal : Form
- {
- private GraphicsPath path;
- private Rectangle rectangulo;
- private bool dentroDelPath = false;
- private bool dentroDelRectangulo = false;
- Brush rosado = Brushes.HotPink;
- Brush azulClaro = Brushes.LightBlue;
- public Principal()
- {
- InitializeComponent();
- }
- private void Principal_Load(object sender, EventArgs e)
- {
- path = new GraphicsPath();
- path.AddEllipse(10, 10, 100, 60);
- path.AddCurve(new Point[] {new Point(50, 50),
- new Point(10,33), new Point(80,43)});
- path.AddLine(50, 120, 250, 80);
- path.AddLine(120, 40, 110, 50);
- path.CloseFigure();
- rectangulo = new Rectangle(100, 170, 220, 120);
- }
- private void Principal_Paint(object sender, PaintEventArgs e)
- {
- Graphics g = e.Graphics;
- if (dentroDelPath)
- {
- g.FillPath(rosado, path);
- g.FillRectangle(azulClaro, rectangulo);
- }
- else if (dentroDelRectangulo)
- {
- g.FillRectangle(rosado, rectangulo);
- g.FillPath(azulClaro, path);
- }
- else
- {
- g.FillPath(azulClaro, path);
- g.FillRectangle(azulClaro, rectangulo);
- }
- g.DrawPath(Pens.Black, path);
- g.DrawRectangle(Pens.Black, rectangulo);
- }
- private void Principal_MouseMove(object sender, MouseEventArgs e)
- {
- using (Graphics g = this.CreateGraphics())
- {
- if (rectangulo.Contains(e.X, e.Y))
- {
- if (!dentroDelRectangulo)
- {
- dentroDelRectangulo = true;
- g.FillRectangle(rosado, rectangulo);
- g.DrawRectangle(Pens.Black, rectangulo);
- }
- }
- else if (dentroDelRectangulo)
- {
- dentroDelRectangulo = false;
- g.FillRectangle(azulClaro, rectangulo);
- g.DrawRectangle(Pens.Black, rectangulo);
- }
- if (path.IsVisible(e.X, e.Y))
- {
- if (!dentroDelPath)
- {
- dentroDelPath = true;
- g.FillPath(rosado, path);
- g.DrawPath(Pens.Black, path);
- }
- }
- else if (dentroDelPath)
- {
- dentroDelPath = false;
- g.FillPath(azulClaro, path);
- g.DrawPath(Pens.Black, path);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement