?
Solved

RichTextBox Properties

Posted on 2015-01-12
14
Medium Priority
?
91 Views
Last Modified: 2015-01-12
Hi all,
Is there any way to block the user create a new line in RichTextBox?  I want user edit the texts inside but he will not be able to crete a new line
and how I block the user entering any another language characters except english letters in richtextbox?
Thank you
0
Comment
Question by:hakanogu
[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
  • 8
  • 5
14 Comments
 
LVL 49

Expert Comment

by:Martin Liss
ID: 40544943
For the first part of your question, do this In the change event for your richtextbox

Private Sub MyRTB_Change()
Const EM_GETLINECOUNT As Long = &HBA


Dim linecount As Long
linecount = SendMessage(txtEdit.hWnd, _
                  EM_GETLINECOUNT, 0, 0)
If linecount >= 4 Then ' allow 3 lines
    Exit Sub
End If
End Sub

Open in new window

0
 

Author Comment

by:hakanogu
ID: 40545025
Hello martin,
İt is asking SendMessage function and txtEdit variable for your code.
0
 
LVL 49

Expert Comment

by:Martin Liss
ID: 40545047
Change txtEdit to the name of your richtextbox.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:hakanogu
ID: 40545061
I am taking warning forSendMessage as "sub or function is not defined"
0
 
LVL 49

Expert Comment

by:Martin Liss
ID: 40545067
At the top of your form's code put

Private Declare Function SendMessage Lib "user32" Alias _
 "SendMessageW"(ByVal hwnd As Long, ByVal wMsg As Long, _
 ByVal wParam As Long, lParam As Any) As Long

Open in new window

0
 

Author Comment

by:hakanogu
ID: 40545085
ın general declerations
Private Declare Function SendMessage Lib "user32" Alias "SendMessageW" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Private Sub RichTextBox4_Change()

Const EM_GETLINECOUNT As Long = &HBA


Dim linecount As Long
linecount = SendMessage(RichTextBox4.hwnd, EM_GETLINECOUNT, 0, 0)
If linecount >= 4 Then ' allow 3 lines
    Exit Sub
End If
End Sub

with this codes ı am still be able to add some lines Martin.
0
 
LVL 49

Expert Comment

by:Martin Liss
ID: 40545218
Please attach a zip file of your project.
0
 

Author Comment

by:hakanogu
ID: 40545248
Maybe You will not be able to run my project because of my INFITF application but my richbox inputs always changing according to my tree view.
V7.zip
0
 
LVL 46

Expert Comment

by:aikimark
ID: 40545292
I think you need to add some code to the Richtext KeyDown or KeyPress events.  Look for the enter key, with or without either the shift or Ctrl key being pressed.  Set the value of the parameter =0 to prevent the character from entering the control.

If you need to prevent a copy/paste of a new line/enter key, you will need to add code to the richtext control's change event.
0
 
LVL 49

Expert Comment

by:Martin Liss
ID: 40545293
Move the code to the KeyDown event and add line 10 and optionally 11.
Private Sub RichTextBox4_KeyDown(KeyCode As Integer, Shift As Integer)
Const EM_GETLINECOUNT As Long = &HBA


Dim linecount As Long

linecount = SendMessage(RichTextBox4.hwnd, EM_GETLINECOUNT, 0, 0)
'MsgBox linecount
If linecount >= 30 Then
    KeyCode = 0
    Beep
    Exit Sub
End If

End Sub

Open in new window

0
 
LVL 49

Expert Comment

by:Martin Liss
ID: 40545303
If you need to prevent a copy/paste of a new line/enter key, you will need to add code to the richtext control's change event.
@aikimark: I tested that and it's not necessary.

@hakanogu: Just a note to let you know that when you do this

Public oi, orow, ocl, i, J, k, l, m, n, p, r, s, t, u, uu, a, B, c, d, e, f As Integer

only f becomes an Integer and all the rest are Variants.
0
 
LVL 49

Accepted Solution

by:
Martin Liss earned 2000 total points
ID: 40545313
Here's a zip file with a bunch of things commented out so that at least the RTB can be accessed.
Q-28595021.zip
0
 

Author Comment

by:hakanogu
ID: 40545316
Actually just İ did with this code:

Private Sub RichTextBox4_KeyPress(KeyAscii As Integer)

         If KeyAscii = 13 Then  ' The ENTER key.
               ' Set the focus to the next control.
            KeyAscii = 0        ' Ignore this key.
         End If
End Sub
0
 
LVL 49

Expert Comment

by:Martin Liss
ID: 40545332
I was wrong when I said in response to aikimark that code in the Change event wasn't necessary. If there are already the maximum number of lines then you can't paste any more, but if there are less that that you can so keep my change event code along with the other code.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

777 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