前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >控件属性和InitializeComponent()关系:

控件属性和InitializeComponent()关系:

作者头像
Java架构师必看
发布2022-03-21 12:10:35
4251
发布2022-03-21 12:10:35
举报
文章被收录于专栏:Java架构师必看

大家好,我是架构君,一个会写代码吟诗的架构师。今天说一说控件属性和InitializeComponent()关系:,希望能够帮助大家进步!!!

代码语言:javascript
复制
 1 namespace Test22
 2 {
 3     partial class Form1
 4     {
 5         /// <summary>
 6         /// 必需的设计器变量。
 7         /// </summary>
 8         private System.ComponentModel.IContainer components = null;
 9 
10         /// <summary>
11         /// 清理所有正在使用的资源。
12         /// </summary>
13         /// <param name="disposing">如果应释放托管资源,为 true;否则为 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 窗体设计器生成的代码
24 
25         /// <summary>
26         /// 设计器支持所需的方法 - 不要
27         /// 使用代码编辑器修改此方法的内容。
28         /// </summary>
29         private void InitializeComponent()
30         {
31             this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
32             ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
33             this.SuspendLayout();
34             // 
35             // numericUpDown1
36             // 
37             this.numericUpDown1.DecimalPlaces = 4;//属性里对应!!!!!
38             this.numericUpDown1.Location = new System.Drawing.Point(12, 12);
39             this.numericUpDown1.Name = "numericUpDown1";
40             this.numericUpDown1.Size = new System.Drawing.Size(120, 21);
41             this.numericUpDown1.TabIndex = 0;
42             // 
43             // Form1
44             // 
45             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
46             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
47             this.ClientSize = new System.Drawing.Size(153, 53);
48             this.Controls.Add(this.numericUpDown1);
49             this.Name = "Form1";
50             this.Text = "Form1";
51             this.Load += new System.EventHandler(this.Form1_Load);
52             ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
53             this.ResumeLayout(false);
54 
55         }
56 
57         #endregion
58 
59         private System.Windows.Forms.NumericUpDown numericUpDown1;
60     }
61 }

控件中小数点位数和InitializeComponent()里面的代码相呼应,而下面的代码又设置了2,所以覆盖掉了,代码和运行结果如下:

代码语言:javascript
复制
此代码由Java架构师必看网-架构君整理
 1 using System;
 2 using System.Data;
 3 using System.Drawing;
 4 using System.Text;
 5 using System.Windows.Forms;
 6 namespace Test22
 7 {
 8     public partial class Form1 : Form
 9     {
10         public Form1()
11         {
12             InitializeComponent();
13         }
14         private void Form1_Load(object sender, EventArgs e)
15         {
16             numericUpDown1.Maximum = 20;
17             numericUpDown1.Minimum = 1;
18             numericUpDown1.DecimalPlaces = 2;
19         }
20     }
21 }

今天文章到此就结束了,感谢您的阅读,Java架构师必看祝您升职加薪,年年好运。

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022-03-182,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档