Created
June 1, 2014 21:37
-
-
Save Fhernd/2205d46947369766e9ab to your computer and use it in GitHub Desktop.
Control con el lienzo de dibujo del triángulo.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ===++=== | |
// | |
// OrtizOL | |
// | |
// ===--=== | |
/*============================================================ | |
// | |
// Clase: ControlTriangulo.cs | |
// | |
// Original en: http://goo.gl/H84cIw | |
// | |
// Propósito: Control con el lienzo de dibujo del triángulo. | |
// | |
============================================================*/ | |
using System; | |
using System.Collections.Generic; | |
using System.ComponentModel; | |
using System.Drawing; | |
using System.Data; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Windows.Forms; | |
using ElTriangulo.Modelo; | |
namespace ElTriangulo.GUI | |
{ | |
/// <summary> | |
/// Control con el lienzo de dibujo del triángulo. | |
/// </summary> | |
public partial class ControlTriangulo : UserControl | |
{ | |
#region Campos (componentes) | |
/// <summary> | |
/// Triángulo a dibujar. | |
/// </summary> | |
private Triangulo triangulo; | |
#endregion | |
#region Constructores | |
/// <summary> | |
/// Creación de control con lienzo de dibujo de triángulo | |
/// </summary> | |
/// <param name="triangulo">Triángulo a dibujar en el lienzo.</param> | |
public ControlTriangulo(Triangulo triangulo) | |
{ | |
InitializeComponent(); | |
this.triangulo = triangulo; | |
} | |
#endregion | |
#region Eventos | |
/// <summary> | |
/// Redibuja el lienzo cada vez que sea necesario. | |
/// </summary> | |
/// <param name="sender">Generador del evento.</param> | |
/// <param name="e">Argumentos del evento.</param> | |
private void ControlTriangulo_Paint(object sender, PaintEventArgs e) | |
{ | |
Graphics g = e.Graphics; | |
PointF[] puntos = new PointF[3]; | |
puntos[0] = new PointF(float.Parse(triangulo.Punto1.X.ToString()), float.Parse(triangulo.Punto1.Y.ToString())); | |
puntos[1] = new PointF(float.Parse(triangulo.Punto2.X.ToString()), float.Parse(triangulo.Punto2.Y.ToString())); | |
puntos[2] = new PointF(float.Parse(triangulo.Punto3.X.ToString()), float.Parse(triangulo.Punto3.Y.ToString())); | |
Pen pen = new Pen(System.Drawing.Color.FromArgb(triangulo.ColorLineas.Rojo, triangulo.ColorLineas.Verde, triangulo.ColorLineas.Azul), 3); | |
SolidBrush brush = new SolidBrush(System.Drawing.Color.FromArgb(triangulo.ColorRelleno.Rojo, triangulo.ColorRelleno.Verde, triangulo.ColorRelleno.Azul)); | |
g.DrawPolygon(pen, puntos); | |
g.FillPolygon(brush, puntos); | |
} | |
#endregion | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment