C # Software Development example. Private Custom Screenshots Tool (11) Editing the toolbar implementation

Source: Internet
Author: User

All articles in this example directory (i) Overview of Functions (ii) Create a project, register a hotkey, Display main window (iii) Tray icon and menu implementation (iv) basic performance (v) optimization for flicker lag during drag-and-drop (vi) Add Configuration management function (vii) Add Magnifier function (eight) Add the function of the keyboard operation (ix) using the custom cursor, QQ when the cursor (10) contains the mouse pointer shape overview, sometimes we need to label, modify, etc., here is the implementation of the editing toolbar. Effect
Resources


About the idea. The picture of the toolbar contains the normal state and the selected state, drawing according to the state of the corresponding position of the picture to draw; The event method needs to respond to several events: The selection area ends, the toolbar is displayed, the focus state of the button is set when the mouse moves on the toolbar, and when the mouse is pressed on the toolbar,sets the focus state of the button;interface Elements
Here I use the Label control to display the toolbar;Use the Panel control to display the tool's settings and palette;Related Code Initialization toolbar
        <summary>///        Windows Load event handlers///</summary>//        <param name= "Sender" ></param>        //<param name= "E" ></param>        private void Form1_Load (object sender, EventArgs e)        {            This.lbl_ToolBox.Size = new Size (Properties.Resources.ToolsBox.Size.Width, 26);//set size            This.lbl_ Toolbox.visible = false;//not displayed by default        }
Show toolbars
        <summary>///Window mouse lift event handlers///</summary>//<param name= "Sender" ><  /param>//<param name= "E" ></param> private void Form1_mouseup (object sender, MouseEventArgs                     e) {if (E.button = = MouseButtons.Left) {if (this.iscuting) {                    This.iscuting = false;                        If the area of the Autodiscover window is not empty, the user selects the area of the Autodiscover window if (!rect_windowfrompoint.isempty) { Savecutimagesize (Rect_windowfrompoint.location, New Point (Rect_windowfrompoint.right-1, Rect_windowfrompoint .                    BOTTOM-1)); } if (this.                        toolboxvisible) {this.lbl_ToolBox.Show (); Send mouse down and lift events to the toolbar, set default entry rectangle edit state MouseEventArgs arg = new MouseEventArgs (MouseButtons.Left, 1, 15, 15                        , 0); This.lBl_toolbox_mousedown (This.lbl_toolbox, ARG);                    This.lbl_toolbox_mouseup (This.lbl_toolbox, ARG); } this.picturebox_zoom.                    Hide ();                    This.lastmousemovetime = 0;                Updatecutinfolabel (Updateuimode.none); }            }        }
        <summary>///width of toolbar buttons///</summary> private int[] toolboxswidth = new int[]        {22, 22, 22, 22, 22, 22, 22, 22, 35, 22, 54}; <summary>////Tool Style button left margin///</summary> private int[] Toolboxsleft = new int[] {7,        33, 59, 85, 111, 137, 171, 197, 223, 268, 294}; <summary>///toolbar button prompt information///</summary> private string[] Toolboxstip = new string[] {        "Rectangle tool", "Ellipse tool", "Arrow Tool", "Paint brush Tool", "type Tool", "tooltip Tool", "Undo Edit", "save", "Upload", "Exit", "Finish"}; <summary>///toolbar drawing event Handlers///</summary>//<param name= "Sender" ></param&gt        ;            <param name= "E" ></param> private void Lbl_toolbox_paint (object sender, PaintEventArgs e) {            Bitmap bmp_lbl = new Bitmap (e.cliprectangle.width, e.cliprectangle.height);            Graphics g = graphics.fromimage (BMP_LBL); G.drawimage (PROPERTIES.RESOURCEs.            Toolsbox, E.cliprectangle, E.cliprectangle, GraphicsUnit.Pixel);            BOOL Tipflag = false; for (int i = 0; i < toolboxsleft.length; i++) {Rectangle fcs_rect = new Rectangle (toolboxsle                Ft[i], 3, toolboxswidth[i], toolheight);                Rectangle sld_rect = new Rectangle (Toolboxsleft[i], toolboxswidth[i], toolheight); if (Fcs_rect.contains (this.mousedowntoolboxlocation)) {G.drawimage (properties.resources .                Toolsbox, Fcs_rect, Sld_rect, GraphicsUnit.Pixel);                    } else {if (Fcs_rect.contains (this.mouseintoolboxlocation))                    {G.drawimage (Properties.Resources.ToolsBox, Fcs_rect, Sld_rect, GraphicsUnit.Pixel);                    }}//If the Rectangle tool is selected, the icon for the button is drawn according to the sub-type if (i = = 0) { Rectangle src_rect = new Rectangle (0,0, 22, 20);                        Draw the tool button's background if (Fcs_rect.contains (this.mousedowntoolboxlocation)) {                    G.drawimage (Properties.Resources.ToolBox_Selected, Fcs_rect, Src_rect, GraphicsUnit.Pixel);                        } else {if (Fcs_rect.contains (this.mouseintoolboxlocation))  {G.drawimage (Properties.Resources.ToolBox_Selected, Fcs_rect, Src_rect,                        GraphicsUnit.Pixel); } else {g.drawimage (Properties.Resources.ToolBox                        _normal, Fcs_rect, Src_rect, GraphicsUnit.Pixel);                     }} Rectangle Dst_rect = new Rectangle (Fcs_rect.left + 3, Fcs_rect.top + 2, 16, 16);                    Src_rect = new Rectangle (0, 0, 16, 16); Draws the icon of the button based on the subtype switch (thIs.imagesubeditmode) {case Imagesubeditmode.rectangle:                            G.drawimage (Properties.Resources.Icon_Rectangle, Dst_rect, Src_rect, GraphicsUnit.Pixel);                        Break Case Imagesubeditmode.circularrectangle:g.drawimage (Properties.Resources.Icon_Circular, Dst_re                            CT, Src_rect, graphicsunit.pixel);                        break;; Case Imagesubeditmode.ellipse:g.drawimage (Properties.Resources.Icon_Ellipse, Dst_rect, Src_rec                            T, GraphicsUnit.Pixel);                        Break Case Imagesubeditmode.arrowhead:g.drawimage (Properties.Resources.Icon_Arrowhead, Dst_rect, SRC                            _rect, GraphicsUnit.Pixel);                        Break                    Default:break; }//Draw triangle block Rectangle dstrect_sAnjiaokuai = new Rectangle (fcs_rect.left + fcs_rect.top + 15, 5, 3);                    Rectangle Srcrect_sanjiaokuai = new Rectangle (0, 0, 5, 3);                G.drawimage (Properties.Resources.SanJiaoKuai, Dstrect_sanjiaokuai, Srcrect_sanjiaokuai, GraphicsUnit.Pixel); }                //==================================================================================================== ==========//If the prompt tool is selected, the icon for the button is drawn according to the subtype if (i = = 5) {Rectan                    GLE src_rect = new Rectangle (0, 0, 22, 20);                        Draw the tool button's background if (Fcs_rect.contains (this.mousedowntoolboxlocation)) {                    G.drawimage (Properties.Resources.ToolBox_Selected, Fcs_rect, Src_rect, GraphicsUnit.Pixel);                        } else {if (Fcs_rect.contains (this.mouseintoolboxlocation))                {            G.drawimage (Properties.Resources.ToolBox_Selected, Fcs_rect, Src_rect, GraphicsUnit.Pixel); } else {g.drawimage (properties.resources.t                        Oolbox_normal, Fcs_rect, Src_rect, GraphicsUnit.Pixel);                     }} Rectangle Dst_rect = new Rectangle (Fcs_rect.left + 3, Fcs_rect.top + 2, 16, 16);                    Src_rect = new Rectangle (0, 0, 16, 16); Icon for drawing buttons according to subtypes switch (this.imagesubeditmode) {case Imagesub Editmode.rectangle:g.drawimage (Properties.Resources.Icon_ToolTips, Dst_rect, Src_rect, Graphic                            Sunit.pixel);                        Break Case Imagesubeditmode.circularrectangle:g.drawimage (Properties.Resources.Icon_ToolTips, Dst_re      CT, Src_rect, graphicsunit.pixel);                      break;; Case Imagesubeditmode.ellipse:g.drawimage (Properties.Resources.Icon_ToolTips, Dst_rect, src_re                            CT, graphicsunit.pixel);                        Break Case Imagesubeditmode.arrowhead:g.drawimage (Properties.Resources.Icon_ToolTips, Dst_rect, src_                            Rect, GraphicsUnit.Pixel);                        Break                    Default:break; }//Draw triangle block Rectangle Dstrect_sanjiaokuai = new Rectangle (Fcs_rect.left + fcs_rect .                    Top + 15, 5, 3);                    Rectangle Srcrect_sanjiaokuai = new Rectangle (0, 0, 5, 3);                G.drawimage (Properties.Resources.SanJiaoKuai, Dstrect_sanjiaokuai, Srcrect_sanjiaokuai, GraphicsUnit.Pixel); }                //====================================================================================================           ==========     if (Fcs_rect.contains (this.mouseintoolboxlocation)) {This.toolTip1.SetToolTip (this                    . Lbl_toolbox, Toolboxstip[i]);                Tipflag = true;            }} if (!tipflag) {This.toolTip1.SetToolTip (This.lbl_toolbox, "");            } e.graphics.drawimage (bmp_lbl, 0, 0);            G.dispose (); Bmp_lbl.        Dispose (); }

Summary of the main use of the technology: Area Mapping, button polymorphism, editing state;

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

C # Software Development example. Private custom-made screen tools (11) Editing the toolbar

Related Article

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.