Creating custom container controls

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jay Dee

    #1

    Creating custom container controls

    I have created a container that will position 4 panels that has 15
    different layouts to choose from.

    I have based it similar to a System.Windows. Forms.SplitCont ainer but
    that has 4 panels instead of 2.

    It douse not have the ability on fixing the splitter like the
    SplitContainer class has, each splitter is based on a parentage of the
    container. For what I wanted it for it did not need that capability so
    I wasn’t too bothered.

    I have also created the Designer class for the control Container and
    the Containers panel class making it user friendly at design time.

    I am very please with what I have achieved so far but I have become a
    little stuck when I came to moving the splitters at run time with the
    mouse.

    What I aim to acheave is something like this

    <code>

    protected override void OnMouseDown(Mou seEventArgs e)
    {
    base.OnMouseDow n(e);

    if (e.X this.VerticalSp litter1Position -
    (this.splitterT hicknes / 2) &&
    e.X < this.VerticalSp litter1Position +
    (this.splitterT hicknes / 2))
    {
    while (true)
    {
    // TO-DO
    // Re-capture the state of the mouse.
    e = new MouseEventArgs( ); // TO-DO - Dont no how to re
    capture the state of the mouse.

    // If the left button is no longer pressed exit loop.
    if (e.Button != MouseButtons.Le ft)
    {
    break;
    }

    this.VerticalSp litter1Position = e.X;

    Application.DoE vents();
    }
    }
    }

    </code>

    When the mouse is pressed while over one of the splitters it call the
    OnMouseDown event.

    Then it needs to wait until the user releases the mouse button before
    re locating the splitter to the new position.

    The problem I have is that I don’t know how to obtain the mouse
    coordinates when the mouse leaves the area of the splitter when the
    mouse moves over one of the containers panels within the container the
    mouse events are no longer called.

    Am I thinking completely wrong by thinking about a loop within the
    OnMouseDown event and if so could anybody point me in the write
    direction.

    This is a link to my container control source code including a simple
    form displaying the views that the container offers.



    Thank you all for any help and I hope this cold be useful to someone.
  • Pavel Minaev

    #2
    Re: Creating custom container controls

    On Aug 4, 12:26 pm, Jay Dee <first...@gmail .comwrote:
    I have created a container that will position 4 panels that has 15
    different layouts to choose from.
    >
    I have based it similar to a System.Windows. Forms.SplitCont ainer but
    that has 4 panels instead of 2.
    >
    It douse not have the ability on fixing the splitter like the
    SplitContainer class has, each splitter is based on a parentage of the
    container. For what I wanted it for it did not need that capability so
    I wasn’t too bothered.
    >
    I have also created the Designer class for the control Container and
    the Containers panel class making it user friendly at design time.
    >
    I am very please with what I have achieved so far but I have become a
    little stuck when I came to moving the splitters at run time with the
    mouse.
    >
    What I aim to acheave is something like this
    >
    <code>
    >
    protected override void OnMouseDown(Mou seEventArgs e)
    {
        base.OnMouseDow n(e);
    >
        if (e.X this.VerticalSp litter1Position -
    (this.splitterT hicknes / 2) &&
            e.X < this.VerticalSp litter1Position +
    (this.splitterT hicknes / 2))
        {
            while (true)
            {
                // TO-DO
                // Re-capture the state of the mouse.
                e = new MouseEventArgs( ); // TO-DO - Dont no how to re
    capture the state of the mouse.
    >
                // If the left button is no longer pressed exit loop.
                if (e.Button != MouseButtons.Le ft)
                {
                    break;
                }
    >
                this.VerticalSp litter1Position = e.X;
    >
                Application.DoE vents();
            }
        }
    >
    }
    >
    </code>
    >
    When the mouse is pressed while over one of the splitters it call the
    OnMouseDown event.
    >
    Then it needs to wait until the user releases the mouse button before
    re locating the splitter to the new position.
    >
    The problem I have is that I don’t know how to obtain the mouse
    coordinates when the mouse leaves the area of the splitter when the
    mouse moves over one of the containers panels within the container the
    mouse events are no longer called.
    >
    Am I thinking completely wrong by thinking about a loop within the
    OnMouseDown event and if so could anybody point me in the write
    direction.
    Yes, you are. If you do that, you block the event loop from processing
    new events. What you should do instead is set some bool flag in
    MouseDown and return immediately, then provide appropriate handlers
    for MouseMove (where you check for the flag and drag the splitter if
    the flag is set), and MouseUp (where you reset the flag).

    You do not need to do anything to receive MouseMove/MouseUp events
    after you've handled MouseDown - WinForms automatically "captures" the
    mouse in MouseDown. However, should you need to control this manually,
    have a look at Control.Capture property.

    Comment

    • Jay Dee

      #3
      Re: Creating custom container controls

      Fantastic, after reading your response it took me about 2 mints to
      make it work.

      Thank you

      <code>

      private bool verticalSplitte r1Move;
      private bool verticalSplitte r2Move;
      private bool horizontalSplit ter1Move;
      private bool horizontalSplit ter2Move;

      protected override void OnMouseDown(Mou seEventArgs e)
      {
      base.OnMouseDow n(e);

      if (e.Button == MouseButtons.Le ft)
      {
      // Move VerticalSplitte r1
      if (e.X this.VerticalSp litter1Position -
      (this.splitterT hicknes / 2) &&
      e.X < this.VerticalSp litter1Position +
      (this.splitterT hicknes / 2))
      {
      this.verticalSp litter1Move = true;
      }
      // Move VerticalSplitte r2
      if (e.X this.VerticalSp litter2Position -
      (this.splitterT hicknes / 2) &&
      e.X < this.VerticalSp litter2Position +
      (this.splitterT hicknes / 2))
      {
      this.verticalSp litter2Move = true;
      }
      // Move HorizontalSplit ter1
      if (e.Y this.Horizontal Splitter1Positi on -
      (this.splitterT hicknes / 2) &&
      e.Y < this.Horizontal Splitter1Positi on +
      (this.splitterT hicknes / 2))
      {
      this.horizontal Splitter1Move = true;
      }
      // Move HorizontalSplit ter2
      if (e.Y this.Horizontal Splitter2Positi on -
      (this.splitterT hicknes / 2) &&
      e.Y < this.Horizontal Splitter2Positi on +
      (this.splitterT hicknes / 2))
      {
      this.horizontal Splitter2Move = true;
      }
      }
      }

      protected override void OnMouseMove(Mou seEventArgs e)
      {
      base.OnMouseMov e(e);

      if (this.verticalS plitter1Move) this.VerticalSp litter1Position =
      e.X;
      if (this.verticalS plitter2Move) this.VerticalSp litter2Position =
      e.X;
      if (this.horizonta lSplitter1Move) this.Horizontal Splitter1Positi on
      = e.Y;
      if (this.horizonta lSplitter2Move) this.Horizontal Splitter2Positi on
      = e.Y;
      }

      protected override void OnMouseUp(Mouse EventArgs e)
      {
      base.OnMouseUp( e);

      this.verticalSp litter1Move = false;
      this.verticalSp litter2Move = false;
      this.horizontal Splitter1Move = false;
      this.horizontal Splitter2Move = false;
      }

      </code>

      Comment

      Working...