Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Set tab spacing to 4 spaces in textboxcontrol
Message
General information
Forum:
ASP.NET
Category:
Forms
Miscellaneous
Thread ID:
00982103
Message ID:
00982552
Views:
25
This message has been marked as the solution to the initial question of the thread.
Zakaria,
I had no luck finding what you were looking for so I tried creating some ustom code. Add this code to the KeyPress event of the textbox control or to your custom textbox usercontrol. It should do what you want it to do. Keep in mind that the code inserts two spaces whenever the TAB key is pressed and not a tab character.
Hope this helps (if not that is ok too because I had fun writing the code <s>)
private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
	if (e.KeyChar == '\t')
	{
		int cursorPosition = ((System.Windows.Forms.TextBox) sender).SelectionStart;
		string beforeCursor = ((System.Windows.Forms.TextBox) sender).Text.Substring(0,((System.Windows.Forms.TextBox) sender).SelectionStart);
		string afterCursor = ((System.Windows.Forms.TextBox) sender).Text.Substring(((System.Windows.Forms.TextBox) sender).SelectionStart);
				
		((System.Windows.Forms.TextBox) sender).Text = beforeCursor + "  " + afterCursor;
		((System.Windows.Forms.TextBox) sender).SelectionStart = cursorPosition + 2;

		e.Handled = true;	
	}
}
Einar



>Hello All,
>
>How to setup the tabspacing to 4 spaces in multiline textboxcontrol instead of the default spacing?
>
>TIA.
Semper ubi sub ubi.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform