简体   繁体   中英

Is any way to change control's background color without `BackColor` property?

There are some properties for Controls, that needs System.Drawing.dll to be used, ie:

control.Size =  new System.Drawing.Size(10, 20);

however, that goal can be achieved without with other workaround (not needed System.Drawing ), ie:

control.Width = 10;
control.Height= 20;

My question is, can we change control's background color ( .BackColor , which requires System.Drawing ) with some workarounds like that? (so, not needed System.Drawing )?

No - The dependency on System.Drawing is for the Color value itself and there are no shortcut properties to, for example, set the component values like you can with Size .

If you don't want to include System.Drawing inline just add a using directive:

using System.Drawing;

...

    control.BackColor = Color.Blue;  // Color will be found in System.Drawing via the "using"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM