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 6864475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:54:58+00:00 2026-05-27T02:54:58+00:00

I have a custom label in a winform app. I change the content of

  • 0

I have a custom label in a winform app. I change the content of the label across threads.
I open a background thread to read input data, and I call my cross-thread method to change the label content using the following code:

// ... invoke a cross-thread method to reset progress label information
Set_ProgressInfo("Reading data from input data file ... inputData");

My cross-thread method is:

public void Set_ProgressInfo(string text)
{
    if (this.progressInfo.InvokeRequired)
    {
        this.progressInfo.BeginInvoke(new MethodInvoker(delegate()
            { Set_ProgressInfo(text); }));
    }
    else
    {
        this.progressInfo.Text = text;

        this.progressInfo.Location = new System.Drawing.Point(55, 595);
        this.progressInfo.ForeColor = System.Drawing.Color.AliceBlue;
        this.progressInfo.Font = new System.Drawing.Font("Verdana", 10.0f,
            System.Drawing.FontStyle.Bold);

        // Auto size label to fit the text
        // ... create a Graphics object for the label
        using (var g_progressInfo = this.progressInfo.CreateGraphics())
        {
           // ... get the Size needed to accommodate the formatted text
           Size preferredSize_progressInfo = g_progressInfo.MeasureString(
           this.progressInfo.Text, this.progressInfo.Font).ToSize();

           // ... pad the text and resize the label
           this.progressInfo.ClientSize = new Size(
           preferredSize_progressInfo.Width + (BSAGlobals.labelTextPadding),
           preferredSize_progressInfo.Height + (BSAGlobals.labelTextPadding));
       }
    }
}

Everything works great, as it should, except:

When I change the font size in

this.progressInfo.Font = new System.Drawing.Font("Verdana", 10.0f,
    System.Drawing.FontStyle.Bold);

from 10.0f to 8.0f, only the “Reading data from input data file …” portion of the string in the calling component

Set_ProgressInfo("Reading data from input data file ... inputData");

displays. For some reason the size is not being calculated correctly at the smaller font size. Am I missing something here? I have been struggling with this for some time now and simply cannot see the reason for this. Any help would be greatly appreciated. Thank you.

  • 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-05-27T02:54:59+00:00Added an answer on May 27, 2026 at 2:54 am

    You are using the wrong measuring method, use TextRenderer.MeasureText() instead. The font metrics for the .NET 1.x rendering method (Graphics.DrawString) isn’t the same. Technically you should use both, using the value of the label’s UseCompatibleTextRendering property, but that can easily be skipped.

    Do favor using the label’s Padding and AutoSize properties so this is all automatic.

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

Sidebar

Related Questions

In my app i have created one custom class for Label.Now i want to
I have a custom made dialog winform. On it I have a label, textbox
In my C# program, I have a Custom Control with a label and a
I have a bunch of custom UITableViewCells with a label and textbox. I have
I have custom classes that I currently instantiate within App.xaml as resources. I want
I have a datagrid with a custom label itemrenderer (basically it makes the label
I have an adobe flex datagrid with a simple custom label itemrenderer in one
In Contacts I have set up a Date field with a custom label (when
I am working on a location aware app, where I want to have custom
I have a custom UserControl (a label and a textbox). My problem is I

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.