Page 1 of 2
Tab Key on RichText
Posted: Thu Mar 16, 2006 6:22 pm
by reinaldocrespo
Hi.
Pressing tab while on a Richtext control is not inserting spaces, but instead it is highlighting the full text. How can I change this behavior?
Thank you,
Reinaldo.
Posted: Thu Mar 16, 2006 9:30 pm
by Antonio Linares
Reinaldo,
Is the richedit control placed on a dialogbox ?
Posted: Thu Mar 16, 2006 9:41 pm
by reinaldocrespo
Yes. Inside a "SysTabControl32" that is inside a Dialog.
Posted: Thu Mar 16, 2006 9:56 pm
by Antonio Linares
Reinaldo,
Please try this:
oRichEdit:nDlgCode = DLGC_WANTALLKEYS
Posted: Thu Mar 16, 2006 11:15 pm
by reinaldocrespo
Nope. Didn't do it. Same behavior.
Reinaldo.
Posted: Fri Mar 17, 2006 2:43 pm
by reinaldocrespo
Si se te ocurre alguna otra cosa, plis...
Posted: Fri Mar 17, 2006 4:48 pm
by Antonio Linares
Reinaldo,
Estamos investigándo, te contestamos cuanto antes.
Re: Tab Key on RichText
Posted: Fri May 15, 2009 12:47 am
by reinaldocrespo
Hi.
I still need to find a way to insert a tab (to indent the paragraph) on a richtext control.
I found this vb code to do the job. The problem is that I don't know how to translate the constant vbTab.
Code: Select all
Private Sub ctlRichText1_KeyDown(KeyCode As Integer, _
ByVal Shift As Integer)
Dim rtf As RichTextBox
Set rtf = Me!ctlRichText1.Object
If KeyCode = 9 Then ' TAB key was pressed.
' Ignore the TAB key, so focus doesn't
' leave the control
KeyCode = 0
' Replace selected text with the tab character
rtf.SelText = vbTab
End If
End Sub
Does anybody know how?
thank you,
Reinaldo.
Re: Tab Key on RichText
Posted: Fri May 15, 2009 6:10 am
by anserkk
Dear Mr.Reinaldo,
After reading the code, I assume that the value of the constant vbTab should be Space(4) or Space(5) ( whatever the length occupies in a line when ever we press the TAB key).
The code is just trying to ignore the TAB character and is replacing TAB with VbTab (VbTab should be character type, filled with blank space)
Regards
Anser
Re: Tab Key on RichText
Posted: Fri May 15, 2009 9:08 pm
by reinaldocrespo
I wish it was that simple. RichText works a little different. I think that we are going to need a wrapper function for the SelText property/method? and also the value of vbTab. I whould think that there are more people working with RichText controls in this forum.
Please help!
Here is another sample I found using Delphi that calls SelText.
Code: Select all
//richEdit1 of type TRichEdit
with richEdit1 do
begin
//move caret to end
SelStart := GetTextLen;
//add one unformatted line
SelText := 'This is the first line' + #13#10;
//add some normal font text
SelText := 'Formatted lines in RichEdit' + #13#10;
//bigger text
SelAttributes.Size := 13;
//add bold + red
SelAttributes.Style := [fsBold];
SelAttributes.Color := clRed;
SelText := 'About';
//only bold
SelAttributes.Color := clWindowText;
SelText := ' Delphi ';
//add italic + blue
SelAttributes.Style := [fsItalic];
SelAttributes.Color := clBlue;
SelText := 'Programming';
//new line
SelText := #13#10;
//add normal again
SelAttributes.Size := 8;
SelAttributes.Color := clGreen;
SelText := 'think of AddFormattedLine custom procedure...';
end;
Reinaldo.
Re: Tab Key on RichText
Posted: Sat May 16, 2009 2:15 pm
by reinaldocrespo
In an effort to get someone interested, I post my latest findings on the subject.
I'm working with a few tabs on a Dialog window from resources. Each tab contains a richtext control where the user may transcribe text.
With oRtf:bKeyChar I'm able to trap the tab key. To insert the tab character I'm doing this in bKeyChar code block:
Code: Select all
...
RELoadRTF( ortf:hWnd, chr( 9 ) + Chr( 0 ), SF_TEXT )
FwKeyboard( ortf, VK_RIGHT ) //otherwise all text is highlighted. don't know why
The problem is that before the tab key gets intercepted by oRtf:bKeyChar for some reason the cursor moves to the beginning of the text on the oRtf control, thus all/any tab key only gets inserted at the start of the text. Any attempt to find cursor position in bKeyChar yields zero (oRtf:GetPos()). It seems like some other control is trapping the tab key before ortf:bKeyChar does.
Any ideas?
Reinaldo.
Re: Tab Key on RichText
Posted: Sat May 16, 2009 5:24 pm
by James Bott
Reinaldo,
Maybe this will help:
http://support.microsoft.com/kb/170141
Have you tried using bKeyDown?
James
Re: Tab Key on RichText
Posted: Sat May 16, 2009 5:38 pm
by reinaldocrespo
Hi James;
bKeyDown does not seem to trap VK_TAB. Actually I could not trap any keystrokes at all with method keydown() of class TRichEdit. Here is how I know:
Code: Select all
*-------------------------------------------------------------------------------------------------------------------------------
METHOD KeyDown( nKey, nFlags ) CLASS RchEdt
logfile( "trace.log", { "Keydown", nKey } )
::PostMsg( FM_CHANGE ) //FM_HIGHLIGHT )
Return Nil //Super:KeyDown( nKey, nFlags )
The sample you cite is the one I used to get this far. I posted it in this same thread above. The problem seems to be a fwh problem. VB and Delphi samples assume the cursor has not moved.
The reason I know the cursor is moving just before bKeyDown is called when VK_TAB is pressed, is because I traced ortf:getpos() after each key stroke. For some reason the cursor position is reset to the origin when VK_TAB is pressed. Only after that my bKeyChar gets executed.
Reinaldo.
Re: Tab Key on RichText
Posted: Sat May 16, 2009 6:48 pm
by mmercado
Hi Reinaldo:
Try next changes in KeyChar and KeyDown methods of TRichEdit class:
Method KeyChar:
Code: Select all
METHOD KeyChar( nKey, nFlags ) CLASS TRichEdit
if ::lReadOnly .and. ! GetKeyState( VK_ESCAPE )
return 0
endif
if nKey == VK_TAB // added by mmercado
Return 0
endif
Super:KeyChar( nKey, nFlags )
::PostMsg( FM_CHANGE )
if ::lHighlight
::PostMsg( FM_HIGHLIGHT )
endif
return nil
Method KeyDown:
Code: Select all
METHOD KeyDown( nKey, nFlags ) CLASS TRichEdit
if ( nKey == VK_INSERT .and. GetKeyState( VK_SHIFT ) .or. ;
nKey == Asc( "V" ) .and. GetKeyState( VK_CONTROL ) )
if ! ::lReadOnly
::Paste()
::PostMsg( FM_CHANGE )
endif
return 0
endif
if ::lReadOnly
if nKey == VK_BACK .or. nKey == VK_DELETE .or. nKey == VK_RETURN
return 0
endif
endif
if nKey == VK_TAB // added by mmercado
::insertRtf( Chr( 9 ) )
::PostMsg( FM_CHANGE )
Return 0
endif
Super:KeyDown( nKey, nFlags )
::PostMsg( FM_CHANGE )
if ::lHighlight
if nKey == VK_DELETE .or. nKey == VK_BACK
::PostMsg( FM_HIGHLIGHT )
endif
endif
return nil
Un abrazo.
Manuel Mercado
Re: Tab Key on RichText
Posted: Mon May 18, 2009 9:43 pm
by reinaldocrespo
Manuel --Hola. es grato ver tu respuesta.
I have created a reduced self-contained sample that demonstrates how the tab key is handled in this particular situation by FW. If any of you would like to help, I can send the sample via email. BTW, I'm willing to pay for the solution.
The self-contained-reduced sample is a single .prg + .rc that can be compiled with the compile batch command in fw/samples.
Thank you all.
Reinaldo.