Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

AutoIndent (Auto Indent) in RichTextBox Control

Posted on 2000-03-25
7
Medium Priority
?
973 Views
Last Modified: 2010-05-18
Hi Experts,
I am making a small customized Editor in vb6 and am using a RichTextBox.  Every thing is fine so far... but now i am stuck at a point where when the user presses enter key the cursor should move to then next line and automatically indent to the number of tabs pressed in the previous line... Just like VB's own IDE and Word etc.

i have looked at SelTabCount, SelTabs, SelIndent properties but am totally lost and have no iedea where to go from here onwards....

a quick response will be much appriciated.

thanx,
msa.

0
Comment
Question by:msali
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 14

Expert Comment

by:mcrider
ID: 2656459
Here's a quick example you can try... It may not be perfect, but it will give you a general idea...

1) Start a new project.

2) Add a richtextbox control to the form.

3) Add the following code to the declarations section of the form:

'-------------------------------------------------------------------------------
    Dim arrTabStop() As Boolean
    Dim TabCounter As Long
    Dim InhibitTabCount As Boolean
    Dim EnterProcessing As Boolean
    Private Declare Function LockWindowUpdate Lib "user32" _
        (ByVal hwndLock As Long) As Long
    Private Sub Form_Load()
        RichTextBox1.Text = ""
    End Sub
    Private Sub RichTextBox1_GotFocus()
          'Store the TabStop property for each control on the
          'form and then set the TabStop property of each
          'control to False
          ReDim arrTabStop(0 To Controls.Count - 1) As Boolean
          For i = 0 To Controls.Count - 1
             arrTabStop(i) = Controls(i).TabStop
             Controls(i).TabStop = False
          Next
    End Sub
    Private Sub RichTextBox1_KeyPress(KeyAscii As Integer)
        Dim iVal As Long
       
            Select Case KeyAscii
                Case 8 'BACKSPACE
                    With RichTextBox1
                        If .GetLineFromChar(.SelStart) = 0 Then
                            If .SelStart <= TabCounter + 1 Then
                                TabCounter = TabCounter - 1
                            End If
                        Else
                            If InhibitTabCount = False Then
                                TabCounter = TabCounter - 1
                            Else
                                If InStr(.SelStart - 2, .Text, vbCrLf) > 0 Then
                                    TabCounter = TabCounter - 1
                                End If
                            End If
                        End If
                        If TabCounter < 0 Then TabCounter = 0
                    End With
                   
                Case 9 'TAB
                    If InhibitTabCount = False Then
                        TabCounter = TabCounter + 1
                    End If
                   
                Case 13 'ENTER
                    If EnterProcessing = False Then
                        EnterProcessing = True
                        InhibitTabCount = True
                        SendKeys "~", True
                        LockWindowUpdate RichTextBox1.hWnd
                        For iVal = 1 To TabCounter
                            SendKeys "{TAB}", True
                        Next iVal
                        LockWindowUpdate 0&
                        InhibitTabCount = False
                        EnterProcessing = False
                        KeyAscii = 0
                    End If
                   
                Case Else 'ALL OTHER KEYS
                    InhibitTabCount = True
            End Select
    End Sub
    Private Sub RichTextBox1_LostFocus()
          'Restore the Tabstop property for each control on the form
          For i = 0 To Controls.Count - 1
             Controls(i).TabStop = arrTabStop(i)
          Next
    End Sub
'-------------------------------------------------------------------------------


4) Run the program and then type:

   {TAB}{TAB}This is a test

When you hit the ENTER key, the next line will start indented 2 tabs...


Play around with it...


Cheers!®©


0
 

Author Comment

by:msali
ID: 2660245
Thanx for the code it works for me so far... and will modify it to my custom need....

would like to give u points for it .... so pls lock it so that i can give u points.

later,
msa.
0
 

Author Comment

by:msali
ID: 2660250
Thanx for the code it works for me so far... and will modify it to my custom need....

would like to give u points for it .... so pls lock it so that i can give u points.

later,
msa.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 14

Accepted Solution

by:
mcrider earned 400 total points
ID: 2661229
Posting for points... ;)


Cheers!®©
0
 

Author Comment

by:msali
ID: 2662771
just a clearification....what is the purpose of LockWindowUpdate API

thanx
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2664828
LockWindowUpdate freezes the update of the hWnd passed to it... In this case, it freezes the RTbox so that the tabs sent to the RTbox are not seen "one at a time"... All of the tabs are sent with the control locked and then it's unlocked to refresh the control.


Thanks for the points! Glad I could help!


Cheers!®©
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2664833
By the way to unlock the last LockWindowUpdate, you do:

   LockWindowUpdate 0&


Cheers!®©
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question