Results 1 to 22 of 22

Thread: [RESOLVED] RictTextBox Question

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Resolved [RESOLVED] RictTextBox Question

    I got some code from a VB project that has a lot of editing features for a RichTextBox. When selecting a word, multiple words, or the entire text the selected text is highlighted in black. How can I change this to be the same color used when selecting in VB projects (dark blue)?


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  2. #2
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: RictTextBox Question

    The RichTextBox control appears to have no such property nor method that can change the color of the selection rectangle. Neither does the API Rich Edit control. That could be because the RichTextBox control simply inverts the ForeColor and BackColor of the selection.


    EDIT

    The Rich Edit control used in WordPad (v4.0 I believe) highlights characters using the same fore and back color as that of the Edit control.
    Last edited by Bonnie West; Jun 21st, 2013 at 02:21 PM.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  3. #3
    Hyperactive Member Lenggries's Avatar
    Join Date
    Sep 2009
    Posts
    353

    Re: RictTextBox Question

    Yeah, what Bonnie said. If you want dark blue highlighting, you'll need to change the BackColor to FFFFFF - (Dark Blue)

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: RictTextBox Question

    RichTextBox1.BackColor = &H00FFFFFF&

    Still comes out black


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: RictTextBox Question

    Quote Originally Posted by Bonnie West View Post
    The RichTextBox control appears to have no such property nor method that can change the color of the selection rectangle. Neither does the API Rich Edit control. That could be because the RichTextBox control simply inverts the ForeColor and BackColor of the selection.


    EDIT

    The Rich Edit control used in WordPad (v4.0 I believe) highlights characters using the same fore and back color as that of the Edit control.
    Years ago I did it using API but that code is long lost. Probably some code I got from LaVolpe


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  6. #6
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: RictTextBox Question

    Quote Originally Posted by jmsrickland View Post
    Years ago I did it using API but that code is long lost. Probably some code I got from LaVolpe
    Interesting. However, I don't know how it can be done, if it can even be done at all. Perhaps there's an API message I've missed in the link I've posted above...
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  7. #7
    Hyperactive Member Lenggries's Avatar
    Join Date
    Sep 2009
    Posts
    353

    Re: RictTextBox Question

    Quote Originally Posted by jmsrickland View Post
    RichTextBox1.BackColor = &H00FFFFFF&

    Still comes out black
    I said FFFFFF - (Dark Blue), not just FFFFFF. Let's say your shade of dark blue is 991111 (bear in mind, in VB6, RGB values are actually ordered as BGR), then to get 991111 as your highlight color, use FFFFFF - 991111 = 66EEEE. So to make the highlight 991111, use:

    Code:
    RichTextBox1.BackColor = &H0066EEEE&
    Last edited by Lenggries; Jun 21st, 2013 at 03:41 PM. Reason: typo

  8. #8
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: RictTextBox Question

    Oh sure NOW you clear that up ... it wasn't obvious it was a formula... you could have explained it that it needed to be white (FFFFFF) minus the dark blue value ... when I read it, I thought you were trying to say that FFFFFF was Dark Blue... I wondered what world you lived in and if I could get in on your reality...


    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  9. #9

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: RictTextBox Question

    I thought you were trying to say that FFFFFF was Dark Blue.

    Me too.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  10. #10

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: RictTextBox Question

    Quote Originally Posted by Bonnie West View Post
    Interesting. However, I don't know how it can be done, if it can even be done at all. Perhaps there's an API message I've missed in the link I've posted above...
    I'm searching through my mind trying to recall the circumstances when and how and who. It seems to me that it was a either a custom control (by LaVolpe) or something and he was spending a lot of time helping me with this but I don't think it involved any of those EM_ constants; more like using drawing APIs (DrawText, Rectangles, etc).


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  11. #11
    Hyperactive Member Lenggries's Avatar
    Join Date
    Sep 2009
    Posts
    353

    Re: RictTextBox Question

    Quote Originally Posted by techgnome View Post
    I wondered what world you lived in and if I could get in on your reality...
    All it takes is the right prescription medication, allergies, and a lot of missing sleep.

    To the OP... not sure if any of this will actually help you, since it has the side effect of changing the background from white to a sickly yellow, but if it's dark blue highlighting you want, what's a little sickly yellow background matter, eh?

  12. #12

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: RictTextBox Question

    Sickly yellow.

    Nice Adjective. But yes, it does matter.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  13. #13
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: RictTextBox Question

    Quote Originally Posted by Bonnie West View Post
    The Rich Edit control used in WordPad (v4.0 I believe) highlights characters using the same fore and back color as that of the Edit control.
    That's probably Rich Edit version 4.1, Msftedit.dll. The VB6 RTB uses Riched20.dll (versions 2.0 or 3.0) indirectly via Riched32.dll (Rich Edit version 1.0) emulation.

    See About Rich Edit Controls


    So unless you create a naked Win32 control or a 3rd party ActiveX wrapper control instead of using the VB6 RTB control you don't have the capability in VB6.


    Turns out the version is the issue, as shown here:

    Name:  sshot2.png
Views: 165
Size:  18.3 KB

    Selected text shows as white on blue
    Attached Files Attached Files
    Last edited by dilettante; Jun 21st, 2013 at 08:20 PM.

  14. #14

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: RictTextBox Question

    Can it be typed into?


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  15. #15
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: RictTextBox Question

    You can do anything possible using the VB6 RichTextBox (and more), but you have to do 100% of the low-level programming required.

    This can mean subclassing techniques and callbacks as well as a long list of window messages and function calls. See:

    Rich Edit Control Reference


    But there are limits to what we can do with these eaily from VB6 programs. So most people just use the RichTextBox.
    Last edited by dilettante; Jun 22nd, 2013 at 08:03 AM.

  16. #16

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: RictTextBox Question

    I'll just use a regular Textbox.

    Thanks all for your help


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  17. #17
    Banned
    Join Date
    Nov 2012
    Posts
    1,171

    Re: [RESOLVED] RictTextBox Question

    it is possible had this done in past when i made a tool

    6am got bad tummy

  18. #18
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    Re: [RESOLVED] RictTextBox Question

    As everyone here pointed out, there it no property to change selection color, but there is always a work around!

    My solution is not complete, as I could only spend 20min on this.

    The only problem that I need to find is if the selection contains vbNewLine, in other words if you select 2 (or more) lines it will not select properly.
    How to fix this would be to verify if how many vbNewLine the selected text has, and then create a different picturebox (picbox array) for each line so it looks exactly like a real selection.

    But anyways, have a look and play with it, if its too hard well at least you tried, I might give it another shot in the next couple days.
    Also, to change the selection color you need to change the picture1.backcolor.

    Note: You can delete the commandbuttons, I noticed I did not delete them!
    Attached Files Attached Files

  19. #19

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: [RESOLVED] RictTextBox Question

    Actually, Max, I switched over to a regular Textbox as it already highlights in dark blue. Also, the regular Textbox has all the properties I need for the project I'm working on. I can still do all the editing features that I want like Undo, Redo, Cut, Copy, Paste, Delete, Select All, Find, Find Next, and Replace. Of course I have to code for these but I had to code for these anyway with a RichTextBox.

    Let me ask you a question. What happens if you start at any given point in the text and drag the mouse over the text to another point. Will it highlight in dark blue with white text?

    EDIT: I ran your code. Not too crazy about it as I don't understand your method. When I drag over text in the textbox it totally covers the text in dark blue.

    What gets me is why did MS design the regular textbox to highlight with white text on dark blue and for the rich text box it is simply inverted text on black. I noticed that when you select lines in the VB design mode it does white on dark blue even if the text is colored. Wonder what control they used for the editor.

    I'm sure that I had resolved this issue some time back. I can just see it in my mind that LaVolpe and I spent several days on this when finally he came up with a solution. I seem to remember it involved using APIs like DrawText and figuring out what the overall area is that was selected and coloring that in dark blue then drawing text over it in white. Now if I can find my text search app I could just select a drive and search for "DrawText". It finds text within files. Oh, where did I put that app.
    Last edited by jmsrickland; Jun 23rd, 2013 at 02:03 PM.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  20. #20
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    Re: [RESOLVED] RictTextBox Question

    Ya I'm not too crazy about it to haha, but I was just trying to make up something.

    It highlights the text in dark blue (on my pc anyways).
    If I change the picture1.backcolor it will select in that color.
    I thought that's what you were trying to do, make a function to change selection color, so that's kind of what I did.

    It's all good I would probably make my own usercontrol for this instead.

    I see that you used a textbox instead, so I won't bother trying to get my code to work properly


    (Not related to this Thread)

    Have you got your chat program "sound wave" to work properly, like you wanted?
    Whenever you do I want to have a little demo of it, if possible of course.

  21. #21

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: [RESOLVED] RictTextBox Question

    @Max

    I have a chat application that shows the sine wave of the messages sent from one user to another. It is not really in real-time however. It works by sending the sound bytes to the other user and that app takes the sound data and converts it to a sine wave on a picturebox that is hidden under another picturebox. Then as the sound is being played back the top picturebox moves from left to right across the under picturebox revealing the sine wave in sync with the sound as it is being heard. This gives the appearance of real-time although it isn't.

    I have another application that allows talking into a mic and showing the sine wave in real time but this only works on the same application. The problem here is I haven't yet figured out how to send the sound and produce the sine wave in real time on the receiving app.

    I have a third application that allows chat in real time but doesn't display any sine wave.

    So, I have the ingredients; I just don't have the recipe to put it all together.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  22. #22
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    Re: [RESOLVED] RictTextBox Question

    Sounds like your almost there.
    Keep me (or us) posted.
    Keep up the good work!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width