Solved

c# textbox tab location

Posted on 2011-09-02
6
958 Views
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.

Thanks
0
Comment
Question by:sidwelle
  • 3
  • 2
6 Comments
 
LVL 74

Expert Comment

by:käµfm³d 👽
Comment Utility
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:

Screenshot
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  : \
0
 

Author Comment

by:sidwelle
Comment Utility
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.



0
 
LVL 22

Expert Comment

by:pivar
Comment Utility
Hi,

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.

/peter
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:sidwelle
Comment Utility
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.

0
 
LVL 22

Accepted Solution

by:
pivar earned 500 total points
Comment Utility

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()
        {
            InitializeComponent();

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

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

/peter
0
 

Author Closing Comment

by:sidwelle
Comment Utility
Works, very nice

Thanks
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now