如何使以下异常返回 BOLD 和文本字体 RED?"return " WMI Error ";"的措辞
这将在后面的代码中用于在文本框中返回 WMI 参数...如下所示:
private static string GetMOValue(ManagementObject mo, string name)
{
try
{
object result = mo[name];
return result == null ? "" : result.ToString();
}
catch (Exception)
{
return "***WMI Error***";
}
}
private void cmbHdd_SelectedIndexChanged(object sender, EventArgs e)
{
//try
//{
ManagementObjectSearcher mosDisks = new ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive WHERE Model = '" + cmbHdd.SelectedItem + "'");
foreach (ManagementObject moDisk in mosDisks.Get())
{
//try
//{
txtSystemName.Text = GetMOValue(moDisk, "systemname");
txtType.Text = GetMOValue(moDisk, "MediaType");
txtModel.Text = GetMOValue(moDisk, "Model");
txtFirmware.Text = GetMOValue(moDisk, "FirmwareRevision");
.....