RichTextBox IgnoreKey?

RandomCoder

Well-Known Member
Licensed User
Longtime User
As the RichTextBox has no Events, how to achieve Ignore Key or move Focus.

I'm already using the door library and so have tried making the RichTextBox.Enabled = False but this greys everything out.

Ideally what I would like is a RichTetBox that cannot be edited by the user.
Also, is it possible to set the scrollbars to the top of the document in the event that a really long file has been loaded?

Regards,
RandomCoder.
 

RandomCoder

Well-Known Member
Licensed User
Longtime User
I've found a solution using the control events library.

B4X:
...
CntrlEvent.New1( RichText.ControlRef )
...

Sub CntrlEvent_GotFocus
   FrmObject.Value = TxtTsOrder.ControlRef
   FrmObject.RunMethod( "Focus" )
End Sub
This way the richtextbox never gets focus long enough to be able to enter any data :sign0060:

I'm still struggling with setting the scroll bar position though.
Plus another slightle improvement has arisen, Is it possible to set the print preview window to maximised?

Regards,
RandomCoder
 

agraham

Expert
Licensed User
Longtime User
Ideally what I would like is a RichTetBox that cannot be edited by the user
ControlEvents is really obsolete now that the Door library supports events. Try this, it also works on a TextBox.

Obj1.New1(False)
Obj1.Value = RTD.ControlRef
Obj1.SetProperty("ReadOnly", True)


I'm still struggling with setting the scroll bar position though
Try this, the RTD must have the focus so move the focus to it then move it away after if necessary.

Obj1.New1(False)
Obj1.Value = RTD.ControlRef
Obj1.RunMethod("Focus")
Obj1.SetProperty("SelectionStart", 0)
Obj1.SetProperty("SelectionLength", 0) ' may not need this
Obj1.RunMethod("ScrollToCaret", 0) ' probably will need this

Is it possible to set the print preview window to maximised?
It's already there, RTD.PrintPreviewState = 2
 

RandomCoder

Well-Known Member
Licensed User
Longtime User
Thanks AGraham, I'll try tomorrow as its late now.

Is it possible to set the print preview window to maximised?

..... It's already there, RTD.PrintPreviewState = 2
Note to myself... read the help files more thoroughly :sign0013:

Regards,
RandomCoder
 

RandomCoder

Well-Known Member
Licensed User
Longtime User
Just for completenes, and for anyone else that may have been following this thread.

ControlEvents is really obsolete now that the Door library supports events. Try this, it also works on a TextBox.

Obj1.New1(False)
Obj1.Value = RTD.ControlRef
Obj1.SetProperty("ReadOnly", True)

This works but still greys out the RichTextBox, much the same as setting the enable property to False.

Try this, the RTD must have the focus so move the focus to it then move it away after if necessary.

Obj1.New1(False)
Obj1.Value = RTD.ControlRef
Obj1.RunMethod("Focus")
Obj1.SetProperty("SelectionStart", 0)
Obj1.SetProperty("SelectionLength", 0) ' may not need this
Obj1.RunMethod("ScrollToCaret", 0) ' probably will need this

It's already there, RTD.PrintPreviewState = 2

This didn't work and also produces an error with this line Obj1.RunMethod("ScrollToCaret", 0), removing the ",0" got rid of the error but still did not move the scorll bar to the top of the page.

However! By moving the focus away from the RichTextBox as soon as it gets Focus, a side effect is that the scrollbars remain at the top of the page and the background is still white :cool:

Problem solved. I'll now remove the ControlEvents library and instead use the door library to catch the GotFocus event thus removing the need for an extra library. I think I'm nearly done now, thanks for all the help.

Regards,
RandomCoder
 

agraham

Expert
Licensed User
Longtime User
This works but still greys out the RichTextBox, much the same as setting the enable property to False.
Really? I just tried this on my RichTextBox demo and it doesn't gray out there but does stop user editing.

This didn't work and also produces an error with this line Obj1.RunMethod("ScrollToCaret", 0)
:signOops::sign0013: I normally try code before I post but, to quote Erel "It wasn't tested and therefore doesn't work". It should be

B4X:
Obj1.RunMethod2("ScrollToCaret", 0, "System.String") ' probably will need this

Actually I still haven't tested it but it should be OK now! :)
 

RandomCoder

Well-Known Member
Licensed User
Longtime User
@AGraham, By moving the Focus it now does everything that I need.

But now a new problem has arisen :sign0013:
A while ago you created me a FolderDialogDesktop.dll which basically works like the OpenDialog in B4PPC but returns the folder path instead of a file path.
The problem is that I get this error message when attempting to at the component....
---------------------------
Basic4ppc
---------------------------
An error occurred.

An item with the same key has already been added.
---------------------------
OK
---------------------------
Other components I already have installed are FormExesktop, ControlsExDesktop, SerialEx, and BinaryFile.

Regards,
RandomCoder
 

agraham

Expert
Licensed User
Longtime User
Actually I still haven't tested it but it should be OK now! :)
Actually it wasn't, too much speed without checking. I've just checked putting the code into my RichTextDemo program and your original amendment was correct and should have worked!

But now a new problem has arisen
That's because FolderDialog is now included in ControlsExDesktop, as from version 1.4, so you don't need a separate library.
 
Last edited:

RandomCoder

Well-Known Member
Licensed User
Longtime User
I can not emphasise this enough... your a star :sign0188:

Thanks,
RandomCoder
 

Zenerdiode

Active Member
Licensed User
I have a RichTextBox that is populated by incoming data from Serial Ports. I was wanting similar control of the RichTextBox to RandomCoder; however I wanted the box to scroll to the end of the data each time. I placed this at the end of my OnCom event Sub and I confirm it works;

B4X:
Obj1.Value=RichText.ControlRef
Obj1.RunMethod("Focus")
RichText.SelectionStart=StrLength(RichText.Rtf)
RichText.SelectionLength=0
Obj1.RunMethod("ScrollToCaret")
 
Top