bonhomeExamJanvier/Bonhomme01/PointOrigine.cs

148 lines
3.6 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace Bonhomme01
{
class PointOrigine
{
#region Données membres
private int _X = 0;
private int _Y = 0;
private bool _Visible = true;
private PictureBox _Hebergeur;
private Color _Fond = Color.Silver;
private Color _Crayon = Color.Black;
#endregion
#region Constructeurs
public PointOrigine()
{
this._Hebergeur = null;
}
public PointOrigine(PictureBox hebergeur)
{
this._Hebergeur = hebergeur;
this._Fond = hebergeur.BackColor;
}
public PointOrigine(PictureBox hebergeur, int xy) : this (hebergeur)
{
X = Y = xy;
}
public PointOrigine(PictureBox hebergeur, int x, int y) : this(hebergeur)
{
X = x;
Y = y;
}
public PointOrigine(int x, int y)
{
X = x;
Y = y;
}
public PointOrigine(PictureBox hebergeur, int xy, Color crayon) : this(hebergeur, xy)
{
Crayon = crayon;
}
public PointOrigine(PictureBox hebergeur, int x, int y, Color crayon) : this(hebergeur, x, y)
{
Crayon = crayon;
}
#endregion
#region Accesseurs
public int X
{
get { return _X; }
set
{
if (value < 0) { this._X = 0; }
else if (value > this._Hebergeur.Bounds.Size.Width) { this._X = this._Hebergeur.Bounds.Size.Width; }
else { this._X = value; }
}
}
public int Y
{
get { return _Y; }
set
{
if (value < 0) { this._Y = 0; }
else if (value > this._Hebergeur.Bounds.Size.Height) { this._Y = this._Hebergeur.Bounds.Size.Height; }
else { this._Y = value; }
}
}
public bool Visible
{
get { return _Visible; }
set { _Visible = value; }
}
public Color Fond
{
get { return _Fond; }
set
{
try { _Fond = value; }
catch (Exception) { }
}
}
public Color Crayon
{
get { return _Crayon; }
set
{
try { _Crayon = value; }
catch (Exception) { }
}
}
public PictureBox Hebergeur
{
get { return _Hebergeur; }
set { _Hebergeur = value; }
}
#endregion
#region Méthodes
public void Bouger(int deplX, int deplY)
{
X += deplX;
Y += deplY;
}
public virtual void Afficher(IntPtr handle)
{
if (this.Visible)
{
Graphics gr = Graphics.FromHwnd(handle);
gr.FillEllipse(new SolidBrush(Color.Yellow), this.X, this.Y, 6, 6);
gr.DrawEllipse(new Pen(this._Crayon, 2), this.X, this.Y, 6, 6);
}
}
public virtual void Cacher(IntPtr handle)
{
if (this.Visible)
{
Graphics gr = Graphics.FromHwnd(handle);
gr.FillEllipse(new SolidBrush(this.Fond), this.X, this.Y, 6, 6);
gr.DrawEllipse(new Pen(this.Fond, 2), this.X, this.Y, 6, 6);
}
}
#endregion
}
}