Canalblog
Editer l'article Suivre ce blog Administration + Créer mon blog
Publicité
Halim
Archives
28 mars 2005

Intégrer un contrôle utilisateur Windows dans une page HTML

But de l'article : créer un contrôle utilisateur Windows et l'intégrer dans une page HTML

Pré-requis : C#, Création des contrôles utilisateur, HTML

La première phase de ce tutorial est la création du contrôle utilisateur. On ne va réinventer la roue, on va créer un contrôle utilisateur qui hérite du contrôle Windows Panel. La classe GraphicPanelControl se présente comme suit  sous le designer des classes sous VS.NET 2005 Beta 1:

classe_graphicpanelcontrol1

using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
 
namespace GraphicPanelNamespace
{
      public class GraphicPanelControl: Panel
      {
            
            #region "attributs"
            private int _lineWidth;
            private Color _lineColor;
            private bool _captured;
            private Point _lastPoint;
            private Color _backgroundColor;
 
            #endregion
 
            #region "accesseurs"
            public int LineWidth
            {
                  get
                  {
                        return _lineWidth;
                  }
                  set
                  {
                        _lineWidth = value;
                  }
            }
            public Color LineColor
            {
                   get
                  {
                        return _lineColor;
                  }
                   set
                  {
                        _lineColor = value;
                  }
            }
      
            public Color BackgroundColor
            {
                get   
                {
                    return _backgroundColor;
                }
 
                set
                {
                    _backgroundColor = value;
                }
        }
        #endregion
        protected override void OnMouseDown (MouseEventArgs e)
            {
                  base.OnMouseDown(e);
                  if (e.Button == MouseButtons.Left)
                  {
                        _lastPoint = new Point(e.X, e.Y);
                        _captured = true;
                  }
 
            }
         protected override void OnMouseMove (MouseEventArgs e)
            {
                  base.OnMouseMove(e);
                  if (_captured )
                  {
                       Point currentPoint = new Point(e.X, e.Y);
                        Pen PenDraw = new Pen(_lineColor,_lineWidth);
 
                        Graphics g = this.CreateGraphics();
                        g.DrawLine    (PenDraw,_lastPoint.X,_lastPoint.Y,currentPoint.X,currentPoint.Y);
                        _lastPoint = currentPoint;
                        g.Dispose();
                        PenDraw.Dispose();
 
                  }
            }
            protected override void OnMouseUp (MouseEventArgs e)
            {
                 base.OnMouseUp(e);
                  if (e.Button == MouseButtons.Left)
                  {
                        _captured = false;
                  }
            }
   
            private System.ComponentModel.Container components = null;
 
            public GraphicPanelControl()
            {               
                  InitializeComponent();
            }
 
            protected override void Dispose( bool disposing )
            {
                  if( disposing )
                  {
                        if( components != null )
                             components.Dispose();
                  }
                  base.Dispose( disposing );
            }
 
            #region Code généré par le Concepteur de composants
            
           private void InitializeComponent()
            {
                  components = new System.ComponentModel.Container();
            }
        #endregion
    }
}

On génère la dll GraphicPanelControl et on copie la dll générèe dans le répertoire C:\inetpub\wwwroot

<html xmlns="http://www.w3.org/1999/xhtml" >
<body>

<object width = 600 height = 400 classid="http:GraphicPanelGraphic.dll#GraphicPanelNamespace.GraphicPanelControl">

<param name="LineWidth" value="6" />
<param name="LineColor" value="red" />
<param name="BackgroundColor" value = "lightGray"/>

</object></body>
</html

Publicité
Commentaires
Publicité
Publicité