gpt4 book ai didi

c# - 将自定义控件替换为现有控件

转载 作者:行者123 更新时间:2023-11-30 15:41:02 24 4
gpt4 key购买 nike

我有一个 WinForms 表单,上面有几个文本框。我需要将其中一些更改为 TextBox 的自定义版本(我不得不重写一个函数)。由于整个新控件只是这一个函数,所以我只用几行代码就完成了这一切,就像我的表单中的一个包含类一样。现在,我想将设计器生成的文本框的实例更改为在代码中 的这个实例。这能以某种方式完成吗?

如果不能,并且我必须向我的项目添加一个全新的 UserControl 项,我是否可以至少在设计器中替换它而不丢失我所有的属性更改和事件处理程序绑定(bind)?

最佳答案

描述

查看 <YourFormName>.Designer.cs文件。这是设计师创建的文件。您可以更改您的 TextBox以这种方式符合您的习惯。

示例

#region Windows Form Designer generated code
private void InitializeComponent()
{
// change this
this.textBox1 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(0, 0);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(100, 20);
this.textBox1.TabIndex = 0;
//
// Form1
//
// ...

}

#endregion

// change this
private System.Windows.Forms.TextBox textBox1;

关于c# - 将自定义控件替换为现有控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8709525/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com