Results 1 to 13 of 13

Thread: Certain Text Colour

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2012
    Posts
    171

    Certain Text Colour

    Hello again, another one to do with colour.

    In my system im making, i have a large textbox which is called remarks. when i double click on this texbox it opens a remarks entry window. I then type what i need to type in the remarks entry window textbox and then press accept (button1). The text in this textbox is then transfered into the larger textbox on the other page. How do i make the text ive just written in the remarks entry window textbox the colour red when i press the button. i dont want the whole textbox red because i have other text in the textbox i want blue like for example the date and time the remarks was entered and the user id etc.

    Can anyone help?

    Cheers

  2. #2
    Addicted Member MetalInquisitor's Avatar
    Join Date
    Sep 2012
    Posts
    143

    Re: Certain Text Colour

    You would need a RichTextBox for remarks, because I doubt what you want can be donde with the normal TextBox. I could be wrong though.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Oct 2012
    Posts
    171

    Re: Certain Text Colour

    do you know how i could have only the text i have written to be red and the date/time user id and another label on the main screen is coloured blue? Exmaple: When i type in the remarks and then press the button the textbox on the main screen should look like this:


    27/04/2013 12:56:00 012345 H4067

    VBBHKVB BKHSGSABSDBVJSDBSDBSDBSDBVSDBVSBVB



    The date and time and the user id and the other label are at the top of the textbox and a few spaces down is the remarks that i had written.

    The textbox is set to appendtext.

  4. #4
    Addicted Member MetalInquisitor's Avatar
    Join Date
    Sep 2012
    Posts
    143

    Re: Certain Text Colour

    I don't think I've ever worked with the RichTextBox, but at a quick glance I think the answer could be in its SelectionColor property.

  5. #5
    Addicted Member MetalInquisitor's Avatar
    Join Date
    Sep 2012
    Posts
    143

    Re: Certain Text Colour

    Check out this example. I know it's in C# but you would just have to do some very minor adapting to VB: http://www.dotnetperls.com/richtextbox

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Oct 2012
    Posts
    171

    Re: Certain Text Colour

    ah okay thanks, ive checked it out and only could find SystemColorsChanged but im not sure what the coding would be either. but thanks anyway.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Oct 2012
    Posts
    171

    Re: Certain Text Colour

    if im honest i have no idea what i would need to change from C# ive never used C# before. but thanks anyway

  8. #8
    Addicted Member MetalInquisitor's Avatar
    Join Date
    Sep 2012
    Posts
    143

    Re: Certain Text Colour

    Like I said, the SelecionColor property. Check this out (add a textbox, a richtextbox and a button to a form):

    vb.net Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.  
    3. With RichTextBox1
    4.             .SelectionColor = Color.Black
    5.             .AppendText("THIS WILL APPEAR IN BLACK ")
    6.             .SelectionColor = Color.Red
    7.             .AppendText("Your textbox1.text in red: " & TextBox1.Text)
    8.             .SelectionColor = Color.Blue
    9.             .AppendText(" THIS WILL APPEAR IN BLUE")
    10.         End With

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Oct 2012
    Posts
    171

    Re: Certain Text Colour

    thanks for that. Althought at the minute where it says selectioncolor theres a blue line underneath saying its not part of a string?

    Cheers

  10. #10
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Certain Text Colour

    .SelectionColor is a property of the RTB itself, not of the text. So ...

    RichTextBox1.Text.SelectionColor is wrong

    RichTextBox1.SelectionColor is right
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Oct 2012
    Posts
    171

    Re: Certain Text Colour

    This works well except for, when i execute the code more than once the blue text reverts to black and i need it to stay blue, the red seems to stay its just the blue text, other than that works like a treat!

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Oct 2012
    Posts
    171

    Re: Certain Text Colour

    Heres the code ive used provided on this thread. Ive taken the With and End With out as it didnt work with it (even the first time) the only thing now is it doesnt work everyother time more than once.


    Code:
    IE.RichTextBox1.SelectionColor = Color.Blue
            IE.RichTextBox1.AppendText(DateTime.Now & "                    " & LOGON.MaskedTextBox1.Text & "                    " & IE.Label6.Text & TextBox22.Text & TextBox22.Text)
            IE.RichTextBox1.SelectionColor = Color.Red
            IE.RichTextBox1.AppendText(TextBox21.Text & TextBox22.Text & TextBox22.Text & TextBox22.Text)
            Me.Close()

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    Oct 2012
    Posts
    171

    Re: Certain Text Colour

    Name:  work.png
Views: 65
Size:  7.0 KB
    Attached Images Attached Images  
    Last edited by Sean.Downes; Apr 27th, 2013 at 12:10 PM.

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