前提
入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章。
官网:https://www.hzhcontrols.cn
GitHub:https://github.com/kwwwvagaa/NetWinformControl
如果觉得写的还行,请点个 star 支持一下吧
目录
c#Winform自定义控件-目录_c#winform自定义控件-有图标的按钮-CSDN博客
准备工作
这个窗体继承子基类窗体FrmWithTitle,如果你对FrmWithTitle还不了解,请移步 (二十四)c#Winform自定义控件-单标题窗体 查看
开始
添加一个Form,命名FrmWithOKCancel2,继承FrmWithTitle
代码不多,直接上全部代码
// 版权所有 黄正辉 交流群:568015492 QQ:623128629
// 文件名称:FrmWithOKCancel2.cs
// 创建日期:2019-08-15 16:05:21
// 功能描述:FrmWithOKCancel2
// 项目地址:https://gitee.com/kwwwvagaa/net_winform_custom_control
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 HZH_Controls.Forms
{
[Designer("System.Windows.Forms.Design.ParentControlDesigner, System.Design", typeof(System.ComponentModel.Design.IDesigner))]
public partial class FrmWithOKCancel2 : FrmWithTitle
{
public FrmWithOKCancel2()
{
InitializeComponent();
}
private void btnOK_BtnClick(object sender, EventArgs e)
{
DoEnter();
}
private void btnCancel_BtnClick(object sender, EventArgs e)
{
DoEsc();
}
protected override void DoEnter()
{
this.DialogResult = System.Windows.Forms.DialogResult.OK;
}
private void FrmWithOKCancel2_VisibleChanged(object sender, EventArgs e)
{
}
}
}
namespace HZH_Controls.Forms
{
partial class FrmWithOKCancel2
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FrmWithOKCancel2));
this.panel2 = new System.Windows.Forms.Panel();
this.panel4 = new System.Windows.Forms.Panel();
this.panel5 = new System.Windows.Forms.Panel();
this.panel1 = new System.Windows.Forms.Panel();
this.ucSplitLine_V1 = new HZH_Controls.Controls.UCSplitLine_V();
this.btnOK = new HZH_Controls.Controls.UCBtnExt();
this.btnCancel = new HZH_Controls.Controls.UCBtnExt();
this.panel3 = new System.Windows.Forms.Panel();
this.ucSplitLine_H2 = new HZH_Controls.Controls.UCSplitLine_H();
this.panel2.SuspendLayout();
this.panel4.SuspendLayout();
this.panel5.SuspendLayout();
this.panel1.SuspendLayout();
this.SuspendLayout();
//
// panel2
//
this.panel2.Controls.Add(this.panel4);
this.panel2.Dock = System.Windows.Forms.DockStyle.Bottom;
this.panel2.Location = new System.Drawing.Point(0, 246);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(427, 64);
this.panel2.TabIndex = 5;
//
// panel4
//
this.panel4.Controls.Add(this.panel5);
this.panel4.Dock = System.Windows.Forms.DockStyle.Right;
this.panel4.Location = new System.Drawing.Point(227, 0);
this.panel4.Name = "panel4";
this.panel4.Size = new System.Drawing.Size(200, 64);
this.panel4.TabIndex = 0;
//
// panel5
//
this.panel5.Controls.Add(this.panel1);
this.panel5.Controls.Add(this.btnOK);
this.panel5.Controls.Add(this.btnCancel);
this.panel5.Dock = System.Windows.Forms.DockStyle.Bottom;
this.panel5.Location = new System.Drawing.Point(0, 0);
this.panel5.Name = "panel5";
this.panel5.Size = new System.Drawing.Size(200, 64);
this.panel5.TabIndex = 5;
//
// panel1
//
this.panel1.Controls.Add(this.ucSplitLine_V1);
this.panel1.Dock = System.Windows.Forms.DockStyle.Right;
this.panel1.Location = new System.Drawing.Point(99, 0);
this.panel1.Name = "panel1";
this.panel1.Padding = new System.Windows.Forms.Padding(0, 15, 0, 15);
this.panel1.Size = new System.Drawing.Size(1, 64);
this.panel1.TabIndex = 1;
//
// ucSplitLine_V1
//
this.ucSplitLine_V1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(232)))), ((int)(((byte)(232)))), ((int)(((byte)(232)))));
this.ucSplitLine_V1.Dock = System.Windows.Forms.DockStyle.Right;
this.ucSplitLine_V1.Location = new System.Drawing.Point(0, 15);
this.ucSplitLine_V1.Name = "ucSplitLine_V1";
this.ucSplitLine_V1.Padding = new System.Windows.Forms.Padding(0, 10, 0, 10);
this.ucSplitLine_V1.Size = new System.Drawing.Size(1, 34);
this.ucSplitLine_V1.TabIndex = 2;
this.ucSplitLine_V1.TabStop = false;
//
// btnOK
//
this.btnOK.BackColor = System.Drawing.Color.Transparent;
this.btnOK.BtnBackColor = System.Drawing.Color.Transparent;
this.btnOK.BtnFont = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnOK.BtnForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(77)))), ((int)(((byte)(59)))));
this.btnOK.BtnText = "确定";
this.btnOK.ConerRadius = 5;
this.btnOK.Cursor = System.Windows.Forms.Cursors.Hand;
this.btnOK.Dock = System.Windows.Forms.DockStyle.Fill;
this.btnOK.FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(247)))), ((int)(((byte)(247)))), ((int)(((byte)(247)))));
this.btnOK.Font = new System.Drawing.Font("微软雅黑", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel);
this.btnOK.IsRadius = false;
this.btnOK.IsShowRect = false;
this.btnOK.IsShowTips = false;
this.btnOK.Location = new System.Drawing.Point(0, 0);
this.btnOK.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.btnOK.Name = "btnOK";
this.btnOK.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(247)))), ((int)(((byte)(247)))), ((int)(((byte)(247)))));
this.btnOK.RectWidth = 1;
this.btnOK.Size = new System.Drawing.Size(100, 64);
this.btnOK.TabIndex = 0;
this.btnOK.TabStop = false;
this.btnOK.TipsText = "";
this.btnOK.BtnClick += new System.EventHandler(this.btnOK_BtnClick);
//
// btnCancel
//
this.btnCancel.BackColor = System.Drawing.Color.Transparent;
this.btnCancel.BtnBackColor = System.Drawing.Color.Transparent;
this.btnCancel.BtnFont = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnCancel.BtnForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(73)))), ((int)(((byte)(119)))), ((int)(((byte)(232)))));
this.btnCancel.BtnText = "取消";
this.btnCancel.ConerRadius = 5;
this.btnCancel.Cursor = System.Windows.Forms.Cursors.Hand;
this.btnCancel.Dock = System.Windows.Forms.DockStyle.Right;
this.btnCancel.FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(247)))), ((int)(((byte)(247)))), ((int)(((byte)(247)))));
this.btnCancel.Font = new System.Drawing.Font("微软雅黑", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel);
this.btnCancel.IsRadius = false;
this.btnCancel.IsShowRect = false;
this.btnCancel.IsShowTips = false;
this.btnCancel.Location = new System.Drawing.Point(100, 0);
this.btnCancel.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.btnCancel.Name = "btnCancel";
this.btnCancel.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(247)))), ((int)(((byte)(247)))), ((int)(((byte)(247)))));
this.btnCancel.RectWidth = 1;
this.btnCancel.Size = new System.Drawing.Size(100, 64);
this.btnCancel.TabIndex = 1;
this.btnCancel.TabStop = false;
this.btnCancel.TipsText = "";
this.btnCancel.BtnClick += new System.EventHandler(this.btnCancel_BtnClick);
//
// panel3
//
this.panel3.BackColor = System.Drawing.Color.White;
this.panel3.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel3.Location = new System.Drawing.Point(0, 61);
this.panel3.Name = "panel3";
this.panel3.Size = new System.Drawing.Size(427, 185);
this.panel3.TabIndex = 6;
//
// ucSplitLine_H2
//
this.ucSplitLine_H2.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(238)))), ((int)(((byte)(238)))), ((int)(((byte)(238)))));
this.ucSplitLine_H2.Dock = System.Windows.Forms.DockStyle.Bottom;
this.ucSplitLine_H2.Location = new System.Drawing.Point(0, 245);
this.ucSplitLine_H2.Name = "ucSplitLine_H2";
this.ucSplitLine_H2.Size = new System.Drawing.Size(427, 1);
this.ucSplitLine_H2.TabIndex = 7;
this.ucSplitLine_H2.TabStop = false;
//
// FrmWithOKCancel2
//
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
this.ClientSize = new System.Drawing.Size(427, 310);
this.Controls.Add(this.ucSplitLine_H2);
this.Controls.Add(this.panel3);
this.Controls.Add(this.panel2);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "FrmWithOKCancel2";
this.Text = "FrmWithOKCancel2";
this.VisibleChanged += new System.EventHandler(this.FrmWithOKCancel2_VisibleChanged);
this.Controls.SetChildIndex(this.panel2, 0);
this.Controls.SetChildIndex(this.panel3, 0);
this.Controls.SetChildIndex(this.ucSplitLine_H2, 0);
this.panel2.ResumeLayout(false);
this.panel4.ResumeLayout(false);
this.panel5.ResumeLayout(false);
this.panel1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Panel panel4;
private System.Windows.Forms.Panel panel5;
private Controls.UCSplitLine_V ucSplitLine_V1;
private Controls.UCBtnExt btnOK;
private Controls.UCBtnExt btnCancel;
public System.Windows.Forms.Panel panel3;
public System.Windows.Forms.Panel panel2;
private System.Windows.Forms.Panel panel1;
private Controls.UCSplitLine_H ucSplitLine_H2;
}
}