[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1278
  • Last Modified:

Set the Tab Size in a TextBox is it possible?

Does anyone know if it possible to set the tabsize in a multiline textbox on a winForm?
if so HOW???


thanks SteveTheSki
0
stevetheski
Asked:
stevetheski
  • 4
  • 3
  • 2
  • +1
1 Solution
 
Fahad MukhtarDistinguished EngineerCommented:
YES, if you give the a proper size in your textbox eg :
200,200
thats how:
tabControl1.Size = new Size(int.Parse(textBox1.Text.Split(',')[0]),int.Parse(textBox1.Text.Split(',')[1]));
0
 
stevetheskiAuthor Commented:
Not the size of the Control the size of the tab like when a user presses shift-tab when they are in a textbox that allows tabs.
0
 
Fahad MukhtarDistinguished EngineerCommented:
sorry i misunderstood..
you can do this (but in a limited way by using richtextbox)
private void button3_Click(object sender, System.EventArgs e)
{

richTextBox1.SelectAll();
richTextBox1.SelectionTabs = new int[] {100,200,300};
      }
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
TheAvengerCommented:
For a simple TextBox it is not possible.
0
 
stevetheskiAuthor Commented:
Damnit, I meant to split the points 50/50 and have desp's ansewr as accepted and theAvengers as assisted.

SteveTheSki
0
 
Fahad MukhtarDistinguished EngineerCommented:
no problem
0
 
stevetheskiAuthor Commented:
DESP if you can find a way let me know and i wil :)
0
 
SeanFuhrmannCommented:
This is possible with a small amount of code.

First off add System.Runtime.InteropServices to your using statements.

Setup the external method with the following code anywhere in your class:

[DllImport("user32.dll", EntryPoint = "SendMessage")]
private static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, int[] lParam);

Add this method and call it when your form is created:

private void SetTabSizeOnTextBox(TextBox textBox, int tabSize)
{
   // This the # of tabs to define
   int iNumTabs = 20;

   // Create our array to hold each tabstop
   int[] arTabs = new int[iNumTabs];

   // Loop through each tabstop and set the location of the tabstop
   for (int i = 0; i < iNumTabs; i++)
      arTabs[i] =  tabSize * 4 * (i + 1);

   // Send the message to the textbox control (203 = EM_SETTABSTOPS)
   SendMessage(textBox.Handle, 203, iNumTabs, arTabs);
}


Example calling method:

SetTabSizeOnTextBox(txtData, 2);

I hope this helps!
0
 
stevetheskiAuthor Commented:
sean,

I will check that out.  Just had a baby yesterday so im not sure how long it will take.  but if it works I will open another q to give some points

Steve
0
 
SeanFuhrmannCommented:
Steve,

Congratulations on the baby!  

I just happened to be digging around trying to figure this out for myself this morning and that was the only solution I could come to, but it seems to work well on my end.

Sean
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now