这里写自定义目录标题
- 1. 工具栏: UcompToolStrip
- 1.1 展示效果
- 1.2 代码
- UcompToolStrip.cs
- UcompToolStrip.Designer.cs
1. 工具栏: UcompToolStrip
自定义一些Winform组件
1.1 展示效果
1)使用效果
2)控件事件
1.2 代码
- 设计
- 编码
UcompToolStrip.cs
public partial class UcompToolStrip : ToolStrip
{
// 定义委托类型
public delegate void AddEventHandler(object sender, EventArgs e);
public delegate void DeleteEventHandler(object sender, EventArgs e);
public delegate void EditEventHandler(object sender, EventArgs e);
public delegate void RefreshEventHandler(object sender, EventArgs e);
public delegate void QueryEventHandler(object sender, EventArgs e);
public delegate void QueryAdvEventHandler(object sender, EventArgs e);
// 定义事件
[Category("自定义事件")]
[Description("Button事件: 新增")]
public event AddEventHandler UcEventOnAdd;
[Category("自定义事件")]
[Description("Button事件: 删除")]
public event DeleteEventHandler UcEventOnDelete;
[Category("自定义事件")]
[Description("Button事件: 编辑")]
public event EditEventHandler UcEventOnEdit;
[Category("自定义事件")]
[Description("Button事件: 刷新")]
public event RefreshEventHandler UcEventOnRefresh;
[Category("自定义事件")]
[Description("Button事件: 查询")]
public event QueryEventHandler UcEventOnQuery;
[Category("自定义事件")]
[Description("Button事件: 高级查询")]
public event QueryAdvEventHandler UcEventOnQueryAdv;
public UcompToolStrip()
{
InitializeComponent();
}
public UcompToolStrip(IContainer container)
{
container.Add(this);
InitializeComponent();
}
// 为 ToolStripButton 添加 Click 事件处理程序
// 定义事件处理方法
private void tsbtnAdd_Click(object sender, EventArgs e)
{
// 调用自定义事件
UcEventOnAdd?.Invoke(this, e);
// 在这里编写按钮点击时的逻辑
//MessageBox.Show("新增");
}
private void tsbtnEdit_Click(object sender, EventArgs e)
{
// 调用自定义事件
UcEventOnEdit?.Invoke(this, e);
}
private void tsbtnDel_Click(object sender, EventArgs e)
{
// 调用自定义事件
UcEventOnDelete?.Invoke(this, e);
}
private void tsbtnRefresh_Click(object sender, EventArgs e)
{
// 调用自定义事件
UcEventOnRefresh?.Invoke(this, e);
}
private void tsbtnQuery_Click(object sender, EventArgs e)
{
// 调用自定义事件
UcEventOnQuery?.Invoke(this, e);
}
private void tsbtnQueryAdv_Click(object sender, EventArgs e)
{
// 调用自定义事件
UcEventOnQueryAdv?.Invoke(this, e);
}
}
UcompToolStrip.Designer.cs
...... 省略
this.toolStripSeparator2,
this.tsbtnQueryAdv});
this.Size = new System.Drawing.Size(100, 34);
this.ResumeLayout(false);
// 增加按钮事件
this.tsbtnAdd.Click += new System.EventHandler(this.tsbtnAdd_Click);
this.tsbtnEdit.Click += new System.EventHandler(this.tsbtnEdit_Click);
this.tsbtnDel.Click += new System.EventHandler(this.tsbtnDel_Click);
this.tsbtnRefresh.Click += new System.EventHandler(this.tsbtnRefresh_Click);
this.tsbtnQuery.Click += new System.EventHandler(this.tsbtnQuery_Click);
this.tsbtnQueryAdv.Click += new System.EventHandler(this.tsbtnQueryAdv_Click);
}
#endregion
private System.Windows.Forms.ToolStripButton tsbtnAdd;
private System.Windows.Forms.ToolStripButton tsbtnEdit;
private System.Windows.Forms.ToolStripButton tsbtnDel;
private System.Windows.Forms.ToolStripButton tsbtnRefresh;
private System.Windows.Forms.ToolStripButton tsbtnQuery;
private System.Windows.Forms.ToolStripButton tsbtnQueryAdv;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
private System.Windows.Forms.ToolStripLabel tslblKeyWord;
private System.Windows.Forms.ToolStripTextBox tstxtInputKeyword;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator2;