C # ToolStrip make four sides docked floating toolbar

Source: Internet
Author: User

  This article mainly introduces the production of C # ToolStrip floating toolbar, can dock up/down/left/right, the code below

About the production of floating bar   In fact, the code given by Atzie is quite detailed: I mainly give a rewrite of the ToolStrip code snippet, added three ToolStripPanel       code as follows:     public partial class Mytoolstrip:too Lstrip     {        public Mytoolstrip ()         {            InitializeComponent ();             this. EndDrag + = new EventHandler (Mytoolstrip_enddrag);             this. SizeChanged + = new EventHandler (mytoolstrip_sizechanged);        }           #region floating status           public to Olstripfloatwindow Floatwindow {get; set;}           private bool isfloating     &NBS P   {            get             {      &N Bsp         return (Floatwindow!= null);           &NBSP {       }           ToolStripPanel Toptoolstrippanel {get; set;} & nbsp       Public ToolStripPanel Bottomtoolstrippanel {get; set;}         public ToolStrip Panel Lefttoolstrippanel {get; set;}         public ToolStripPanel Righttoolstrippanel {get; set;}           #endregion           #region float implementation           private void Floatwindow_locationchanged (object sender, EventArgs e)         {    & nbsp      //When FLOATWINDWS position is moved to ToolStripPanel, this is placed on ToolStripPanel           &N Bsp if (this. Floatwindow = null)             {                R Eturn;                         if (floatwindow.hascreateD             {               //main form position   &NBS P             Point frmloc = this. TopToolStripPanel.Parent.Location;                //floating tool strip location                 Point toolbarloc = floatwindow.location;                   if (toolbarloc.y-frmloc.y <= 0)///Top Strippanel &nbsp ;               {                    T His. FloatWindow.Controls.Remove (this);                     this. Toptoolstrippanel.suspendlayout ();                     this. TOPTOOLSTRIPPANEL.CONTROLS.ADD (this);                     this. Location = this. ToptoolstrippaneL.pointtoclient (Toolbarloc);                     this. Toptoolstrippanel.resumelayout ();                     this. Floatwindow.dispose ();                     this. Floatwindow = null;                     return;                                 if (tool barloc.x-frmloc.x <= 0)//to left Strippanel                 {    &NBS P               this. FloatWindow.Controls.Remove (this);                     this. Lefttoolstrippanel.suspendlayout ();                     this. LEFTTOOLSTRIPPANEL.CONTROLS.ADD (this);         &NBsp           this. Location = this. Lefttoolstrippanel.pointtoclient (Toolbarloc);                     this. Lefttoolstrippanel.resumelayout ();                     this. Floatwindow.dispose ();                     this. Floatwindow = null;                     return;                                 if (tool barloc.x + floatwindow.width >= this. TopToolStripPanel.Parent.Width)//to the right Strippanel                 {    & nbsp               this. FloatWindow.Controls.Remove (this);                     this. Righttoolstrippanel.suspendlayout ();                    this. RIGHTTOOLSTRIPPANEL.CONTROLS.ADD (this);                     this. Location = this. Righttoolstrippanel.pointtoclient (Toolbarloc);                     this. Righttoolstrippanel.resumelayout ();                     this. Floatwindow.dispose ();                     this. Floatwindow = null;                     return;                                 if (tool Barloc.y + floatwindow.height >= this. TopToolStripPanel.Parent.Height)//At bottom Strippanel                 {                    this. FloatWindow.Controls.Remove (this);                     this. Bottomtoolstrippanel.suspendlayout ();                     this. BOTTOMTOOLSTRIPPANEL.CONTROLS.ADD (this);                     this. Location = this. Bottomtoolstrippanel.pointtoclient (Toolbarloc);                     this. Bottomtoolstrippanel.resumelayout ();                     this. Floatwindow.dispose ();                     this. Floatwindow = null;                     return;                            }        }           private void Mytoolstrip_enddrag (object sender, EventArgs e)     &N Bsp   {            Point screenpt = cursor.position             Po int clientpt = this. TopToolStripPanel.Parent.PointToClient (SCREENPT);              //floating area             Rectangle Floatarea = NE W Rectangle (   //) I have this icon resize to 32*32                 this. Toptoolstrippanel.parent.width-2 * 32,                  this. Toptoolstrippanel.parent.height-2 * 32);               if (Floatarea.contains (CLIENTPT))//Judgment shift time         &NB Sp   {                Toolstripfloatwindow fw = new Toolstripfloatwindow (); &nb Sp               FW. Controls.Add (this);                 this. left = 0;                 this. top = 0;                 this. Floatwindow = FW;                 floatwindow.locationchanged + = new EventHandler (floatwindow_locat ionchanged);                 FW. SetBounds (Screenpt.x, Screenpt.y, this.) Clientsize.width, this. Clientsize.height + 22); 22 for the form title bar height                   FW. Show ();             &NBSP,         {          Private void Mytoolstrip_sizechanged (object sender, EventArgs e)         {            if (this.isfloating)             {                this. Floatwindow.width = this. Clientsize.width;            }        }     &nbsp     #endregion      }  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.