/// <summary> /// 窗口加载事件处理程序 /// </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);//设置大小 this.lbl_ToolBox.Visible = false;//默认不显示 }
/// <summary> /// 截图窗口鼠标抬起事件处理程序 /// </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 (!rect_WindowFromPoint.IsEmpty) { SaveCutImageSize(rect_WindowFromPoint.Location, new Point(rect_WindowFromPoint.Right - 1, rect_WindowFromPoint.Bottom -1)); } if (this.ToolBoxVisible) { this.lbl_ToolBox.Show(); //向工具栏发送鼠标按下和抬起事件,设置默认进入矩形编辑状态 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> /// 工具栏按钮的宽度 /// </summary> private int[] toolBoxsWidth = new int[] { 22, 22, 22, 22, 22, 22, 22, 22, 35, 22, 54 }; /// <summary> /// 工具样式按钮的左侧边距 /// </summary> private int[] toolBoxsLeft = new int[] { 7, 33, 59, 85, 111, 137, 171, 197, 223, 268, 294 }; /// <summary> /// 工具栏按钮提示信息 /// </summary> private string[] toolBoxsTip = new string[] { "矩形工具", "椭圆工具", "箭头工具", "画刷工具", "文字工具", "提示工具", "撤消编辑", "保存截图", "上传截图", "退出截图", "完成截图" }; /// <summary> /// 工具栏绘制事件处理程序 /// </summary> /// <param name="sender"></param> /// <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(toolBoxsLeft[i], 3, toolBoxsWidth[i], toolHeight); Rectangle sld_Rect = new Rectangle(toolBoxsLeft[i], 29, 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 (i == 0) { Rectangle src_Rect = new Rectangle(0, 0, 22, 20); //绘制工具按钮的背景 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); //根据子类型绘制按钮的图标 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_Rect, src_Rect, GraphicsUnit.Pixel); break; ; case ImageSubEditMode.Ellipse: g.DrawImage(Properties.Resources.Icon_Ellipse, dst_Rect, src_Rect, GraphicsUnit.Pixel); break; case ImageSubEditMode.Arrowhead: g.DrawImage(Properties.Resources.Icon_Arrowhead, dst_Rect, src_Rect, GraphicsUnit.Pixel); break; default: break; } //绘制三角块 Rectangle dstRect_SanJiaoKuai = new Rectangle(fcs_Rect.Left + 15, 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 (i == 5) { Rectangle src_Rect = new Rectangle(0, 0, 22, 20); //绘制工具按钮的背景 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); //根据子类型绘制按钮的图标 switch (this.imageSubEditMode) { case ImageSubEditMode.Rectangle: g.DrawImage(Properties.Resources.Icon_ToolTips, dst_Rect, src_Rect, GraphicsUnit.Pixel); break; case ImageSubEditMode.CircularRectangle: g.DrawImage(Properties.Resources.Icon_ToolTips, dst_Rect, src_Rect, GraphicsUnit.Pixel); break; ; case ImageSubEditMode.Ellipse: g.DrawImage(Properties.Resources.Icon_ToolTips, dst_Rect, src_Rect, GraphicsUnit.Pixel); break; case ImageSubEditMode.Arrowhead: g.DrawImage(Properties.Resources.Icon_ToolTips, dst_Rect, src_Rect, GraphicsUnit.Pixel); break; default: break; } //绘制三角块 Rectangle dstRect_SanJiaoKuai = new Rectangle(fcs_Rect.Left + 15, 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(); }
版权声明:本文为博主原创文章,未经博主允许不得转载。
C#软件开发实例.私人订制自己的屏幕截图工具(十一)编辑工具栏的实现
原文地址:http://blog.csdn.net/testcs_dn/article/details/49079127