tab size in a text box

G

Guest

Is there a easy way to set the tab size in a multiline textbox object? For
example, I want to change the tab character to be 4 spaces.
 
C

Carlos J. Quintero [.NET MVP]

I think that you have to use the Win32 API, something like this (VB.NET
code, but easy to follow):

Friend Shared Sub SetTextBoxTabStops(ByVal ctlTextBox As TextBox, ByVal
iNumberOfSpacesPerTab As Integer)

Const EM_SETTABSTOPS As Integer = &HCB
Const NUM_TABS As Integer = 10

Dim iCounter As Integer
Dim iArray(NUM_TABS) As Integer

For iCounter = 0 To NUM_TABS
iArray(iCounter) = iNumberOfSpacesPerTab * 4 * (iCounter + 1)
Next
SendMessage(ctlTextBox.Handle, EM_SETTABSTOPS, NUM_TABS, iArray)

End Sub

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
You can code, design and document much faster.
Free resources for add-in developers:
http://www.mztools.com
 
G

Guest

The proposed solution leaves somethings to be desired:
1) The namespace environment is undefined. This means, at least in my
standard VB.net 2003 world that SendMessage is NOT defined. Adminttedly this
is a csharp group, but the code sure looks like VB to me:)))

What makes it interesting is that if you type SendMessage in say the load
event of a form and hold the cursor over it there is a "definition" for it,
but it is private. Similarly if you do a show definition the object browser
suggests that it might be part of windows.forms.controls, but it doesn't
appear in the list of members.

2) According to the doco on the EM_SETTABSTOPS message the array is not
needed in this design. Just set spcaing*-4 and use an wparam = 1 and an
lparam = spacking

3) Why the designers of the class structure did not allow for this
functionality in textboxes is beyond me. They allow for accepting tabs but
not for setting the spacing!

4) All that said, I can't make it work. Suggestions please.



So what gives????? (I recognize that in the proposed code the winapi version
is being used - note passing the handle - and the private one doesn't require
a handle.

2) All that aside I'm not sure that it will work unless the textbox has some
special properties.

--
Regards,
Al Christoph
Senior Consultant and Proprietor
Three Bears Software, LLC
just right software @ just right prices @3bears.biz
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top