VS2022 .NET7手动更改组件类型(TextEdit改为ComboBoxEdit)|C/S开发框架

VS2022 .NET7手动更改组件类型(TextEdit改为ComboBoxEdit)
前言
.NET7不支持通过设计器直接变更组件类型。
作者想把TextEdit组件变更为ComboBoxEdit类型,有两种方法实现:
- 删除TextEdit组件,重新拖放一个ComboBoxEdit组件代替
- 通过设计器代码手动变更组件类型
本文讲解第2种方式,虽然操作比较麻烦,但是能提升开发者对VS设计器的使用经验,深度理解VS设计器的原理。


操作步骤
1、获取组件名称,txtPK

2、打开Designer.cs文件

3、找到 txtPK 组件的变量申明及实例化代码,变更组件类型


4、添加Combo按钮
变更组件类型后,发现组件没有显示Combo按钮,我们手工添加Combo按钮。


5、完成

扫一扫加作者微信