c# - 在 Windows 窗体 (C#) 中使用一个声明设置多个属性

标签 c# windows winforms

有没有办法在 Windows 窗体 C# 中通过一个声明设置多个属性?

我正在为游戏制作技能计算器,我希望能够做这样的事情:

someControl.Text = "some text",
           .BackgroundImage = "someImage.jpg";

有没有可能做这样的事情?

最佳答案

在 VB 中,您可以使用“WITH”关键字。 C# 中最接近的是采用对象初始值设定项的构造函数。

var someControl = new Control() {
                         Text = "SomeText",
                         BackgroundImage "someImage.jpg" };

但是不,我不认为有一种方法可以在 C# 中完成您的要求。

关于c# - 在 Windows 窗体 (C#) 中使用一个声明设置多个属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17032663/

相关文章:

c# - 使用一个 Windows 窗体 - Visual Studios c#

windows - 为什么 TFontDialog 提供的字体比 Screen.Fonts 少?

java - 在 logback 中恢复已删除的日志文件在 Windows 上运行良好,但在 Linux SUSE 上不起作用

vb.net - 编译适用于 ARM 和 Windows RT 的 VB.NET WinForms 应用程序

vb.net - 默认表单实例何时创建?

c# - 使用 TPL 数据流的请求/响应模式

c# - 在编译时使用三元运算符计算字符串常量

windows - 尝试运行 mysqld 时出现时间戳错误

c# - 获取拖放到 Windows 窗体上的文件的文件扩展名

c# - 在 C# 中获取当前 CPU 使用率