(二十六)c#Winform自定义控件-有确定取消的窗体(二)-HZHControls

官网

https://www.hzhcontrols.cn

前提

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

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

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

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

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

目录

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

准备工作

这个窗体继承子基类窗体FrmWithTitle,如果你对FrmWithTitle还不了解,请移步 (二十四)c#Winform自定义控件-单标题窗体 查看

开始

添加一个Form,命名FrmWithOKCancel2,继承FrmWithTitle

代码不多,直接上全部代码

 1 // 版权所有  黄正辉  交流群:568015492   QQ:623128629
 2 // 文件名称:FrmWithOKCancel2.cs
 3 // 创建日期:2019-08-15 16:05:21
 4 // 功能描述:FrmWithOKCancel2
 5 // 项目地址:https://gitee.com/kwwwvagaa/net_winform_custom_control
 6 
 7 using System;
 8 using System.Collections.Generic;
 9 using System.ComponentModel;
10 using System.Data;
11 using System.Drawing;
12 using System.Linq;
13 using System.Text;
14 using System.Windows.Forms;
15 
16 namespace HZH_Controls.Forms
17 {
18     [Designer("System.Windows.Forms.Design.ParentControlDesigner, System.Design", typeof(System.ComponentModel.Design.IDesigner))]
19     public partial class FrmWithOKCancel2 : FrmWithTitle
20     {
21         public FrmWithOKCancel2()
22         {
23             InitializeComponent();
24         }
25 
26         private void btnOK_BtnClick(object sender, EventArgs e)
27         {
28             DoEnter();
29         }
30 
31         private void btnCancel_BtnClick(object sender, EventArgs e)
32         {
33             DoEsc();
34         }
35 
36         protected override void DoEnter()
37         {
38             this.DialogResult = System.Windows.Forms.DialogResult.OK;
39         }
40 
41         private void FrmWithOKCancel2_VisibleChanged(object sender, EventArgs e)
42         {
43         }
44     }
45 }
View Code
  1 namespace HZH_Controls.Forms
  2 {
  3     partial class FrmWithOKCancel2
  4     {
  5         /// <summary>
  6         /// Required designer variable.
  7         /// </summary>
  8         private System.ComponentModel.IContainer components = null;
  9 
 10         /// <summary>
 11         /// Clean up any resources being used.
 12         /// </summary>
 13         /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
 14         protected override void Dispose(bool disposing)
 15         {
 16             if (disposing && (components != null))
 17             {
 18                 components.Dispose();
 19             }
 20             base.Dispose(disposing);
 21         }
 22 
 23         #region Windows Form Designer generated code
 24 
 25         /// <summary>
 26         /// Required method for Designer support - do not modify
 27         /// the contents of this method with the code editor.
 28         /// </summary>
 29         private void InitializeComponent()
 30         {
 31             System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FrmWithOKCancel2));
 32             this.panel2 = new System.Windows.Forms.Panel();
 33             this.panel4 = new System.Windows.Forms.Panel();
 34             this.panel5 = new System.Windows.Forms.Panel();
 35             this.panel1 = new System.Windows.Forms.Panel();
 36             this.ucSplitLine_V1 = new HZH_Controls.Controls.UCSplitLine_V();
 37             this.btnOK = new HZH_Controls.Controls.UCBtnExt();
 38             this.btnCancel = new HZH_Controls.Controls.UCBtnExt();
 39             this.panel3 = new System.Windows.Forms.Panel();
 40             this.ucSplitLine_H2 = new HZH_Controls.Controls.UCSplitLine_H();
 41             this.panel2.SuspendLayout();
 42             this.panel4.SuspendLayout();
 43             this.panel5.SuspendLayout();
 44             this.panel1.SuspendLayout();
 45             this.SuspendLayout();
 46             // 
 47             // panel2
 48             // 
 49             this.panel2.Controls.Add(this.panel4);
 50             this.panel2.Dock = System.Windows.Forms.DockStyle.Bottom;
 51             this.panel2.Location = new System.Drawing.Point(0, 246);
 52             this.panel2.Name = "panel2";
 53             this.panel2.Size = new System.Drawing.Size(427, 64);
 54             this.panel2.TabIndex = 5;
 55             // 
 56             // panel4
 57             // 
 58             this.panel4.Controls.Add(this.panel5);
 59             this.panel4.Dock = System.Windows.Forms.DockStyle.Right;
 60             this.panel4.Location = new System.Drawing.Point(227, 0);
 61             this.panel4.Name = "panel4";
 62             this.panel4.Size = new System.Drawing.Size(200, 64);
 63             this.panel4.TabIndex = 0;
 64             // 
 65             // panel5
 66             // 
 67             this.panel5.Controls.Add(this.panel1);
 68             this.panel5.Controls.Add(this.btnOK);
 69             this.panel5.Controls.Add(this.btnCancel);
 70             this.panel5.Dock = System.Windows.Forms.DockStyle.Bottom;
 71             this.panel5.Location = new System.Drawing.Point(0, 0);
 72             this.panel5.Name = "panel5";
 73             this.panel5.Size = new System.Drawing.Size(200, 64);
 74             this.panel5.TabIndex = 5;
 75             // 
 76             // panel1
 77             // 
 78             this.panel1.Controls.Add(this.ucSplitLine_V1);
 79             this.panel1.Dock = System.Windows.Forms.DockStyle.Right;
 80             this.panel1.Location = new System.Drawing.Point(99, 0);
 81             this.panel1.Name = "panel1";
 82             this.panel1.Padding = new System.Windows.Forms.Padding(0, 15, 0, 15);
 83             this.panel1.Size = new System.Drawing.Size(1, 64);
 84             this.panel1.TabIndex = 1;
 85             // 
 86             // ucSplitLine_V1
 87             // 
 88             this.ucSplitLine_V1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(232)))), ((int)(((byte)(232)))), ((int)(((byte)(232)))));
 89             this.ucSplitLine_V1.Dock = System.Windows.Forms.DockStyle.Right;
 90             this.ucSplitLine_V1.Location = new System.Drawing.Point(0, 15);
 91             this.ucSplitLine_V1.Name = "ucSplitLine_V1";
 92             this.ucSplitLine_V1.Padding = new System.Windows.Forms.Padding(0, 10, 0, 10);
 93             this.ucSplitLine_V1.Size = new System.Drawing.Size(1, 34);
 94             this.ucSplitLine_V1.TabIndex = 2;
 95             this.ucSplitLine_V1.TabStop = false;
 96             // 
 97             // btnOK
 98             // 
 99             this.btnOK.BackColor = System.Drawing.Color.Transparent;
100             this.btnOK.BtnBackColor = System.Drawing.Color.Transparent;
101             this.btnOK.BtnFont = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
102             this.btnOK.BtnForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(77)))), ((int)(((byte)(59)))));
103             this.btnOK.BtnText = "确定";
104             this.btnOK.ConerRadius = 5;
105             this.btnOK.Cursor = System.Windows.Forms.Cursors.Hand;
106             this.btnOK.Dock = System.Windows.Forms.DockStyle.Fill;
107             this.btnOK.FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(247)))), ((int)(((byte)(247)))), ((int)(((byte)(247)))));
108             this.btnOK.Font = new System.Drawing.Font("微软雅黑", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel);
109             this.btnOK.IsRadius = false;
110             this.btnOK.IsShowRect = false;
111             this.btnOK.IsShowTips = false;
112             this.btnOK.Location = new System.Drawing.Point(0, 0);
113             this.btnOK.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
114             this.btnOK.Name = "btnOK";
115             this.btnOK.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(247)))), ((int)(((byte)(247)))), ((int)(((byte)(247)))));
116             this.btnOK.RectWidth = 1;
117             this.btnOK.Size = new System.Drawing.Size(100, 64);
118             this.btnOK.TabIndex = 0;
119             this.btnOK.TabStop = false;
120             this.btnOK.TipsText = "";
121             this.btnOK.BtnClick += new System.EventHandler(this.btnOK_BtnClick);
122             // 
123             // btnCancel
124             // 
125             this.btnCancel.BackColor = System.Drawing.Color.Transparent;
126             this.btnCancel.BtnBackColor = System.Drawing.Color.Transparent;
127             this.btnCancel.BtnFont = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
128             this.btnCancel.BtnForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(73)))), ((int)(((byte)(119)))), ((int)(((byte)(232)))));
129             this.btnCancel.BtnText = "取消";
130             this.btnCancel.ConerRadius = 5;
131             this.btnCancel.Cursor = System.Windows.Forms.Cursors.Hand;
132             this.btnCancel.Dock = System.Windows.Forms.DockStyle.Right;
133             this.btnCancel.FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(247)))), ((int)(((byte)(247)))), ((int)(((byte)(247)))));
134             this.btnCancel.Font = new System.Drawing.Font("微软雅黑", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel);
135             this.btnCancel.IsRadius = false;
136             this.btnCancel.IsShowRect = false;
137             this.btnCancel.IsShowTips = false;
138             this.btnCancel.Location = new System.Drawing.Point(100, 0);
139             this.btnCancel.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
140             this.btnCancel.Name = "btnCancel";
141             this.btnCancel.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(247)))), ((int)(((byte)(247)))), ((int)(((byte)(247)))));
142             this.btnCancel.RectWidth = 1;
143             this.btnCancel.Size = new System.Drawing.Size(100, 64);
144             this.btnCancel.TabIndex = 1;
145             this.btnCancel.TabStop = false;
146             this.btnCancel.TipsText = "";
147             this.btnCancel.BtnClick += new System.EventHandler(this.btnCancel_BtnClick);
148             // 
149             // panel3
150             // 
151             this.panel3.BackColor = System.Drawing.Color.White;
152             this.panel3.Dock = System.Windows.Forms.DockStyle.Fill;
153             this.panel3.Location = new System.Drawing.Point(0, 61);
154             this.panel3.Name = "panel3";
155             this.panel3.Size = new System.Drawing.Size(427, 185);
156             this.panel3.TabIndex = 6;
157             // 
158             // ucSplitLine_H2
159             // 
160             this.ucSplitLine_H2.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(238)))), ((int)(((byte)(238)))), ((int)(((byte)(238)))));
161             this.ucSplitLine_H2.Dock = System.Windows.Forms.DockStyle.Bottom;
162             this.ucSplitLine_H2.Location = new System.Drawing.Point(0, 245);
163             this.ucSplitLine_H2.Name = "ucSplitLine_H2";
164             this.ucSplitLine_H2.Size = new System.Drawing.Size(427, 1);
165             this.ucSplitLine_H2.TabIndex = 7;
166             this.ucSplitLine_H2.TabStop = false;
167             // 
168             // FrmWithOKCancel2
169             // 
170             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
171             this.ClientSize = new System.Drawing.Size(427, 310);
172             this.Controls.Add(this.ucSplitLine_H2);
173             this.Controls.Add(this.panel3);
174             this.Controls.Add(this.panel2);
175             this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
176             this.Name = "FrmWithOKCancel2";
177             this.Text = "FrmWithOKCancel2";
178             this.VisibleChanged += new System.EventHandler(this.FrmWithOKCancel2_VisibleChanged);
179             this.Controls.SetChildIndex(this.panel2, 0);
180             this.Controls.SetChildIndex(this.panel3, 0);
181             this.Controls.SetChildIndex(this.ucSplitLine_H2, 0);
182             this.panel2.ResumeLayout(false);
183             this.panel4.ResumeLayout(false);
184             this.panel5.ResumeLayout(false);
185             this.panel1.ResumeLayout(false);
186             this.ResumeLayout(false);
187 
188         }
189 
190         #endregion
191 
192         private System.Windows.Forms.Panel panel4;
193         private System.Windows.Forms.Panel panel5;
194         private Controls.UCSplitLine_V ucSplitLine_V1;
195         private Controls.UCBtnExt btnOK;
196         private Controls.UCBtnExt btnCancel;
197         public System.Windows.Forms.Panel panel3;
198         public System.Windows.Forms.Panel panel2;
199         private System.Windows.Forms.Panel panel1;
200         private Controls.UCSplitLine_H ucSplitLine_H2;
201     }
202 }
View Code

 

用处及效果

最后的话

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

posted @ 2019-08-16 15:29  冰封一夏  阅读(1542)  评论(0编辑  收藏  举报
HZHControls控件库官网:https://www.hzhcontrols.cn