Advertisement
Fhernd

Principal.cs

Mar 8th, 2018
1,662
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.12 KB | None | 0 0
  1. using System;
  2. using System.Drawing;
  3. using System.Drawing.Drawing2D;
  4. using System.Windows.Forms;
  5.  
  6. namespace R802DeteccionClickFigura
  7. {
  8.     public partial class Principal : Form
  9.     {
  10.         private GraphicsPath path;
  11.         private Rectangle rectangulo;
  12.  
  13.         private bool dentroDelPath = false;
  14.         private bool dentroDelRectangulo = false;
  15.  
  16.         Brush rosado = Brushes.HotPink;
  17.         Brush azulClaro = Brushes.LightBlue;
  18.  
  19.         public Principal()
  20.         {
  21.             InitializeComponent();
  22.         }
  23.  
  24.         private void Principal_Load(object sender, EventArgs e)
  25.         {
  26.             path = new GraphicsPath();
  27.             path.AddEllipse(10, 10, 100, 60);
  28.             path.AddCurve(new Point[] {new Point(50, 50),
  29.                 new Point(10,33), new Point(80,43)});
  30.             path.AddLine(50, 120, 250, 80);
  31.             path.AddLine(120, 40, 110, 50);
  32.             path.CloseFigure();
  33.  
  34.             rectangulo = new Rectangle(100, 170, 220, 120);
  35.         }
  36.  
  37.         private void Principal_Paint(object sender, PaintEventArgs e)
  38.         {
  39.             Graphics g = e.Graphics;
  40.  
  41.             if (dentroDelPath)
  42.             {
  43.                 g.FillPath(rosado, path);
  44.                 g.FillRectangle(azulClaro, rectangulo);
  45.             }
  46.             else if (dentroDelRectangulo)
  47.             {
  48.                 g.FillRectangle(rosado, rectangulo);
  49.                 g.FillPath(azulClaro, path);
  50.             }
  51.             else
  52.             {
  53.                 g.FillPath(azulClaro, path);
  54.                 g.FillRectangle(azulClaro, rectangulo);
  55.             }
  56.  
  57.             g.DrawPath(Pens.Black, path);
  58.             g.DrawRectangle(Pens.Black, rectangulo);
  59.         }
  60.  
  61.         private void Principal_MouseMove(object sender, MouseEventArgs e)
  62.         {
  63.             using (Graphics g = this.CreateGraphics())
  64.             {
  65.                 if (rectangulo.Contains(e.X, e.Y))
  66.                 {
  67.                     if (!dentroDelRectangulo)
  68.                     {
  69.                         dentroDelRectangulo = true;
  70.                        
  71.                         g.FillRectangle(rosado, rectangulo);
  72.                         g.DrawRectangle(Pens.Black, rectangulo);
  73.                     }
  74.                 }
  75.                 else if (dentroDelRectangulo)
  76.                 {
  77.                     dentroDelRectangulo = false;
  78.                    
  79.                     g.FillRectangle(azulClaro, rectangulo);
  80.                     g.DrawRectangle(Pens.Black, rectangulo);
  81.                 }
  82.  
  83.                 if (path.IsVisible(e.X, e.Y))
  84.                 {
  85.                     if (!dentroDelPath)
  86.                     {
  87.                         dentroDelPath = true;
  88.                        
  89.                         g.FillPath(rosado, path);
  90.                         g.DrawPath(Pens.Black, path);
  91.                     }
  92.                 }
  93.                 else if (dentroDelPath)
  94.                 {
  95.                     dentroDelPath = false;
  96.                    
  97.                     g.FillPath(azulClaro, path);
  98.                     g.DrawPath(Pens.Black, path);
  99.                 }
  100.             }
  101.         }
  102.     }
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement