jvolkel

This may be a simple question, but I have not been able to find an answer yet. I am using the text box as a small word processor project and I don't like the way the tab key moves the cursor. It seems to indent about an inch and I would like to set it to maybe a half inch, or 4 spaces, or aqny other value. How can I do this I have looked in my.computer system.settings and no luck. Thanks.

Joe




Re: Visual Basic Express Edition setting tab key stops

EverydayHack

Disclaimer: Newbie the following is a newbie answer - Experienced coders please review and correct for accuracy.

As far as I can tell.....

Textbox class inherits most functionality from the TextBoxBase class...

TextBoxBase class only allows tab settings in the context of allowing the tab in the textbox or not.

Therefore if you want to add functionality you're looking at rolling your own.

And I don't think the source is available for TextBoxBase as it is a Windows System Control.

Have you considered multiple text boxes or implementing a table to represent the data you wish to display

Setting the font to Courier was always a nice trick I've used to get text to line up and tabs to be predictable.

You could also consider making a button append a text string to the value of the string displayed in the text box, but I see no ability to divine the cursors current position within the text box, so this would only work if your need for custom distances occurs at the end of the text box, instead of editing somewhere in the middle.






Re: Visual Basic Express Edition setting tab key stops

Tall Dude

Public Class Form1

Private Declare Function SendMessage Lib "user32" Alias _

"SendMessageA" (ByVal hwnd As IntPtr, ByVal wMsg As _

Integer, ByVal wParam As Integer, ByRef lParam As _

Integer) As Integer

Private Const EM_SETTABSTOPS As Integer = &HCB

Private Sub Form1_Load(ByVal sender As System.Object, ByVal _

e As System.EventArgs) Handles MyBase.Load

Me.TextBox1.AcceptsTab = True

' Set the tab stop width

SendMessage(TextBox1.Handle, EM_SETTABSTOPS, 1, 100)

' or

' Set variable distance tab stops

'Dim tabs() As Integer = {20, 130, 300}

'SendMessage(TextBox1.Handle, EM_SETTABSTOPS, tabs.Length, tabs(0))

End Sub

End Class






Re: Visual Basic Express Edition setting tab key stops

jvolkel

Thanks for the reply everydayhack. I found the "Tab enable" property but need more control. It looks like talldude has the answer in the next reply.




Re: Visual Basic Express Edition setting tab key stops

jvolkel

Thanks for the reply Talldude. This looks like it is what I wanted. I have printed your post out and am trying to determine just what it is doing. I have some experience using Basic, xBasic, and C so as a new VB user I want to know what's going on here and will have to search the documentation to make sure it is clear to me. That is the fun part of learning a new language for me. It means more to me than just typing in your code and having it work. Thanks again.

Joe






Re: Visual Basic Express Edition setting tab key stops

jvolkel

Hi again Tall Dude, I typed in the code that you provided and it worked like a charm. I replaced the 100 in lparam with 10 and got the stop where I wanted it.

I did some research into what is happening here and came up with the following. I would appreciate it if you could tell me if I am on the right track.

Here Goes:

It looks like we are adding the function SendMessage which is using the user32 function SendMessageA. We then set up an enumerator( ) called EM_SETTABSTOPS and insert the value &HCB (Dec 206 I think it was). This enumerator represents the index number for a wMsg (Windows Message ) and modifies the window for TextBox1 when we use the SendMessage function by sending wParam and lParam.

Is this correct

If so, is there any way to look up the wMsg commands that are available I tried searching the MSDN Library but have not had any luck yet. Thanks for your help!

Joe V.






Re: Visual Basic Express Edition setting tab key stops

Tall Dude

I am not an expert on WMsg commands and do not have

a handy reference on them either.

I had to look at numerous examples of the SendMessage dealing

with tab stops before I posted the answer I gave.

You may want to open a new thread with this additional question.

(I just an old hacker)






Re: Visual Basic Express Edition setting tab key stops

jvolkel

AHH...OK Thanks for the info Tall Dude, I will try the new thread route. Thanks for all the help.

Joe V.