none
VC#的ToolStrip如何拖曳為一個獨立的視窗 RRS feed

  • 問題

  • 請問

    Toolstrip配合toolstripcontainer可以在視窗的上下左右拖曳,但如何拖曳成一個獨立的視窗,一般在Windows的軟體很常看到的功能。在BC++ builder中就是coolbar的功能。

    謝謝!

    2006年9月11日 上午 12:32

解答

  • 程式碼區塊
    public class FloatToolStrip : ToolStrip
    {
        public event EventHandler Undocked;
     
        protected override void OnMouseDown(MouseEventArgs mea)
        {
            if (this.GripRectangle.Contains(mea.Location))
            {              
                Point location = PointToScreen(Point.Empty);
     
                // For more control, this would be a custom form.
                // You could then event handlers that would react
                // when it is dragged to an edge, and redock it
                // automatically.
                floatForm = new Form();
                floatForm.StartPosition = FormStartPosition.Manual;
                floatForm.Owner = this.FindForm();
                Point pt = location;
                pt.Offset(5, 5);
                floatForm.Location = pt;
                floatForm.Text = this.Text;
                floatForm.FormBorderStyle =
                  FormBorderStyle.FixedToolWindow;
                floatForm.ClientSize = this.Size;
     
                // A control can be contained in only one form.
                // This moves
                // the ToolStrip out of the original form and 
                // into the floating form.
                floatForm.Controls.Add(this);
                floatForm.Show();
     
                // Raise the event to notify the form.
                if (Undocked != null) Undocked(this, EventArgs.Empty);
            }
            else
            {
                // Perform the normal mouse-click handling.
                base.OnMouseDown(mea);
            }
        }
     
        private Form floatForm;
        public Form FloatForm
        {
            get { return floatForm; }
        }
    }

     

     

     

    Source:

    http://en.csharp-online.net/Tool,_Menu,_and_Status_Strips%E2%80%94Floating_ToolStrips

     

     

    2007年12月7日 上午 04:29

所有回覆

  • 程式碼區塊
    public class FloatToolStrip : ToolStrip
    {
        public event EventHandler Undocked;
     
        protected override void OnMouseDown(MouseEventArgs mea)
        {
            if (this.GripRectangle.Contains(mea.Location))
            {              
                Point location = PointToScreen(Point.Empty);
     
                // For more control, this would be a custom form.
                // You could then event handlers that would react
                // when it is dragged to an edge, and redock it
                // automatically.
                floatForm = new Form();
                floatForm.StartPosition = FormStartPosition.Manual;
                floatForm.Owner = this.FindForm();
                Point pt = location;
                pt.Offset(5, 5);
                floatForm.Location = pt;
                floatForm.Text = this.Text;
                floatForm.FormBorderStyle =
                  FormBorderStyle.FixedToolWindow;
                floatForm.ClientSize = this.Size;
     
                // A control can be contained in only one form.
                // This moves
                // the ToolStrip out of the original form and 
                // into the floating form.
                floatForm.Controls.Add(this);
                floatForm.Show();
     
                // Raise the event to notify the form.
                if (Undocked != null) Undocked(this, EventArgs.Empty);
            }
            else
            {
                // Perform the normal mouse-click handling.
                base.OnMouseDown(mea);
            }
        }
     
        private Form floatForm;
        public Form FloatForm
        {
            get { return floatForm; }
        }
    }

     

     

     

    Source:

    http://en.csharp-online.net/Tool,_Menu,_and_Status_Strips%E2%80%94Floating_ToolStrips

     

     

    2007年12月7日 上午 04:29
  • 那麼我使用Toolstripcontainor,如何先可以得知使用者所拖放的目的地為Containor上還是要建立ToolWindow呢?

    我想制作與Office類同的拖放作業。

     

    2008年7月12日 上午 03:02