Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


c# textbox tab location

Posted on 2011-09-02
Medium Priority
Last Modified: 2013-12-17
How can I set the Tab locations within a textbox ? I found one example that uses the API to send a msg, but I thought .Net would be cleaner than that.

Question by:sidwelle
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 36475756
What do you mean by "tab locations"? Are you referring to when hitting the Tab key you go to the next TextBox (or other control)? If so, you would use the designer for this:

The numbers indicate the tab order of the controls. Nested controls get a decimal value. When you have the numbers showing, you can simply click the controls in the order you want the next control to be entered.

My guess is that you don't mean this, though  : \

Author Comment

ID: 36475802
No,  When I  populate a textbox with a string and it contains a 'TAB' or '\t', I want to set the tab location on the TextBox control. The tab location being the number of characters from the left border.

LVL 22

Expert Comment

ID: 36475815

I think you need to use API message EM_SETTABSTOPS for TextBox.

But if it's ok to use RichTextBox you coud use RichTextBox.SelectionTabs.

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments


Author Comment

ID: 36475897
I was trying to use the example here: http://stackoverflow.com/questions/2000772/using-c-how-do-i-set-tab-positions-in-a-multiline-textbox

But I was having a lot of problems with the 'IntPtr' statement and I don't know alot about it.

LVL 22

Accepted Solution

pivar earned 2000 total points
ID: 36476042

Try the following
using System.Runtime.InteropServices;

namespace Test {

  public partial class Form1 : Form {
        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);
        public Form1()

            SetTabStops(textBox1, new int[] { 10, 50, 100 });

        private void SetTabStops(TextBox tb, int[] tabs)
              SendMessage(tb.Handle, EM_SETTABSTOPS, tabs.Length, tabs);


Author Closing Comment

ID: 36476181
Works, very nice


Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question