[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

RichTextBox Properties

Posted on 2015-01-12
14
Medium Priority
?
92 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

650 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