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
Solved

c# textbox tab location

Posted on 2011-09-02
6
966 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 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:

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
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.



0
 
LVL 22

Expert Comment

by:pivar
ID: 36475815
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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

Author Comment

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

0
 
LVL 22

Accepted Solution

by:
pivar earned 500 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()
        {
            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
ID: 36476181
Works, very nice

Thanks
0

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.NET 2008 - SQL Timeout 9 34
linq, c# 8 22
Where does legacy ASP.NET initialize language? 2 19
reading excel file in .net 2 13
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

807 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