如果() +开关() +图片框 [C#]
事情是这样的,我有一个 Windows 窗体,其中有一个空图片框和一些使用 wmi 获取系统信息的标签,图片框应该使用 if 自动从项目中名为 Pictures 的文件夹中获取操作系统的徽标声明或开关盒,但我一生都无法想出可行的东西。
基本思想是:
如果 OSN 包含 7,pictureBoxOS 从图片文件夹中获取名为 W7 的图像。
如果 OSN 包含 8,pictureBoxOS 从图片文件夹中获取名为 W8 的图像 依此类推
OSN 是操作系统名称
下面是 SysInfo 类中写入的一些内容
public static class SysInfo
{
public static String GetOSName()
{
ManagementClass mc = new ManagementClass("Win32_OperatingSystem");
ManagementObjectCollection moc = mc.GetInstances();
String OSN = String.Empty;
foreach (ManagementObject mo in moc)
{
OSN = mo.Properties["Caption"].Value.ToString();
break;
}
return OSN;
}
然后是表格中写入的内容
public partial class FormSystemInfo : Form
{
public FormSystemInfo()
{
InitializeComponent();
LoadTheme();
}
private void FormSystemInfo_Load(object sender, EventArgs e)
{
labelOSName.Text=SysInfo.GetOSName();
labelOSVersion.Text=SysInfo.GetOSVersion();
labelBrandModel.Text=SysInfo.GetBrandModel();
labelProcessorName.Text=SysInfo.GetProcessorName();
labelMemory.Text=SysInfo.GetPhysicalMemory();
labelDriveID.Text=SysInfo.GetDriveID();
labelGPUName.Text=SysInfo.GetGPUName();
labelSerialNumber.Text = SysInfo.GetSerialNumber();
}
}
Here's the thing, I have a Windows Form with an empty pictureBox in it and some labels that get system info using wmi, the picture box is supposed to automatically get the logo of the operating system from a folder in the project called Pictures using an if statement or a switch case but I can't for the life of me come up with something that works.
The basic idea is :
if OSN contains a 7, pictureBoxOS gets the image called W7 from the pictures folder.
if OSN contains an 8, pictureBoxOS gets the image called W8 from the pictures folder
so on and so forth
OSN being the OS Name
What follows is some of what's written in the SysInfo Class
public static class SysInfo
{
public static String GetOSName()
{
ManagementClass mc = new ManagementClass("Win32_OperatingSystem");
ManagementObjectCollection moc = mc.GetInstances();
String OSN = String.Empty;
foreach (ManagementObject mo in moc)
{
OSN = mo.Properties["Caption"].Value.ToString();
break;
}
return OSN;
}
Then comes what's written in the form
public partial class FormSystemInfo : Form
{
public FormSystemInfo()
{
InitializeComponent();
LoadTheme();
}
private void FormSystemInfo_Load(object sender, EventArgs e)
{
labelOSName.Text=SysInfo.GetOSName();
labelOSVersion.Text=SysInfo.GetOSVersion();
labelBrandModel.Text=SysInfo.GetBrandModel();
labelProcessorName.Text=SysInfo.GetProcessorName();
labelMemory.Text=SysInfo.GetPhysicalMemory();
labelDriveID.Text=SysInfo.GetDriveID();
labelGPUName.Text=SysInfo.GetGPUName();
labelSerialNumber.Text = SysInfo.GetSerialNumber();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于任何可能偶然发现这篇文章的人,我确实找到了一种使它起作用的方法:
For anyone who might stumble upon this post, I did find a way to make it work: