Is there a graceful way to set custom tab sizes/positions in a multiline textbox in C#?
            Asked
            
        
        
            Active
            
        
            Viewed 3,677 times
        
    5
            
            
        - 
                    WinForms or WPF? (note that I can't actually say whether this will make a difference!) – AakashM Jan 04 '10 at 17:15
- 
                    See http://stackoverflow.com/questions/1298406/how-to-set-the-tab-width-in-a-windows-forms-textbox-control – Mongus Pong Jan 04 '10 at 17:15
- 
                    Based on his other questions, probably WinForms. – SLaks Jan 04 '10 at 17:16
2 Answers
10
            You need to send the EM_SETTABSTOPS message, like this:
static class NativeMethods {
    [DllImport("user32.dll")]
    public static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, ref int lParam);
}
static void SetTabs(TextBox box) {
    //EM_SETTABSTOPS - http://msdn.microsoft.com/en-us/library/bb761663%28VS.85%29.aspx
    int lParam = 16;  //Set tab size to 4 spaces
    NativeMethods.SendMessage(box.Handle, 0x00CB, new IntPtr(1), ref lParam);
    box.Invalidate();
}
 
    
    
        SLaks
        
- 868,454
- 176
- 1,908
- 1,964
0
            
            
        Apart from by vb 2013 the friendly people at microsoft have decided you no longer need the windows handle and you can no longer get at it.
 
    
    
        Dave
        
- 11
- 1
 
    