|
-
Nov 26th, 2008, 02:21 AM
#1
Thread Starter
New Member
Adding text box to rich text box
I'm developing a urdu editor software. I want to add text box to rich text box by clicking at a menu item. I have coded the rich text box for urdu language. The problem is how to use the same coding for the text box?
Thnx
-
Nov 26th, 2008, 08:50 AM
#2
Re: Adding text box to rich text box
A standard textbox doesn't support that.
If you need two textboxs for some reason, why aren't you using two richtextboxs?
-
Nov 27th, 2008, 01:54 AM
#3
Thread Starter
New Member
Re: Adding text box to rich text box
I am using a rich text box and i need to place a textbox on it at any position by clicking athe menu entry
-
Nov 27th, 2008, 03:27 AM
#4
Re: Adding text box to rich text box
you can try like this, it does not put the textbox in the richtextbox but over it
vb Code:
Text1.Move RichTextBox1.Left, RichTextBox1.Top Text1.ZOrder 0
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Nov 27th, 2008, 05:09 AM
#5
Thread Starter
New Member
Re: Adding text box to rich text box
-
Nov 27th, 2008, 08:56 AM
#6
Thread Starter
New Member
Re: Adding text box to rich text box
I have tried that but its not working. I have added following code to the click event of "Add Text" menu entry
Code:
Dim Text1 As TextBox
With Text1
ZOrder 0
End With
When i run it nothing happens. Any ideas.....
-
Nov 27th, 2008, 03:10 PM
#7
Re: Adding text box to rich text box
if you are creating a textbox at run time you need to add to the controls collection
if you are working with a textbox created at design time, do not declare it as a variable
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Nov 27th, 2008, 03:19 PM
#8
Re: Adding text box to rich text box
How about the following code
Code:
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private Sub Command1_Click()
SetParent Text1.hWnd, RichTextBox1.hWnd
End Sub
It will put the textbox inside the richtextbox, is that what you want?
-
Nov 28th, 2008, 04:41 AM
#9
Thread Starter
New Member
Re: Adding text box to rich text box
Its giving the runtime error # 91
Object variable or with block variable not set
-
Nov 28th, 2008, 05:29 AM
#10
Re: Adding text box to rich text box
i tested dee-u code in a new project, works fine
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Nov 28th, 2008, 09:07 AM
#11
Re: Adding text box to rich text box
 Originally Posted by yuleball
Its giving the runtime error # 91
Object variable or with block variable not set
You need to have a RichTextBox control in your form named RichTextBox1, and a Textbox named Text1. How are you doing it?
-
Dec 2nd, 2008, 11:29 PM
#12
Thread Starter
New Member
Re: Adding text box to rich text box
I have done that. thank you. Now problem is that i want to place this text box at the position of cursor e-g if the cursor is at line no 3 then this text box should be added at line no 3. Also when i have finished entering text in this text box, i want that cursor is placed below this text box.
-
Dec 3rd, 2008, 02:23 AM
#13
Re: Adding text box to rich text box
i don't believe you can do like that, i think the text in the richtext box will continue under /behind the textbox
looks like you should consider making a usercontrol
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Dec 3rd, 2008, 04:24 AM
#14
Thread Starter
New Member
Re: Adding text box to rich text box
-
Dec 3rd, 2008, 03:15 PM
#15
Re: Adding text box to rich text box
i had a thought about this, if you place an image (blank, no picture) of appropriate size (or resize to suit) in the richtextbox, then place your textbox over the image, the text should appear to wrap around the textbox
i have never tried to do this, and it might take some trial and error to make the textbox and image match size and position
in any case if you save or print the richtext using methods of the richtextbox the textbox will not be included
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Dec 3rd, 2008, 11:34 PM
#16
Re: Adding text box to rich text box
 Originally Posted by yuleball
Now problem is that i want to place this text box at the position of cursor e-g if the cursor is at line no 3 then this text box should be added at line no 3.
Heres a really-really simple example to position a textbox on the line the cursor is at, doesn't take into account mixed fonts/sizes, moving the vertical scrollbar while textbox is shown or anything like that though.
Code:
Option Explicit
' for scroll bar info
Private Declare Function GetScrollInfo Lib "user32.dll" (ByVal hwnd As Long, ByVal n As Long, ByRef lpScrollInfo As SCROLLINFO) As Long
Private Const SB_VERT As Long = 1
Private Const SIF_RANGE As Long = &H1
Private Const SIF_PAGE As Long = &H2
Private Const SIF_POS As Long = &H4
Private Type SCROLLINFO
cbSize As Long
fMask As Long
nMin As Long
nMax As Long
nPage As Long
nPos As Long
nTrackPos As Long
End Type
'for GetCurrentLine
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, _
ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const EM_LINEFROMCHAR = &HC9
' for get height of text
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Declare Function GetTextExtentPoint32 Lib "gdi32" Alias "GetTextExtentPoint32A" _
(ByVal hdc As Long, ByVal lpsz As String, ByVal cbString As Long, lpSize As POINTAPI) As Long
' var to hold height of text
Dim TxtHeight As Long
Private Sub ShowTextBox()
Dim TxtTop As Long, CurLine As Long
Dim sINFO As SCROLLINFO
' find pos of vert scrollbar
sINFO.cbSize = Len(sINFO)
sINFO.fMask = SIF_RANGE Or SIF_PAGE Or SIF_POS
GetScrollInfo RichTextBox1.hwnd, SB_VERT, sINFO
' what line is cursor on
CurLine = GetCurrentLine(RichTextBox1)
If CurLine > 0 Then TxtTop = (CurLine * TxtHeight)
' show Textbox
Text1.Visible = True
Text1.ZOrder 0
Text1.Move 0, TxtTop - sINFO.nPos
Text1.SetFocus
End Sub
Private Function GetCurrentLine(RTB As RichTextBox) As Long
GetCurrentLine = SendMessage(RTB.hwnd, EM_LINEFROMCHAR, ByVal RTB.SelStart, ByVal 0& + 1)
End Function
Private Sub Command1_Click()
ShowTextBox ' show text box
End Sub
Private Sub Form_Load()
Dim i As Integer
Dim TextSize As POINTAPI
Text1.Visible = False
Me.ScaleMode = vbPixels
Me.Font = "Courier New"
Me.FontSize = 12
GetTextExtentPoint32 Me.hdc, "8W", 2, TextSize ' get size of font
TxtHeight = TextSize.Y ' save text height
' set RTB font/size same as form so text height matches.
RichTextBox1.Font = Me.Font
RichTextBox1.Font.Size = Me.FontSize
' add some test text to the RTB control
RichTextBox1.Text = ""
For i = 1 To 20
RichTextBox1.Text = RichTextBox1.Text & "Line Number " & CStr(i) & vbCrLf
Next i
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then
KeyAscii = 0
Text1.Visible = False
End If
End Sub
-
Dec 4th, 2008, 06:17 AM
#17
Thread Starter
New Member
Re: Adding text box to rich text box
I have tried it but its not working. plz help
-
Dec 4th, 2008, 06:36 AM
#18
Re: Adding text box to rich text box
what do you mean by
I have tried it but its not working
?
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|