实现功能:
大写GUID字符,
为GUID字符串加{},
其他功能:
自动复制到剪切板,
总之最前显示。
对于后两个功能,感觉很好使,因为在全屏打开vs或者sql server时,可以不需要切换程序,
自动复制到剪切板自然是很方便的功能,考虑到可能会覆盖剪切板中的重要内容,所以该功能是可选的。
附上源代码:
Form1.Designer.cs
namespace Eyuan.GUIDGenerator
{
partial class fmGUIDGenerator
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.txtGUID = new System.Windows.Forms.TextBox();
this.btnGenerator = new System.Windows.Forms.Button();
this.btnCopy = new System.Windows.Forms.Button();
this.cbUppercase = new System.Windows.Forms.CheckBox();
this.cbBraceSurround = new System.Windows.Forms.CheckBox();
this.cbAlwaysVisible = new System.Windows.Forms.CheckBox();
this.cbAutoCopy = new System.Windows.Forms.CheckBox();
this.SuspendLayout();
//
// txtGUID
//
this.txtGUID.Location = new System.Drawing.Point(4, 5);
this.txtGUID.Name = "txtGUID";
this.txtGUID.Size = new System.Drawing.Size(236, 21);
this.txtGUID.TabIndex = 1;
//
// btnGenerator
//
this.btnGenerator.Location = new System.Drawing.Point(4, 41);
this.btnGenerator.Name = "btnGenerator";
this.btnGenerator.Size = new System.Drawing.Size(75, 23);
this.btnGenerator.TabIndex = 2;
this.btnGenerator.Text = "生成(&G)";
this.btnGenerator.UseVisualStyleBackColor = true;
this.btnGenerator.Click += new System.EventHandler(this.btnGenerator_Click);
//
// btnCopy
//
this.btnCopy.Location = new System.Drawing.Point(163, 40);
this.btnCopy.Name = "btnCopy";
this.btnCopy.Size = new System.Drawing.Size(75, 23);
this.btnCopy.TabIndex = 3;
this.btnCopy.Text = "复制(&C)";
this.btnCopy.UseVisualStyleBackColor = true;
//
// cbUppercase
//
this.cbUppercase.AutoSize = true;
this.cbUppercase.Location = new System.Drawing.Point(4, 80);
this.cbUppercase.Name = "cbUppercase";
this.cbUppercase.Size = new System.Drawing.Size(48, 16);
this.cbUppercase.TabIndex = 4;
this.cbUppercase.Text = "大写";
this.cbUppercase.UseVisualStyleBackColor = true;
this.cbUppercase.CheckedChanged += new System.EventHandler(this.cbUppercase_CheckedChanged);
//
// cbBraceSurround
//
this.cbBraceSurround.AutoSize = true;
this.cbBraceSurround.Location = new System.Drawing.Point(116, 80);
this.cbBraceSurround.Name = "cbBraceSurround";
this.cbBraceSurround.Size = new System.Drawing.Size(48, 16);
this.cbBraceSurround.TabIndex = 5;
this.cbBraceSurround.Text = "加{}";
this.cbBraceSurround.UseVisualStyleBackColor = true;
this.cbBraceSurround.CheckedChanged += new System.EventHandler(this.cbBraceSurround_CheckedChanged);
//
// cbAlwaysVisible
//
this.cbAlwaysVisible.AutoSize = true;
this.cbAlwaysVisible.Location = new System.Drawing.Point(4, 104);
this.cbAlwaysVisible.Name = "cbAlwaysVisible";
this.cbAlwaysVisible.Size = new System.Drawing.Size(72, 16);
this.cbAlwaysVisible.TabIndex = 6;
this.cbAlwaysVisible.Text = "显示最前";
this.cbAlwaysVisible.UseVisualStyleBackColor = true;
this.cbAlwaysVisible.CheckedChanged += new System.EventHandler(this.cbAlwaysVisible_CheckedChanged);
//
// cbAutoCopy
//
this.cbAutoCopy.AutoSize = true;
this.cbAutoCopy.Location = new System.Drawing.Point(114, 103);
this.cbAutoCopy.Name = "cbAutoCopy";
this.cbAutoCopy.Size = new System.Drawing.Size(120, 16);
this.cbAutoCopy.TabIndex = 7;
this.cbAutoCopy.Text = "自动复制到剪切板";
this.cbAutoCopy.UseVisualStyleBackColor = true;
this.cbAutoCopy.CheckedChanged += new System.EventHandler(this.cbAutoCopy_CheckedChanged);
//
// fmGUIDGenerator
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(243, 121);
this.Controls.Add(this.cbAutoCopy);
this.Controls.Add(this.cbAlwaysVisible);
this.Controls.Add(this.cbBraceSurround);
this.Controls.Add(this.cbUppercase);
this.Controls.Add(this.btnCopy);
this.Controls.Add(this.btnGenerator);
this.Controls.Add(this.txtGUID);
this.Name = "fmGUIDGenerator";
this.Text = "GUID生成器";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.TextBox txtGUID;
private System.Windows.Forms.Button btnGenerator;
private System.Windows.Forms.Button btnCopy;
private System.Windows.Forms.CheckBox cbUppercase;
private System.Windows.Forms.CheckBox cbBraceSurround;
private System.Windows.Forms.CheckBox cbAlwaysVisible;
private System.Windows.Forms.CheckBox cbAutoCopy;
}
}
Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Eyuan.GUIDGenerator
{
public partial class fmGUIDGenerator : Form
{
#region 字段
string strGUID = string.Empty;
bool isUppercase = false;
bool isBraceSurround = false;
bool isAutoCopy = false;
#endregion
public fmGUIDGenerator()
{
InitializeComponent();
txtGUID.ReadOnly = true;
}
/// <summary>
/// 生成GUID
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnGenerator_Click(object sender, EventArgs e)
{
strGUID = GenerateGUID();
if (isAutoCopy)
{
Clipboard.SetText(strGUID, TextDataFormat.Text);
}
txtGUID.Text = strGUID;
}
/// <summary>
/// 返回指定格式的的GUID字符串
/// </summary>
/// <returns></returns>
private string GenerateGUID()
{
string sGUID = System.Guid.NewGuid().ToString();
if (isBraceSurround)
{
sGUID = "{" + sGUID + "}";
}
if (isUppercase)
{
sGUID = sGUID.ToUpper();
}
return sGUID;
}
#region bool变量设置
private void cbUppercase_CheckedChanged(object sender, EventArgs e)
{
isUppercase = cbUppercase.Checked;
}
private void cbBraceSurround_CheckedChanged(object sender, EventArgs e)
{
isBraceSurround = cbBraceSurround.Checked;
}
private void cbAlwaysVisible_CheckedChanged(object sender, EventArgs e)
{
this.TopMost = cbAlwaysVisible.Checked;
}
private void cbAutoCopy_CheckedChanged(object sender, EventArgs e)
{
isAutoCopy = cbAutoCopy.Checked;
}
#endregion
/// <summary>
/// 手动复制到剪贴板
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnCopy_Click(object sender, EventArgs e)
{
Clipboard.SetText(strGUID, TextDataFormat.Text);
}
}
}
截图:
源代码下载:
http://download.csdn.net/detail/eyuanatqqdotcom/4269926
小弟.net刚刚入门,希望结识一些朋友,互相学习,共同进步。
Email:e_yuan@foxmail.com
QQ:373048914