Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8589205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:59:44+00:00 2026-06-11T22:59:44+00:00

How do I make the below exception return BOLD and text font RED? The

  • 0

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");
.....
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T22:59:45+00:00Added an answer on June 11, 2026 at 10:59 pm

    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 TextChanged event of the textbox to achieve this, but this is not an example of nice code:

    private void textBox1_TextChanged(object sender, EventArgs e)
    {
      Font defaultFont = SystemFonts.DefaultFont;
    
      if(textBox1.Text.StartsWith("**") && textBox1.Text.EndsWith("**"))
      {
        textBox1.Font = new Font(defaultFont.FontFamily, defaultFont.Size, FontStyle.Bold);
        textBox1.ForeColor = Color.Red;
        // note: can't change text here as it will recursively trigger this handler
      }
      else
      {
        textBox1.Font = defaultFont;
        textBox1.ForeColor = SystemColors.ControlText;
      }
    }
    

    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

    Font defaultFont = SystemFonts.DefaultFont;
    try
    { 
       textBox1.Text = GetMOValue(...);
       textBox1.Font = defaultFont;
       textBox1.ForeColor = SystemColors.ControlText;
    }
    catch(Exception ex)
    { 
       textBox1.Text = "ERROR";
       textBox1.Font = new Font(defaultFont.FontFamily, defaultFont.Size, FontStyle.Bold);
       textBox1.ForeColor = Color.Red;
    }
    // the Font and ForeColor properties are repeatedly set in case that previous
    // try had the different result (e.g. previous => error, current => OK, so 
    // we need to reset the attributes of textbox
    

    You can use RichTextBox, WebBrowser or some custom drawn control to support fancier formatting.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use the code below and get this error InvalidDataExcption: The magic number in
For the following make file copied below, I am getting the missing separator error.
I am using this Ajax script below to make cross domain Ajax calls which
Below is some jQuery code the i wrote to make a simple animation. However
How can I make something like this below work? <?PHP $_SESSION['signup_errors']['test1']; $_SESSION['signup_errors']['test2']; $_SESSION['signup_errors']['test3']; $_SESSION['signup_errors']['test4'];
Below is some logging output from a .NET application. Error in MainFunction. Message: Exception
The problem. See the below code... I was missing the return field; statement and
I am receiving an error at this line return folder.SubFolders.Aggregate(count, (current, subfolder) => GetFilesCount(subfolder,
I use some code from the PHP manual to make an exception test, but
I'm getting a ClassCastException in the below code, which doesn't make much sense to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.