Spliting colored text
Spliting colored text
Spliting colored text
Spliting colored text
Spliting colored text
Spliting colored text Spliting colored text Spliting colored text Spliting colored text Spliting colored text Spliting colored text Spliting colored text Spliting colored text
Spliting colored text Spliting colored text
Spliting colored text
Go Back  Xtreme Visual Basic Talk > > > Spliting colored text


Reply
 
Thread Tools Display Modes
  #1  
Old 11-01-2010, 01:11 PM
mato900 mato900 is offline
Newcomer
 
Join Date: Nov 2010
Location: Slovenia
Posts: 9
Question Spliting colored text


First I'd like to say hello everyone
And i hope i posted this in the right section... anyways here's my problem
So far i got:
Richtextbox1 in which user inputs colored words
i used the code : Richtextbox1.selectioncolor (i belive)

So what i want to do this the moment when the user presses Button1, the colored text that he inputed in richtextbox would be copied to Textbox1, but so that each time theres a word with new color it would put infront the word number "1,2,..."
Example:

Richtextbox1: ThankYouEveryone

and then he'd press Button1.
And in Textbox1 this would say:

1Thank2You3Everyone

That was primarly question, now i have other one XD

How can i split a text from textbox1.text to textbox2.text when user presses button like so:

Example:
Textbox1.text = Thank You For Helping
Textbox2.text would say = ThankYouForHelping


Thanks in advace
Reply With Quote
  #2  
Old 11-02-2010, 10:16 AM
Gruff's Avatar
GruffSpliting colored text Gruff is offline
Bald Mountain Survivor

Retired Moderator
* Expert *
 
Join Date: Aug 2003
Location: Oregon, USA - deceased
Posts: 6,440
Default

mato900,

In the future limit your questions to one topic per post. It helps when searching the forum for an answer.

To find your colored text you will have to parse the RTF property of the RichTextBox control.
Similar to HTML, RTF is a formatting language.

You can dump your RTF contents to a standard textbox to get an idea of the code.
Code:
Public Class Form1 Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click TextBox1.Text = RichTextBox1.Rtf End Sub End Class

Off hand it looks to me as if the colors are defined at the top and referenced in the body by the tags. /cfn Where n is the Color number. /cf0 appears to end the colored section.

Your second question is not a matter of splitting but of removal. Use the string.Replace() method to replace all space characters with no characters.

myString = myString.Replace(" ","")
__________________
Burn the land and boil the sea
You can't take the sky from me


~T
Reply With Quote
  #3  
Old 11-02-2010, 11:18 AM
mato900 mato900 is offline
Newcomer
 
Join Date: Nov 2010
Location: Slovenia
Posts: 9
Default

First off i want to apologize, its my first time using this forum searching for help =)
And i want to thank you for your quick reply and help
That replace thing work out very well, thanks

Now for the first question about the colored text, i will try to explain it a bit more:
On my form i got 9 picture boxes that're colored with diffrent colors (If you'll need exact colors let me know )
And when the user presses one of that picture boxes the Richtextbox1.SelectionColor gets changed to that color (So he's writting in that color in Richtextbox1 from now, untill he presses other, but you probablly knew that XD )
So when he presses button1, the text gets copied from Richtextbox1 to Textbox1, but so that infront of each text theres a number specifying a color =)

Sorry for my english maybe i didnt explain it exact, uhm.
I want every color to have its own number

Example:
Red = 1
Blue = 2
Green = 3
Black = 4

Richtextbox1.text = ThankYouVeryMuch

And in textbox1.text this would come :
4Thank1You3Very2Much

Hope i explained it better than last time XD

I tried the way you showed but all i get is this big code :S

Thank you for your help =)

Last edited by mato900; 11-02-2010 at 11:26 AM.
Reply With Quote
  #4  
Old 11-02-2010, 12:10 PM
Gruff's Avatar
GruffSpliting colored text Gruff is offline
Bald Mountain Survivor

Retired Moderator
* Expert *
 
Join Date: Aug 2003
Location: Oregon, USA - deceased
Posts: 6,440
Default

BTW welcome to the forum. Don't forget to read the forum Posting Guidelines.

Okay. It sounds like you know the color you are applying to the richtextbox up front.
Quote:
user presses one of that picture boxes the Richtextbox1.SelectionColor gets changed to that color
If you know the TextColor (And Color Number) and the word that is going to be entered into the RichTextBox then I guess I do not see the problem.

Are you asking how to append the color number with the text to the textbox?

Code:
' Where ColorNumber and TextValue are variables TextBox1.text &= ColorNumber & TextValue.
__________________
Burn the land and boil the sea
You can't take the sky from me


~T
Reply With Quote
  #5  
Old 11-02-2010, 12:25 PM
mato900 mato900 is offline
Newcomer
 
Join Date: Nov 2010
Location: Slovenia
Posts: 9
Default

Hi, and thanks

This is the code for Picutre Boxes:

Code:
Public Class Form1

    Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
        RichTextBox1.SelectionColor = Color.Red
    End Sub

    Private Sub PictureBox2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox2.Click
        RichTextBox1.SelectionColor = Color.Green
    End Sub

    Private Sub PictureBox3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox3.Click
        RichTextBox1.SelectionColor = Color.Yellow
    End Sub

    Private Sub PictureBox4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox4.Click
        RichTextBox1.SelectionColor = Color.Blue
    End Sub

    Private Sub PictureBox5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox5.Click
        RichTextBox1.SelectionColor = Color.Cyan
    End Sub

    Private Sub PictureBox6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox6.Click
        RichTextBox1.SelectionColor = Color.Fuchsia
    End Sub

    Private Sub PictureBox7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox7.Click
        RichTextBox1.SelectionColor = Color.White
    End Sub

    Private Sub PictureBox8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox8.Click
        RichTextBox1.SelectionColor = Color.RoyalBlue
    End Sub

    Private Sub PictureBox9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox9.Click
        RichTextBox1.SelectionColor = Color.Silver
    End Sub

    Private Sub PictureBox10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox10.Click
        RichTextBox1.SelectionColor = Color.Black
    End Sub
Now i am facing another problem here's the code from the button event:

Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        If RichTextBox1.SelectionColor = Color.Red Then
            TextBox1.Text &= "1" & RichTextBox1.Text
        ElseIf RichTextBox1.SelectionColor = Color.Green Then
            TextBox1.Text &= "2" & RichTextBox1.Text
        ElseIf RichTextBox1.SelectionColor = Color.Yellow Then
            TextBox1.Text &= "3" & RichTextBox1.Text
        ElseIf RichTextBox1.SelectionColor = Color.Blue Then
            TextBox1.Text &= "4" & RichTextBox1.Text
        ElseIf RichTextBox1.SelectionColor = Color.Cyan Then
            TextBox1.Text &= "5" & RichTextBox1.Text
        ElseIf RichTextBox1.SelectionColor = Color.Fuchsia Then
            TextBox1.Text &= "6" & RichTextBox1.Text
        ElseIf RichTextBox1.SelectionColor = Color.White Then
            TextBox1.Text &= "7" & RichTextBox1.Text
        ElseIf RichTextBox1.SelectionColor = Color.RoyalBlue Then
            TextBox1.Text &= "8" & RichTextBox1.Text
        ElseIf RichTextBox1.SelectionColor = Color.Silver Then
            TextBox1.Text &= "9" & RichTextBox1.Text
        ElseIf RichTextBox1.SelectionColor = Color.Black Then
            TextBox1.Text &= "0" & RichTextBox1.Text
        End If
End Sub
The thing is that in the textbox1 only one number shows, the number from the last picture box that was clicked :S
Thanks again XD



I am sorry for my bad english :S
And thanks for helping me XD

Last edited by mato900; 11-02-2010 at 12:41 PM.
Reply With Quote
  #6  
Old 11-02-2010, 01:21 PM
mato900 mato900 is offline
Newcomer
 
Join Date: Nov 2010
Location: Slovenia
Posts: 9
Default

I Think theres a problem at:
TextBox1.Text &= "1" & RichTextBox1.Text
Dont know what to type instead, quite confusing :P
Reply With Quote
  #7  
Old 11-02-2010, 01:40 PM
Gruff's Avatar
GruffSpliting colored text Gruff is offline
Bald Mountain Survivor

Retired Moderator
* Expert *
 
Join Date: Aug 2003
Location: Oregon, USA - deceased
Posts: 6,440
Default

mato,

One of the more powerful features of programming is that you do not need to type in things repeatedly. The following snippet should do what you want to do without all the fuss.
BTW I used labels instead of pictureboxes as pictureboxes use a lot of system resources where labels do not.

Code:
Public Class Form1 'Assumes the text to be colorized is selected in the Richtextbox. 'Create an event handler that receives all 10 label clicks. Labels are named A1, A2, A3, Etc... Private Sub Any_Label_A_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles A1.Click, A2.Click, A3.Click, A4.Click, A5.Click, A6.Click, A7.Click, A8.Click, A9.Click, A10.Click Dim SentLabel As Label = DirectCast(sender, Label) 'Get Label Clicked Dim ColorNumber As String = SentLabel.Text 'Get the color number RichTextBox1.SelectionColor = SentLabel.BackColor 'Set the RTF color to the label color you clicked TextBox1.Text &= ColorNumber & RichTextBox1.SelectedText 'Record ColorNumber and selected text End Sub End Class
Attached Images
File Type: png Colorize Text.png (19.7 KB, 8 views)
__________________
Burn the land and boil the sea
You can't take the sky from me


~T

Last edited by Gruff; 11-02-2010 at 01:50 PM.
Reply With Quote
  #8  
Old 11-02-2010, 02:29 PM
mato900 mato900 is offline
Newcomer
 
Join Date: Nov 2010
Location: Slovenia
Posts: 9
Default

Thank you Gruff,
Not only you solved my problem but you taught me something more
I appreciate that a lot.

Cheers
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Spliting colored text
Spliting colored text
Spliting colored text Spliting colored text
Spliting colored text
Spliting colored text
Spliting colored text Spliting colored text Spliting colored text Spliting colored text Spliting colored text Spliting colored text Spliting colored text
Spliting colored text
Spliting colored text
 
Spliting colored text
Spliting colored text
 
-->