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

  • Home
  • SEARCH
  • 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 1048915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:31:58+00:00 2026-05-16T16:31:58+00:00

When a selection in WindowsForms RichTextbox uses two or more different font sizes (eg.

  • 0

When a selection in WindowsForms RichTextbox uses two or more different font sizes (eg. you select text with font size 9 and some other text with font size 16 in the same selection), SelectionFont.Size always returns 13. Is there any way to detect that two different sizes are selected?

  • 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-16T16:31:58+00:00Added an answer on May 16, 2026 at 4:31 pm

    If a range is selected which contains items that have the same font,
    but different sizes, the control incorrectly reports that the selection contains a font with size 13. I’m not certain this can be fixed. Perhaps it’s always 13 in this case, perhaps not, I don’t know.

    But i use the follow Solution …
    Found via Reflection in Methode

    public class RichTextBox : TextBoxBase ...
      private Font GetCharFormatFont(bool selectionOnly)**
    

    Example Code:
    Content => The RichTextBox-Control

    // var lSize = Content.SelectionSize;
    var lSize = RichTextBoxHelper.GetSelectionSize(Content);
    
    if (lSize.HasValue)
      ComboBoxFontSize.Text = Convert.ToString(lSize.Value);
    else
      // Multible Sizes ...
      ComboBoxFontSize.Text = string.Empty;
    

    Helper Methode (Class):

    using System;
    using System.ComponentModel;
    using System.Runtime.InteropServices;
    using System.Windows.Forms;
    
    namespace UnimatrixOne
    {
      public class RichTextBoxHelper
      {
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(HandleRef hWnd, int msg, int wParam, [In, Out, MarshalAs(UnmanagedType.LPStruct)] CHARFORMATA lParam);
    
        private const long CFM_SIZE = 0x80000000;
        private const int EM_GETCHARFORMAT = 0x043A;
        private const int SCF_SELECTION = 0x01;
    
        /// <summary> 
        /// Contains information about character formatting in a rich edit control. 
        /// </summary> 
        /// <remarks><see cref="CHARFORMAT"/>works with all Rich Edit versions.</remarks> 
        [StructLayout(LayoutKind.Sequential, Pack = 4)]
        public class CHARFORMATA
        {
          public int cbSize = Marshal.SizeOf(typeof(CHARFORMATA));
          public int dwMask;
          public int dwEffects;
          public int yHeight;
          public int yOffset;
          public int crTextColor;
          public byte bCharSet;
          public byte bPitchAndFamily;
          [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
          public byte[] szFaceName = new byte[32];
        }
    
        /// <summary> 
        /// Gets or sets the underline size off the current selection. 
        /// </summary>
        [Browsable(false),
        DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public static float? GetSelectionSize(RichTextBox control)
        {
          var lParam = new CHARFORMATA();
          lParam.cbSize = Marshal.SizeOf(lParam);
    
          // Get the underline style 
          SendMessage(new HandleRef(control, control.Handle), EM_GETCHARFORMAT, SCF_SELECTION, lParam);
          if ((lParam.dwMask & -CFM_SIZE) != 0)
          {
            float emSize = ((float)lParam.yHeight) / 20f;
    
            if ((emSize == 0f) && (lParam.yHeight > 0))
              emSize = 1f;
    
            return emSize;
          }
          else
            return null;
        }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When using a selection menu with the option for multiple select, jquery changes the
I have a selection for some items using a spinner widget. At the moment
System.Windows.Forms.ComboBox has two different events that the programmer can handle: SelectionChangeCommitted - event fires
I'm using a System.Windows.Forms.TextBox . It is possible to select text by using the
I've got a Windows Forms application with two ListBox controls on the same form.
let m = Regex.Match(X.Text, \\b(select)|(where)|(from)\\b, RegexOptions.IgnoreCase) it highlights only Select , so I guess
On selection change of radio button, I want to show a clock/timer for 5
That's how cell selection looks in MS Excel: Is it possible to have the
When making a selection on this simple gui list I am getting valueChanged to
I have a selection of products within my wordpress site. They are configurable products

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.