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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T14:41:19+00:00 2026-05-10T14:41:19+00:00

This seemed like an easy thing to do. I just wanted to pop up

  • 0

This seemed like an easy thing to do. I just wanted to pop up a text window and display two columns of data — a description on the left side and a corresponding value displayed on the right side. I haven’t worked with Forms much so I just grabbed the first control that seemed appropriate, a TextBox. I thought using tabs would be an easy way to create the second column, but I discovered things just don’t work that well.

There seems to be two problems with the way I tried to do this (see below). First, I read on numerous websites that the MeasureString function isn’t very precise due to how complex fonts are, with kerning issues and all. The second is that I have no idea what the TextBox control is using as its StringFormat underneath.

Anyway, the result is that I invariably end up with items in the right column that are off by a tab. I suppose I could roll my own text window and do everything myself, but gee, isn’t there a simple way to do this?

    TextBox textBox    = new TextBox();     textBox.Font       = new Font('Calibri', 11);     textBox.Dock       = DockStyle.Fill;     textBox.Multiline  = true;     textBox.WordWrap   = false;     textBox.ScrollBars = ScrollBars.Vertical;      Form form            = new Form();     form.Text            = 'Recipe';     form.Size            = new Size(400, 600);     form.FormBorderStyle = FormBorderStyle.Sizable;     form.StartPosition   = FormStartPosition.CenterScreen;     form.Controls.Add(textBox);      Graphics g = form.CreateGraphics();      float targetWidth = 230;      foreach (PropertyInfo property in properties)     {         string text = String.Format('{0}:\t', Description);          while (g.MeasureString(text,textBox.Font).Width < targetWidth)             text += '\t';          textBox.AppendText(text + value.ToString() + '\n');     }      g.Dispose();     form.ShowDialog(); 
  • 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. 2026-05-10T14:41:19+00:00Added an answer on May 10, 2026 at 2:41 pm

    If you want, you can translate this VB.Net code to C#. The theory here is that you change the size of a tab in the control.

    Private Declare Function SendMessage _   Lib 'user32' Alias 'SendMessageA' _   (ByVal handle As IntPtr, ByVal wMsg As Integer, _   ByVal wParam As Integer, ByRef lParam As Integer) As Integer   Private Sub SetTabStops(ByVal ctlTextBox As TextBox)    Const EM_SETTABSTOPS As Integer = &HCBS    Dim tabs() As Integer = {20, 40, 80}    SendMessage(ctlTextBox.Handle, EM_SETTABSTOPS, _     tabs.Length, tabs(0))  End Sub 

    I converted a version to C# for you, too. Tested and working in VS2005.

    Add this using statement to your form:

    using System.Runtime.InteropServices; 

    Put this right after the class declaration:

        private const int EM_SETTABSTOPS = 0x00CB;     [DllImport('User32.dll', CharSet = CharSet.Auto)]     public static extern IntPtr SendMessage(IntPtr h, int msg, int wParam, int[] lParam); 

    Call this method when you want to set the tabstops:

        private void SetTabStops(TextBox ctlTextBox)     {         const int EM_SETTABSTOPS = 203;         int[] tabs = { 100, 40, 80 };         SendMessage(textBox1.Handle, EM_SETTABSTOPS, tabs.Length, tabs);     } 

    To use it, here is all I did:

        private void Form1_Load(object sender, EventArgs e)     {         SetTabStops(textBox1);          textBox1.Text = 'Hi\tWorld';     } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This seemed like it should be easy, but I have had trouble getting it
This one has me puzzled. It seemed like an easy task, but the solution
This seemed to me like an easy one, but I can't seem to find
In linking a sports event to two teams, at first this seemed to make
This is really just for my own use: I would like to be able
I just uncovered this confusion and would like a confirmation that it is what
It's easy! I just came across this blog post by Rudi Grobler that says
This seemed like a common question but after doing some searching, I wasn't really
This seemed to spark a bit of conversation on another question and I thought
This seemed pretty straightforward: capture a POST in Fiddler (Windows, because I find it

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.