在 Windows 窗体 (C#) 中使用一个声明设置多个属性 [英] Setting multiple properties with one declaration in Windows Forms (C#)
本文介绍了在 Windows 窗体 (C#) 中使用一个声明设置多个属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法在 Windows Forms C# 中使用一个声明来设置多个属性?
Is there a way to set multiple properties with one declaration in Windows Forms C#?
我正在为游戏制作技能计算器,我希望能够执行以下操作:
I'm making a skill calculator for a game and I would like be able to do something like this:
someControl.Text = "some text",
.BackgroundImage = "someImage.jpg";
有没有可能做这样的事情?
Is it possible to do something like that?
推荐答案
在 VB 中,您可以使用WITH"关键字.C# 中最接近的是带有对象初始值设定项的构造函数.
In VB, you could use the "WITH" keyword. The closest thing in C# is the constructor that takes an object initializer.
var someControl = new Control() {
Text = "SomeText",
BackgroundImage "someImage.jpg" };
但是不,我认为没有办法在 C# 中完成您的要求.
but no, I don't think there is a way to do what you are asking in C#.
这篇关于在 Windows 窗体 (C#) 中使用一个声明设置多个属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文