实例介绍
【实例简介】
为编程提供便捷方式,
加入历史剪切板和常用正则!
未完善【自定义安卓库】
打算写一个联网的有兴趣的可以联系我!qq:481869314
【实例截图】
【核心代码】
using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace 编程工具箱 { //猫九先森QQ:481869314可以一起写一个我联网的哦!有兴趣联系我! public partial class Form1 : Form { int tp = 0; ArrayList jqb = new ArrayList(); string st = Clipboard.GetText(); public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { timer1.Start(); FormDock a = new FormDock(this); } #region 取色器 [DllImport("user32.dll")]//取设备场景 private static extern IntPtr GetDC(IntPtr hwnd);//返回设备场景句柄 [DllImport("gdi32.dll")]//取指定点颜色 private static extern int GetPixel(IntPtr hdc, Point p); private void timer1_Tick(object sender, EventArgs e) { Point p = new Point(MousePosition.X, MousePosition.Y);//取置顶点坐标 label1.Text ="当前鼠标坐标:" "X:" p.X "Y:" p.Y;//把坐标显示到窗口上 IntPtr hdc = GetDC(new IntPtr(0));//取到设备场景(0就是全屏的设备场景) int c = GetPixel(hdc, p);//取指定点颜色 int r = (c & 0xFF);//转换R int g = (c & 0xFF00) / 256;//转换G int b = (c & 0xFF0000) / 65536;//转换B textBox1.Text = c.ToString();//输出10进制颜色 textBox2.Text ="#" r.ToString("x").PadLeft(2, '0') g.ToString("x").PadLeft(2, '0') b.ToString("x").PadLeft(2, '0');//输出16进制颜色 textBox3.Text = r.ToString() ',' g.ToString() ',' b.ToString();//输出RGB pictureBox1.BackColor = Color.FromArgb(r, g, b);//设置颜色框 } private void button1_Click(object sender, EventArgs e) { colorDialog1.ShowDialog(); } #endregion #region 快捷按钮 private void button2_Click(object sender, EventArgs e) { try { //远程桌面 System.Diagnostics.Process.Start("mstsc.exe"); } catch { MessageBox.Show("系统找不到指定的程序文件", "错误提示!"); return; } } private void button3_Click(object sender, EventArgs e) { try { //计算器 System.Diagnostics.Process.Start("calc.exe"); } catch { MessageBox.Show("系统找不到指定的程序文件", "错误提示!"); return; } } private void button4_Click(object sender, EventArgs e) { try { //记事本 System.Diagnostics.Process.Start("notepad.exe"); } catch { MessageBox.Show("系统找不到指定的程序文件", "错误提示!"); return; } } private void button5_Click(object sender, EventArgs e) { try { //CMD System.Diagnostics.Process.Start("cmd.exe"); } catch { MessageBox.Show("系统找不到指定的程序文件", "错误提示!"); return; } } private void button7_Click(object sender, EventArgs e) { try { string path = null; OpenFileDialog opf = new OpenFileDialog(); opf.Filter = "JPG|*.jpg|PNG|*.png|GIF|*.gif"; if (opf.ShowDialog() == DialogResult.OK) path = opf.FileName; Bitmap pbm = new Bitmap(path); this.BackgroundImage = pbm; } catch { } } private void button8_Click(object sender, EventArgs e) { string character; character = textASCII.Text; try { if (character.Length == 1) { ASCIIEncoding asciiEncoding = new System.Text.ASCIIEncoding(); int intAsciiCode = (int)asciiEncoding.GetBytes(character)[0]; textBox4.Text="ASCII:" intAsciiCode.ToString(); } else { throw new Exception("Character is not valid."); } } catch { MessageBox.Show("转换失败请输入一个合法字符!","系统提示:"); } } private void button6_Click(object sender, EventArgs e) { //创建图象,保存将来截取的图象 Bitmap image = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height); Graphics imgGraphics = Graphics.FromImage(image); //设置截屏区域 imgGraphics.CopyFromScreen(0, 0, 0, 0, new Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height)); //保存 image.Save(tp ".jpg"); } #endregion #region 桌面停靠 /// <summary> /// 窗口停靠隐藏类 /// 使用方法 /// private FormDock formDock = null; /// formDock = new FormDock(this,300); /// </summary> public class FormDock { #region 自定义声明 /// <summary> /// 定义计时器 /// </summary> private Timer StopRectTimer = new Timer(); /// <summary> /// 贴边设置 /// </summary> internal AnchorStyles StopAanhor = AnchorStyles.None; /// <summary> /// 父级窗口实例 /// </summary> private Form parentForm = null; private Point m_TempPoiont;//临时点位置 private Point m_LastPoint;//窗体最小化前的坐标点位置 #endregion #region 构造函数 /// <summary> /// 自动停靠 /// </summary> /// <param name="frmParent">父窗口对象</param> public FormDock(Form frmParent) { parentForm = frmParent; parentForm.LocationChanged = new EventHandler(parentForm_LocationChanged); StopRectTimer.Tick = new EventHandler(timer1_Tick); //注册事件 StopRectTimer.Interval = 500; //计时器执行周期 StopRectTimer.Start(); //计时器开始执行 } /// <summary> /// 自动停靠 /// </summary> /// <param name="frmParent">父窗口对象</param> /// <param name="_trimInterval">时钟周期</param> public FormDock(Form frmParent, int _trimInterval) { parentForm = frmParent; parentForm.LocationChanged = new EventHandler(parentForm_LocationChanged); StopRectTimer.Tick = new EventHandler(timer1_Tick); //注册事件 StopRectTimer.Interval = _trimInterval; //计时器执行周期 StopRectTimer.Start(); //计时器开始执行 } #endregion /// <summary> /// 时钟的开始 /// </summary> public void TimerStart() { StopRectTimer.Start(); } /// <summary> /// 时钟的停止 /// </summary> public void TimerStop() { StopRectTimer.Stop(); } #region 窗口位置改变事件 /// <summary> /// 窗口位置改变事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void parentForm_LocationChanged(object sender, EventArgs e) { if (parentForm.Location.X == -32000 && parentForm.Location.Y == -32000) { m_LastPoint = m_TempPoiont;//最小化了,m_LastPoint就是最小化前的位置。 } else { m_TempPoiont = parentForm.Location; } this.mStopAnthor(); } #endregion #region 计时器 周期事件 /// <summary> /// 计时器 周期事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void timer1_Tick(object sender, EventArgs e) { if (parentForm.Bounds.Contains(Cursor.Position)) { this.FormShow(); } else { this.FormHide(); } } #endregion #region 窗口停靠位置计算 /// <summary> /// 窗口停靠位置计算 /// </summary> private void mStopAnthor() { if (parentForm.Top <= 0) { StopAanhor = AnchorStyles.Top; } else if (parentForm.Left <= 0) { StopAanhor = AnchorStyles.Left; } else if (parentForm.Left >= Screen.PrimaryScreen.Bounds.Width - parentForm.Width) { StopAanhor = AnchorStyles.Right; } else { StopAanhor = AnchorStyles.None; } } #endregion #region 窗体不贴边显示 /// <summary> /// 窗体不贴边显示 /// </summary> public void FormShow() { switch (this.StopAanhor) { case AnchorStyles.Top: parentForm.Location = new Point(parentForm.Location.X, 0); break; case AnchorStyles.Left: parentForm.Location = new Point(0, parentForm.Location.Y); break; case AnchorStyles.Right: parentForm.Location = new Point(Screen.PrimaryScreen.Bounds.Width - parentForm.Width, parentForm.Location.Y); break; } } #endregion #region 窗体贴边隐藏 /// <summary> /// 窗体贴边隐藏 /// </summary> private void FormHide() { switch (this.StopAanhor) { case AnchorStyles.Top: if (parentForm.WindowState == FormWindowState.Minimized) { parentForm.Location = this.m_LastPoint; break; } parentForm.Location = new Point(parentForm.Location.X, (parentForm.Height - 2) * (-1)); break; case AnchorStyles.Left: parentForm.Location = new Point((-1) * (parentForm.Width - 2), parentForm.Location.Y); break; case AnchorStyles.Right: parentForm.Location = new Point(Screen.PrimaryScreen.Bounds.Width - 2, parentForm.Location.Y); break; } } #endregion } #endregion #region 常用正则匹配 private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { int i; i = comboBox1.SelectedIndex; switch (i) { case 0: Clipboard.SetDataObject(@"\w[-\w. ]*@([A-Za-z0-9][-A-Za-z0-9] \.) [A-Za-z]{2,14}"); MessageBox.Show(@"内容为:\w[-\w. ]*@([A-Za-z0-9][-A-Za-z0-9] \.) [A-Za-z]{2,14}","已复制到粘贴板"); break; case 1: Clipboard.SetDataObject(@"[\u4e00-\u9fa5]"); MessageBox.Show(@"内容为:[\u4e00-\u9fa5]", "已复制到粘贴板"); break; case 2: Clipboard.SetDataObject(@"[^\x00-\xff]"); MessageBox.Show(@"内容为:[^\x00-\xff]", "已复制到粘贴板"); break; case 3: Clipboard.SetDataObject(@"([01]?\d|2[0-3]):[0-5]?\d:[0-5]?\d"); MessageBox.Show(@"内容为:([01]?\d|2[0-3]):[0-5]?\d:[0-5]?\d", "已复制到粘贴板"); break; case 4: Clipboard.SetDataObject(@"(\d )\.(\d )\.(\d )\.(\d )"); MessageBox.Show(@"内容为:(\d )\.(\d )\.(\d )\.(\d )", "已复制到粘贴板"); break; case 5: Clipboard.SetDataObject(@"\d{17}[0-9Xx]|\d{15}"); MessageBox.Show(@"内容为:\d{17}[0-9Xx]|\d{15}", "已复制到粘贴板"); break; case 6: Clipboard.SetDataObject(@"(([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))-02-29)"); MessageBox.Show(@"内容为:(([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))-02-29)", "已复制到粘贴板"); break; case 7: Clipboard.SetDataObject(@"[1-9]\d*"); MessageBox.Show(@"内容为:[1-9]\d*", "已复制到粘贴板"); break; case 8: Clipboard.SetDataObject(@"-[1-9]\d*"); MessageBox.Show(@"内容为:-[1-9]\d*", "已复制到粘贴板"); break; case 9: Clipboard.SetDataObject(@"(13\d|14[57]|15[^4,\D]|17[13678]|18\d)\d{8}|170[0589]\d{7}"); MessageBox.Show(@"内容为:(13\d|14[57]|15[^4,\D]|17[13678]|18\d)\d{8}|170[0589]\d{7}", "已复制到粘贴板"); break; default: break; } } #endregion #region 历史剪切板 private void button9_Click(object sender, EventArgs e) { if (button9.Text == "清除历史剪切板") { timer2.Stop(); Clipboard.Clear(); jqb.Clear(); button9.Text = "开启历史剪切板"; } else if (button9.Text != "开启历史剪切板") { button9.Text = "清除历史剪切板"; timer2.Start(); } } private void timer2_Tick(object sender, EventArgs e) { string temp = Clipboard.GetText(); if (st !=temp ) { jqb.Add(temp); comboBox2.Items.Add(temp); st = temp; } } private void comboBox2_SelectedIndexChanged(object sender, EventArgs e) { int i; i = comboBox2.SelectedIndex; switch (i) { case 0: Clipboard.SetDataObject(comboBox2.SelectedItem); break; case 1: Clipboard.SetDataObject(comboBox2.SelectedItem); break; case 2: Clipboard.SetDataObject(comboBox2.SelectedItem); break; case 3: Clipboard.SetDataObject(comboBox2.SelectedItem); break; case 4: Clipboard.SetDataObject(comboBox2.SelectedItem); break; default: MessageBox.Show("当前只能截取前五个剪切板即将清空", "系统提示:"); jqb.Clear(); Clipboard.Clear(); comboBox2.Items.Clear(); break; } } #endregion private void button10_Click(object sender, EventArgs e) { android_kongjianku a = new android_kongjianku(); a.ShowDialog(); } } }
相关软件
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
网友评论
我要评论