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
Printable View
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
A standard textbox doesn't support that.
If you need two textboxs for some reason, why aren't you using two richtextboxs?
I am using a rich text box and i need to place a textbox on it at any position by clicking athe menu entry
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
thnx i will try that
I have tried that but its not working. I have added following code to the click event of "Add Text" menu entry
When i run it nothing happens. Any ideas.....Code:Dim Text1 As TextBox
With Text1
ZOrder 0
End With
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
How about the following code
It will put the textbox inside the richtextbox, is that what you want?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
Its giving the runtime error # 91
Object variable or with block variable not set
i tested dee-u code in a new project, works fine
You need to have a RichTextBox control in your form named RichTextBox1, and a Textbox named Text1. How are you doing it?Quote:
Originally Posted by yuleball
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.
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
How can I do that?
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
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.Quote:
Originally Posted by yuleball
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
I have tried it but its not working. plz help
what do you mean by?Quote:
I have tried it but its not working