Ontani Posted October 14, 2004 Posted October 14, 2004 i got a richtextbox were text is entered truw TCP/IP (like messenger) when the text looks like this: Ontani says: Hi Friend says: Hey, How your doing Ontani says: good, and you...? it has to color my name (ontani) like in the example how can i do this? this is the send code: toSend= userName & " says:" & vbCrLf & txtToSend.Text txtRecieved.Text &= toSend & vbCrLf wsTCP.SendData(toSend) txtToSend.Text = "" someone an idea? Greetz Quote www.purevision.be :: www.devpoint.be
Leaders Iceplug Posted October 14, 2004 Leaders Posted October 14, 2004 You will have to use the SelectionStart and the SelectionLength of the RichTextBox to select your name, and then use SelectedColor to change the color of your name. You will probably have to use .IndexOf to find your name for SelectionStart, or maybe .Find to find it. :) Quote Iceplug, USN One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(
Ontani Posted October 14, 2004 Author Posted October 14, 2004 yeah i tried txtRecieved.SelectionStart = txtRecieved.Find("Ontani") txtRecieved.SelectionLength = 7 txtRecieved.SelectionColor = Color.MarineBlye that works for the first time then it doesn't anymore. i don't know how to make a loop to select every "Ontani" in the textbox Greetz Quote www.purevision.be :: www.devpoint.be
Rick_Fla Posted October 14, 2004 Posted October 14, 2004 i got a richtextbox were text is entered truw TCP/IP (like messenger) when the text looks like this: Ontani says: Hi Friend says: Hey, How your doing Ontani says: good, and you...? it has to color my name (ontani) like in the example how can i do this? this is the send code: toSend= userName & " says:" & vbCrLf & txtToSend.Text txtRecieved.Text &= toSend & vbCrLf wsTCP.SendData(toSend) txtToSend.Text = "" someone an idea? Greetz Check this link, looks close to what you are looking for. http://www.codeproject.com/cs/miscctrl/csexrichtextbox.asp Quote "Nobody knows what I do until I stop doing it."
Ontani Posted October 14, 2004 Author Posted October 14, 2004 that link is in C# :s i'm trying for vb.net Quote www.purevision.be :: www.devpoint.be
Rick_Fla Posted October 14, 2004 Posted October 14, 2004 (edited) Sorry, I am still trying to wake up. I am not a C# expert, but I know there are a few sites which might be able to turn this into VB code. There is not a lot there, let me see what I can find. *correction* Ok, there is a lot more int he source code that you would have to download, and not being a C# person, I am not sure I can convert it anytime soon, sorry about that. Edited October 14, 2004 by Rick_Fla Quote "Nobody knows what I do until I stop doing it."
Ontani Posted October 14, 2004 Author Posted October 14, 2004 so you have no clue at all to do this in vb.net? Quote www.purevision.be :: www.devpoint.be
Rick_Fla Posted October 14, 2004 Posted October 14, 2004 Play around with this Me.rtbTest.SelectionColor = Color.Blue Me.rtbTest.SelectedText = "Ontani " Me.rtbTest.SelectionColor = Color.Black Me.rtbTest.SelectedText = "Says: Cool" Quote "Nobody knows what I do until I stop doing it."
Ontani Posted October 14, 2004 Author Posted October 14, 2004 can't get it to work, don't see anything logical in that. :confused: is it possible to do something like this set color blue add "Ontani" set color black add " says: " something like that? Greetz Quote www.purevision.be :: www.devpoint.be
Rick_Fla Posted October 14, 2004 Posted October 14, 2004 I think best if one of the experts answer this more. Not afraid to say this is outside of my knowledge. Quote "Nobody knows what I do until I stop doing it."
Leaders Iceplug Posted October 15, 2004 Leaders Posted October 15, 2004 Try using IndexOf instead of Find. :) Really all you do is assign TB.Text.IndexOf("Ontani") to the selectionstart instead. That finds the first Ontani in the textbox. Everything else that you have after it is fine. Now, to loop it, you have to use: X = TB.Text.IndexOf("Ontani", TB.SelectionStart + 1) 'This will find the next Ontani from wherever the selection is. in a loop of some sort. Preferably a Do Loop that loops until X = -1. And of course, this check will come at the end. Now, if you want some pseudocode... this is how you might set up the "IndexOf Loop". X = indexof ontani Do Until X = -1 selectionlength selcolor X = indexof (next) ontani Loop :) Quote Iceplug, USN One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(
Ontani Posted October 16, 2004 Author Posted October 16, 2004 isn't there a way to add a color to the text when its added to the richtextbox cause this is gonna take a huge time when the textbox is full of text Greetz Quote www.purevision.be :: www.devpoint.be
Leaders Iceplug Posted October 18, 2004 Leaders Posted October 18, 2004 Sure, but the cursor will have to stay at the end of the textbox. If you move the cursor to the end of the textbox, you can simply do: RTB.SelectedText = "Ontani" RTB.SelectedColor = Color.Red (or something like that) :) Quote Iceplug, USN One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(
Ontani Posted October 18, 2004 Author Posted October 18, 2004 Sure, but the cursor will have to stay at the end of the textbox. If you move the cursor to the end of the textbox, you can simply do: RTB.SelectedText = "Ontani" RTB.SelectedColor = Color.Red (or something like that) :) it was the other way around ;) RTB.SelectedColor = Color.Red RTB.SelectedText = "Ontani" Thanx Quote www.purevision.be :: www.devpoint.be
Ontani Posted October 18, 2004 Author Posted October 18, 2004 Damned can't get it done! I want to add the speaker to the richtextbox without any Style so just plain text. and the text to be added next can have a font/size/color. something like : Ontani says: Hey i used the FontDialog for choosing the font. (what works) but the adding @ the insertion of the text to the richtextbox something goes wrong. Private Const WM_VSCROLL As Int32 = &H115 Private Const SB_BOTTOM As Int32 = 7 Private Declare Auto Function SendMessage Lib "user32.dll" (ByVal hwnd As IntPtr, ByVal wMsg As Int32, ByVal wParam As Int32, _ ByVal lParam As Int32) As Int32 Dim User as String = "Ontani" ... RTB.Text &= User & " says: " & vbCrLf SendMessage(RTB.Handle, WM_VSCROLL, SB_BOTTOM, 0) RTB.SelectionFont = FontDialog1.Font RTB.SelectedText = TextBox1.Text & vbCrLf the sendmessage takes sure the carret (cursor) goes to the end of the richtextbox. (well it should) the text in the textbox is added in front of everything. Can someone help me with this problem Greetz. Quote www.purevision.be :: www.devpoint.be
Leaders snarfblam Posted October 18, 2004 Leaders Posted October 18, 2004 I'm just throwing an idea out there... You can retrieve and set the raw rich text from a rich text box. You could construct your own raw rich text if you learn a little about rtf format and assign it to the RichTextBox's Rtf property. For example, to insert your name into the RichTextBox you could maintain a raw rtf string that includes "{\colortbl ;\red0\green0\blue255;}" somewhere in the rtf (not sure exactly where, but this adds blue to the color table), and then insert this: "\cf1\b" & Name & ": \cf0\b0" & Message into the rtf in order to insert the message with the name in blue bold and message in black regular. Assign this to the richtextbox's Rtf property and... voila! Formatted rich text. Just insert your new messages in the rtf string like this, and assigning it to the richtextbox's rtf property. Quote [sIGPIC]e[/sIGPIC]
Leaders Iceplug Posted October 19, 2004 Leaders Posted October 19, 2004 So, RTB.SelectionStart = RTB.TextLength doesn't move the cursor to the end? Quote Iceplug, USN One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(
Ontani Posted October 19, 2004 Author Posted October 19, 2004 For some reason it doesn't with Richtextboxes (well it doesn't in my case) i know it works for regular textboxes. the sendmessage thingy works perfectly Quote www.purevision.be :: www.devpoint.be
mooman_fl Posted November 17, 2004 Posted November 17, 2004 I am trying to do something similar. The only difference that I can see is that I need the whole line colored. For some reason the first one gets set correctly... the remaining lines seem to be set to the right color and THEN get changed to the same color as the first line... the last line added in my example code below seems to be the correct color. I am guessing that it has something to do with the selection part but I have struggled with this for hours and can't seem to get it. Any help is appreciated. string[] strTest = new string[] {"Line one", "Line two", "Line three", "Line four" , "Line five"}; Color[] clrTest = new Color[] {Color.Red, Color.Blue, Color.Yellow, Color.Green, Color.Purple}; int i = 0; foreach (string s in strTest) { rtb1.Text += s+Environment.NewLine; rtb1.SelectionStart = rtb1.Text.Length - (s.Length+1); rtb1.SelectionLength = s.Length; rtb1.SelectionColor = clrTest[i]; rtb1.SelectionStart = rtb1.Text.Length; i++; } Quote "Programmers are tools for converting caffeine into code." Madcow Inventions -- Software for the Sanity Challenged.
mooman_fl Posted November 17, 2004 Posted November 17, 2004 Ok... after posting the above example it finally sunk in what Iceplug was saying... and the correcton Otani made. I got it to work with this code: string[] strTest = new string[]{"Line one", "Line two", "Line three", "Line four", "Line five"}; Color[] clrTest = new Color[]{Color.Red, Color.Blue, Color.Yellow, Color.Green, Color.Purple}; int i = 0; foreach (string s in strTest) { rtb1.SelectionColor = clrTest(i); rtb1.SelectedText = s + Environment.NewLine; i++; }[size=2][color=#006400][/color][/size] Or for the sake of completeness here is the VB example: Dim strTest As String() = New String() {"Line one", "Line two", "Line three", "Line four", "Line five"} Dim clrTest As Color() = New Color() {Color.Red, Color.Blue, Color.Yellow, Color.Green, Color.Purple} Dim i As Integer = 0 For Each s As String In strTest rtb1.SelectionColor = clrTest(i) rtb1.SelectedText = s + Environment.NewLine i += 1 Next[size=2][color=#0000ff][/color][/size] Quote "Programmers are tools for converting caffeine into code." Madcow Inventions -- Software for the Sanity Challenged.
Kershaad Posted January 31, 2005 Posted January 31, 2005 ***? Ok... after posting the above example it finally sunk in what Iceplug was saying... and the correcton Otani made. I got it to work with this code: Or for the sake of completeness here is the VB example: Dim strTest As String() = New String() {"Line one", "Line two", "Line three", "Line four", "Line five"} Dim clrTest As Color() = New Color() {Color.Red, Color.Blue, Color.Yellow, Color.Green, Color.Purple} Dim i As Integer = 0 For Each s As String In strTest rtb1.SelectionColor = clrTest(i) rtb1.SelectedText = s + Environment.NewLine i += 1 Next[size=2][color=#0000ff][/color][/size] I was after an answer for this program, and I tried ur code, and it kinda worked. it made the specified text the correct color - but when more text was added to the text bot - it reset the colored text to its original colour. i have NFI why. any help would be appreciated Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.