官网

http://www.hzhcontrols.com

前提

入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章。

GitHub:https://github.com/kwwwvagaa/NetWinformControl

码云:https://gitee.com/kwwwvagaa/net_winform_custom_control.git

如果觉得写的还行,请点个 star 支持一下吧

欢迎前来交流探讨: 企鹅群568015492 

idkey=6e08741ef16fe53bf0314c1c9e336c4f626047943a8b76bac062361bab6b4f8d">

目录

https://www.cnblogs.com/bfyx/p/11364884.html

准备工作

这个窗体继承子基类窗体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(, );
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(, );
this.panel2.TabIndex = ;
//
// panel4
//
this.panel4.Controls.Add(this.panel5);
this.panel4.Dock = System.Windows.Forms.DockStyle.Right;
this.panel4.Location = new System.Drawing.Point(, );
this.panel4.Name = "panel4";
this.panel4.Size = new System.Drawing.Size(, );
this.panel4.TabIndex = ;
//
// 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(, );
this.panel5.Name = "panel5";
this.panel5.Size = new System.Drawing.Size(, );
this.panel5.TabIndex = ;
//
// panel1
//
this.panel1.Controls.Add(this.ucSplitLine_V1);
this.panel1.Dock = System.Windows.Forms.DockStyle.Right;
this.panel1.Location = new System.Drawing.Point(, );
this.panel1.Name = "panel1";
this.panel1.Padding = new System.Windows.Forms.Padding(, , , );
this.panel1.Size = new System.Drawing.Size(, );
this.panel1.TabIndex = ;
//
// ucSplitLine_V1
//
this.ucSplitLine_V1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)()))), ((int)(((byte)()))), ((int)(((byte)()))));
this.ucSplitLine_V1.Dock = System.Windows.Forms.DockStyle.Right;
this.ucSplitLine_V1.Location = new System.Drawing.Point(, );
this.ucSplitLine_V1.Name = "ucSplitLine_V1";
this.ucSplitLine_V1.Padding = new System.Windows.Forms.Padding(, , , );
this.ucSplitLine_V1.Size = new System.Drawing.Size(, );
this.ucSplitLine_V1.TabIndex = ;
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)()));
this.btnOK.BtnForeColor = System.Drawing.Color.FromArgb(((int)(((byte)()))), ((int)(((byte)()))), ((int)(((byte)()))));
this.btnOK.BtnText = "确定";
this.btnOK.ConerRadius = ;
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)()))), ((int)(((byte)()))), ((int)(((byte)()))));
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(, );
this.btnOK.Margin = new System.Windows.Forms.Padding(, , , );
this.btnOK.Name = "btnOK";
this.btnOK.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)()))), ((int)(((byte)()))), ((int)(((byte)()))));
this.btnOK.RectWidth = ;
this.btnOK.Size = new System.Drawing.Size(, );
this.btnOK.TabIndex = ;
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)()));
this.btnCancel.BtnForeColor = System.Drawing.Color.FromArgb(((int)(((byte)()))), ((int)(((byte)()))), ((int)(((byte)()))));
this.btnCancel.BtnText = "取消";
this.btnCancel.ConerRadius = ;
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)()))), ((int)(((byte)()))), ((int)(((byte)()))));
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(, );
this.btnCancel.Margin = new System.Windows.Forms.Padding(, , , );
this.btnCancel.Name = "btnCancel";
this.btnCancel.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)()))), ((int)(((byte)()))), ((int)(((byte)()))));
this.btnCancel.RectWidth = ;
this.btnCancel.Size = new System.Drawing.Size(, );
this.btnCancel.TabIndex = ;
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(, );
this.panel3.Name = "panel3";
this.panel3.Size = new System.Drawing.Size(, );
this.panel3.TabIndex = ;
//
// ucSplitLine_H2
//
this.ucSplitLine_H2.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)()))), ((int)(((byte)()))), ((int)(((byte)()))));
this.ucSplitLine_H2.Dock = System.Windows.Forms.DockStyle.Bottom;
this.ucSplitLine_H2.Location = new System.Drawing.Point(, );
this.ucSplitLine_H2.Name = "ucSplitLine_H2";
this.ucSplitLine_H2.Size = new System.Drawing.Size(, );
this.ucSplitLine_H2.TabIndex = ;
this.ucSplitLine_H2.TabStop = false;
//
// FrmWithOKCancel2
//
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
this.ClientSize = new System.Drawing.Size(, );
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, );
this.Controls.SetChildIndex(this.panel3, );
this.Controls.SetChildIndex(this.ucSplitLine_H2, );
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;
}
}

用处及效果

最后的话

如果你喜欢的话,请到 https://gitee.com/kwwwvagaa/net_winform_custom_control 点个星 星吧

最新文章

  1. 别再为了iOS新系统设备而重新安装一个新版Xcode了.其实我们可以添加版本支持
  2. 书旗小说app点评
  3. 从 datetime2 数据类型到 datetime 数据类型的转换产生一个超出范围的值
  4. 初涉SQL Server性能问题(1/4):服务器概况
  5. array_walk() 函数
  6. 杭电ACM2061--Treasure the new start, freshmen!
  7. [学习笔记]设计模式之Flyweight
  8. 四轴飞行器1.4 姿态解算和Matlab实时姿态显示
  9. vb6源码后台点击任意窗口指定坐标XY位置,支持FLASH和一般的游戏
  10. Java线程学习笔记(一个)
  11. 关于移动APP与Web APP的测试重点以及区别
  12. dubbo直连提供者 &amp; 只订阅 &amp; 只注册
  13. 使用VMware安装Ubuntu虚拟机,创建后开启显示黑屏的解决方法
  14. 2018-2019-2 20165330《网络对抗技术》Exp5 MSF基础应用
  15. python基础之Day13
  16. 作业引擎quartz.net --- 监听链
  17. 三种方式控制GPIO
  18. hdu CA Loves GCD(dp)
  19. ios图层转场动画
  20. 磁盘IO概念及优化入门知识

热门文章

  1. 深入学习Spring框架(三)- AOP面向切面
  2. ASP.NET Core Web Api之JWT(一)
  3. Oracle修改字段类型报错:“ORA-01439:要更改数据类型,则要修改的列必须为空”
  4. js继承的6种方式
  5. springboot之mybatisplus,mp的简单理解
  6. spring mvc 拦截器的使用
  7. Lock和synchronized比较详解(转)
  8. JDBC连接-操作数据库
  9. flash put_movie loadmovie 区别
  10. 【Android UI】侧滑栏的使用(HorizontalScrollView控件的使用)