Valhalla Legends Archive

Programming => General Programming => .NET Platform => Topic started by: Mangix on September 17, 2005, 12:07 PM

Title: [C#]AppendRTB
Post by: Mangix on September 17, 2005, 12:07 PM
im making a void to Append Text to a Rich Text Box but im having one problem. i cant set the color.

void AppendRTB(System.Windows.Forms.RichTextBox rtb, string text, System.Drawing.Color color)
{
rtb.SelectionStart = rtb.Text.Length;
rtb.SelectionLength = 0;
rtb.SelectedText = text;
rtb.SelectionColor = color;
rtb.SelectionStart = rtb.Text.Length;
}


i've tried using just the color name but it says it doesnt exist. i also tried using Color.colorname which doesnt error but it doesnt change the color. it's still black.

also, how do i make a newline in .NET?
Title: Re: [C#]AppendRTB
Post by: MyndFyre on September 17, 2005, 04:13 PM
Quote from: Mangix on September 17, 2005, 12:07 PM
im making a void to Append Text to a Rich Text Box but im having one problem. i cant set the color.

void AppendRTB(System.Windows.Forms.RichTextBox rtb, string text, System.Drawing.Color color)
{
rtb.SelectionStart = rtb.Text.Length;
rtb.SelectionLength = 0;
rtb.SelectedText = text;
rtb.SelectionColor = color;
rtb.SelectionStart = rtb.Text.Length;
}


i've tried using just the color name but it says it doesnt exist. i also tried using Color.colorname which doesnt error but it doesnt change the color. it's still black.

also, how do i make a newline in .NET?
Try selecting the text (by specifying the SelectionLength as text.Length after adding the text?  Otherwise IDK.

Environment.NewLine.
Title: Re: [C#]AppendRTB
Post by: Mangix on September 17, 2005, 06:11 PM
i fixed it somehow. dunno why but the same code now works. weird.

edit:do you know how i can do a perfect Now function? right now im using this code to produce a Time. string tmeNow = DateTime.Now.Hour.ToString() + ":" + DateTime.Now.Minute.ToString() + ":" + DateTime.Now.Second.ToString(); now i dont like this code. sometimes it produces a time value like this.

Quote12:3:7
the real time is 12:30:07 but that's what i want it to show. the zeroes behind it.
Title: Re: [C#]AppendRTB
Post by: Insolence on September 18, 2005, 01:51 AM
That's very easy, if < 10 +=  " ", then tack on the minute(s)/second(s) :)
Title: Re: [C#]AppendRTB
Post by: MyndFyre on September 18, 2005, 04:01 AM
I'm going to throw out a REALLY crazy suggestion...

If you have MSDN documentation, you can see the codes for the DateTime format strings here: ms-help://MS.VSCC.2003/MS.MSDNQTR.2004OCT.1033/cpguide/html/cpconcustomdatetimeformatstrings.html (copy-paste that into MSDN document reader)

(This links to October 2004 MSDN, which is the most recent that I had).


How about:

DateTime.Now.ToString("HH:mm:ss")


I've noticed people like to do things the hard way when easy ways to do stuff exist automatically.  :P
Title: Re: [C#]AppendRTB
Post by: Mangix on September 18, 2005, 10:31 PM
dont you mean the MSDN Library? i have the Beta 2 but i cant access it. reason is because it's supposed to be used with VS 2005 products but i uninstalled all of em(cept for SQL Server(i cant get rid of it -_-)). right now the whole library is in weird .hks files(i think). it's also zipped in an archive.

edit:as for the Now, thanks a lot :) oh and just so you know, i dont think i cant use any version of the MSDN Libarary cause i use SharpDevelop :-\