(二十四)c#Winform自定义控件-单标题窗体
程序员文章站
2022-05-29 10:04:00
前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章。 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control 如果觉得写的还行,请点个 star 支持一下吧 欢迎前来交流探讨: 企鹅群568015492 目录 ......
前提
入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章。
开源地址:
如果觉得写的还行,请点个 star 支持一下吧
欢迎前来交流探讨: 企鹅群568015492
目录
准备工作
这个窗体继承子基类窗体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 }
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 }
用处及效果
最后的话
如果你喜欢的话,请到 点个星 星吧