How do I make the below exception return BOLD and text font RED? The wordings of “return “WMI Error“;”
This is used later in the code for returning WMI parameters in a textbox…as shown below:
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");
.....
TextBox is not a web browser. It supports showing text with a single font – no decorations, colors, etc. You can change a font for the textbox in runtime.
You could handle the
TextChangedevent of the textbox to achieve this, but this is not an example of nice code:A better approach would be to have a simple method which will set the text and textbox attributes.
the soapbox: Please note that I consider this form of checking the text for ** characters to see if it is an error, extremely ugly and unreliable. What you should do is have something like
You can use RichTextBox, WebBrowser or some custom drawn control to support fancier formatting.