| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 
 | using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
 
namespace MovableObject
{
    public partial class Connector : UserControl
    {
        public Connector()
        {
            InitializeComponent();
 
            this.SetStyle(ControlStyles.UserPaint |
                          ControlStyles.AllPaintingInWmPaint |
                          ControlStyles.OptimizedDoubleBuffer, true);
 
 
        }
 
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics canvas = e.Graphics;
 
            //on clear le background
            canvas.FillRectangle(Brushes.White, 0, 0, mW_f, mH_f);
 
            //on trace la ligne horizontale
            canvas.DrawLine(Pens.Black, 0, mH2_f, mW_f - mDb_f, mH2_f);
 
            if (mMouseIsOnCircle_b)
            {
                canvas.FillEllipse(mOnMouseBrush,
                               mW_f - mDb_f, 0,
                               mDb_f - 1, mH_f - 1);
            }
 
            //on trace le cercle
            canvas.DrawEllipse(Pens.Black,
                               mW_f - mDb_f, 0,
                               mDb_f - 1, mH_f - 1);
        }
 
        protected override void  OnSizeChanged(EventArgs e)
        {
 	        mH_f = this.Height;
            mW_f = this.Width;
 
            mH2_f = this.Height/2;
            mDb_f = mH_f;
 
            this.Invalidate();
        }
 
        protected override void OnMouseMove(MouseEventArgs e)
        {
            if (e.X > mW_f - mDb_f)
            {
                mMouseIsOnCircle_b = true;
            }
            else
            {
                mMouseIsOnCircle_b = false;
            }
 
            this.Invalidate();
        }
 
        protected override void OnMouseLeave(EventArgs e)
        {
            mMouseIsOnCircle_b = false;
            this.Invalidate();
        }
 
        [System.ComponentModel.DefaultValueAttribute(typeof(System.Drawing.Color), 
            "OnMouse Color"), 
            System.ComponentModel.CategoryAttribute("Appearance"), 
            System.ComponentModel.DescriptionAttribute("La couleur lorsque la souris est sur le cercle.")
        ]
 
        public System.Drawing.Color OnMouseColor
        {
            get
            {
                return this.mOnMouseColor;
            }
            set
            {
                this.mOnMouseColor = value;
                this.mOnMouseBrush = new SolidBrush(mOnMouseColor);
 
                if (this.DesignMode == true)
                {
                    this.Invalidate();
                }
            }
        }
 
        private float mH_f;  //heigth
        private float mW_f;  //width
        private float mDb_f; //big diameter
        private float mDl_f; //little diameter
        private float mH2_f; //half heigth
 
        private bool mLinked_b = false; //linked?
        private bool mMouseIsOnCircle_b = false;
 
        private SolidBrush mOnMouseBrush = new SolidBrush(Color.Red);
        private Color mOnMouseColor = Color.Red;
    }
} | 
Partager