Text control: desired behavior--HELP

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Eric B

    #1

    Text control: desired behavior--HELP

    I am looking for a text control (or API) that can emulate the behavior
    of CodeWrite where you can move the cursor in any direction on a blank
    text area and begin typing (so you are not confined to the left
    margin). Visual Basic used to be like this in Versions prior to 5.

    I can't for the life of me figure out what to call this "feature" so
    it has been hard to search for.

    Any help would be appreciated
  • Rick Rothstein

    #2
    Re: Text control: desired behavior--HELP

    > I am looking for a text control (or API) that can emulate the behavior[color=blue]
    > of CodeWrite where you can move the cursor in any direction on a blank
    > text area and begin typing (so you are not confined to the left
    > margin). Visual Basic used to be like this in Versions prior to 5.
    >
    > I can't for the life of me figure out what to call this "feature" so
    > it has been hard to search for.
    >
    > Any help would be appreciated[/color]

    I think the feature name you are thinking of is something like "free-form
    text entry".

    I've never seen CodeWrite, so I don't know how it operates; however, I've
    taken a guess. First and foremost, for this to make any sense in operation,
    you will have to use a fixed-width font so up/down arrows take you to a
    predictable location. I'd suggest you use something like Courier or Courier
    New (which looks smoother to me). Since you can put the cursor anywhere
    within the TextBox, I figured it should operate in TypeOver (as opposed to
    Insert) Mode, hitting return would just take you to the beginning of the
    next line (lines wouldn't be split), selections are replaced in place with
    the characters after it remaining in place, and so on.

    Here is some **rough** code that will give you an idea to get you started
    (you'll want to play with it, I'm sure). Place a TextBox on the form and set
    the Font to "Courier New" and pick a FontSize you like (do these at
    design-time only). Then paste this code into the form's code window. That
    should be all you need to do; just run the program and try it out.

    Rick - MVP

    Dim CharsWide As Long
    Dim LinesHigh As Long

    Private Sub Form_Load()
    Dim CharWidth As Long
    Dim CharHeight As Long
    With Text1
    Set Me.Font = .Font
    CharWidth = Me.TextWidth("X ")
    CharHeight = Me.TextHeight(" X")
    CharsWide = .Width \ CharWidth
    LinesHigh = .Height \ CharHeight
    For x = 1 To LinesHigh
    .SelText = String$(CharsWi de, " ")
    Next
    .MaxLength = CharsWide * LinesHigh
    End With
    End Sub

    Private Sub Text1_KeyDown(K eyCode As Integer, Shift As Integer)
    Dim TextFromClipBoa rd As String
    Dim CurrentSelStart As Long
    With Text1
    If KeyCode = vbKeyDelete Then
    If .SelLength = 0 Then .SelLength = 1
    CurrentSelStart = .SelStart
    .SelText = String(.SelLeng th, " ")
    .SelStart = CurrentSelStart
    KeyCode = 0
    ElseIf KeyCode = vbKeyBack Then
    .SelLength = 0
    ElseIf (Shift = vbShiftMask And KeyCode = vbKeyInsert) Or _
    (Shift = vbCtrlMask And KeyCode = vbKeyV) Then
    CurrentSelStart = .SelStart
    TextFromClipBoa rd = Clipboard.GetTe xt
    .SelText = String(.SelLeng th, " ")
    .SelStart = CurrentSelStart
    .SelLength = Len(TextFromCli pBoard)
    .SelText = TextFromClipBoa rd
    KeyCode = 0
    End If
    End With
    End Sub

    Private Sub Text1_KeyPress( KeyAscii As Integer)
    With Text1
    If KeyAscii = 13 Then
    If .SelStart \ CharsWide < LinesHigh - 1 Then
    SendKeys "{DOWN}{HOM E}"
    End If
    KeyAscii = 0
    ElseIf KeyAscii = 8 Then
    If .SelStart Then
    .SelStart = .SelStart - 1
    .SelLength = 1
    .SelText = " "
    .SelStart = .SelStart - 1
    End If
    KeyAscii = 0
    ElseIf KeyAscii > 31 Then
    .SelLength = 1
    End If
    End With
    End Sub


    Comment

    • Eric B

      #3
      Re: Text control: desired behavior--HELP

      "Rick Rothstein" <rickNOSPAMnews @NOSPAMcomcast. net> wrote in message news:<07mdnV4hO 61Rn9XdRVn-uA@comcast.com> ...
      [color=blue]
      > Then paste this code into the form's code window. That
      > should be all you need to do; just run the program and try it out.[/color]


      Thanks, looks like I was already ALMOST there. What I was doing was
      about 90% of what your code does. I'll try it. Thanks!!!!

      Comment

      • Rick Rothstein

        #4
        Re: Text control: desired behavior--HELP

        > > Then paste this code into the form's code window. That[color=blue][color=green]
        > > should be all you need to do; just run the program and try it out.[/color]
        >
        > Thanks, looks like I was already ALMOST there. What I was doing was
        > about 90% of what your code does. I'll try it. Thanks!!!![/color]

        I'm not offering my code up as an ideal approach to your problem, just as a
        possible starting point. I really don't have a feel for an interface of this
        type. For example, while I wanted the BackSpace key to work like most people
        expect, I didn't have any idea how to approach it here (so I just made it
        erase the previous character). The problem in doing it the "right" way is
        what to you do with the remainder of the text on subsequent lines? On the
        same line, we could just slide the rest of the line over one character; but
        what about the next line down? Does its first character wrap to the last
        character position of the current line? Or to the end of the text on the
        current line? It probably depends on how it came into being... by word
        wrapping or by hitting a carriage return, there is no way of knowing. I
        guess we could track the carriage returns, but what if more text was added
        on the line after the carriage return (something that can't be done in a
        normal text editor without adding spaces in front of the carriage return
        plus the new text). And handling the BackSpace key is just one of the
        questions I had. Anyway, good luck with the program.

        Rick - MVP


        Comment

        Working...