Custom Control

Hi,

I am looking for some sample code for creating a custom control that is
moveable/selectable at runtime.  I am looking for something simmilar to how
a control would function at design time.  I have read some articles about
hooking into the designer support but that seems to be no help.  I am new to
custom control development so please bear with me.

To be more specific I'm trying to do something simmilar to what Visio does
with its shapes.  I need to have moveable shapes and a connector tool to
link them.

Any help, big or small will be greatly appreciated.

Thanks in advance,

Brian S. Estep


Answer this question

Custom Control

  • havoc27

    You can hook the MouseDown, MouseMove and MouseUp events to get this behavior.  The code below is copied from the <a href="http://windowsforms.net/articles/usingregionmastercontrols.aspx">RegionMaster Controls</a> (the Form1.cs file to be exact).

    private void solidClock1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
    {
    mouseDown = true;
    formMove = new Point(e.X,e.Y);
    }

    private void solidClock1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
    {
    if (mouseDown)
    {
    this.Location = 
                              new Point(this.Left - (formMove.X - e.X), this.Top - (formMove.Y - e.Y));
    }
    }

    private void solidClock1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
    {
    mouseDown = false;
    }
    - mike

  • Custom Control