Windows窗体-随机设置BackColor-Powershell [英] Windows Forms - Randomize BackColor - Powershell

查看:70
本文介绍了Windows窗体-随机设置BackColor-Powershell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Windows窗体制作GUI,我想添加一个功能,您可以在其中随机化窗体的背景色.请注意,我打算将代码完全用Powershell编写.

I'm making a GUI using Windows Forms and I'd like to add a feature where you can randomize the background color of the form. Please be noted that I intend to keep the code fully written in Powershell.

这是代码段:

[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") 
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")  
$objForm = New-Object System.Windows.Forms.Form    
$choochoo = New-Object System.Windows.Forms.Button 

这是我需要帮助的代码:

And here is the code that I need help with:

$choochoo.Add_Click({$objForm.BackColor = Random}) 

显然,"Random"在此示例中不起作用,仅用作占位符.

Obviously 'Random' does not work in this example and is only being used as a placeholder.

我想我需要使用时间来生成随机值,但是希望使用更具体的代码.预先感谢.

I suppose I need to generate random values using the time but would appreciate a more concrete code. Thanks in advance.

推荐答案

您将要使用

You'll want to be using an instance of System.Random to select from the possible static properties of System.Drawing.Color.

这篇关于Windows窗体-随机设置BackColor-Powershell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆