|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Changing a richtextbox's colour!compiles fine. I am saving the fore and back colour of a RTB to the registry like this: Srx.SetValue("ForeColour", Console.ForeColor.ToArgb.ToString) Srx.SetValue("BackColour", Console.BackColor.ToArgb.ToString) Then, I try to read the colours back in at runtime and change the colour of the RTB like this: Dim ForeCol As New System.Drawing.Color Dim BackCol As New System.Drawing.Color ForeCol.FromName(Lrx.GetValue("ForeColour")) Console.ForeColor = ForeCol BackCol.FromName(Lrx.GetValue("BackColour")) Console.BackColor = BackCol The colours get saved to the registry OK but when the form loads it is not changing the colours! As far as I can tell the values are read back from the registry OK but just ignored. Any ideas?? Thanks. Hi Hugh,
> Srx.SetValue("ForeColour", Console.ForeColor.ToArgb.ToString) It looks like your saving to an Argb value here...> Srx.SetValue("BackColour", Console.BackColor.ToArgb.ToString) > Dim ForeCol As New System.Drawing.Color But loading from a Name here. Use FromArgb instead.> Dim BackCol As New System.Drawing.Color > > ForeCol.FromName(Lrx.GetValue("ForeColour")) > Console.ForeColor = ForeCol > BackCol.FromName(Lrx.GetValue("BackColour")) > Console.BackColor = BackCol I hope this helps. Nick. > Thanks, I never saw that. I have changed it but it makes no> But loading from a Name here. Use FromArgb instead. > > I hope this helps. > > Nick. difference. The colours loaded are still black text on white background. Hugh Hi Hugh,
I see no reason why using ToArgb and FromArgb shouldn't work. But one thing you can try is the ColorConverter class, ColorTranslater.ToWin32 and FromWin32 methods to obtain a color value from a 32 bit integer. Make sure you are loading them from the registry correctly first by popping them up on a message box or displaying to the console before passing to the rich text box. Nick. Show quoteHide quote "Hugh Janus" <my-junk-acco***@hotmail.com> wrote in message news:1139484987.023608.178050@g14g2000cwa.googlegroups.com... > > >> But loading from a Name here. Use FromArgb instead. >> >> I hope this helps. >> >> Nick. > > Thanks, I never saw that. I have changed it but it makes no > difference. The colours loaded are still black text on white > background. > > Hugh > Hang on a second,
Try changing the name of your rich textbox to something other than Console... Show quoteHide quote "Nick Pateman" <a@a.com> wrote in message news:%23tMhzeYLGHA.1028@TK2MSFTNGP11.phx.gbl... > Hi Hugh, > > I see no reason why using ToArgb and FromArgb shouldn't work. But one > thing you can try is the ColorConverter class, > > ColorTranslater.ToWin32 and FromWin32 methods to obtain a color value > from a 32 bit integer. > > Make sure you are loading them from the registry correctly first by > popping them up on a message box or displaying to the console before > passing to the rich text box. > > Nick. > > "Hugh Janus" <my-junk-acco***@hotmail.com> wrote in message > news:1139484987.023608.178050@g14g2000cwa.googlegroups.com... >> > >>> But loading from a Name here. Use FromArgb instead. >>> >>> I hope this helps. >>> >>> Nick. >> >> Thanks, I never saw that. I have changed it but it makes no >> difference. The colours loaded are still black text on white >> background. >> >> Hugh >> > > > > I see no reason why using ToArgb and FromArgb shouldn't work. But one OK, this is my new code after lots of playing around.> > thing you can try is the ColorConverter class, > > > > ColorTranslater.ToWin32 and FromWin32 methods to obtain a color value > > from a 32 bit integer. > > > > Make sure you are loading them from the registry correctly first by > > popping them up on a message box or displaying to the console before > > passing to the rich text box. > > > > Nick. > > Dim SColour As Color SColour = Color.FromArgb(txtConsole.ForeColor.ToArgb) Dim RColour As String = SColour.ToString Srx.SetValue("ForeColour", RColour) That writes the value "Color [A=255, R=255, G=255, B=128]" to the registry for a sort of off-yellow colour. .... Then, I read it back in with this: Dim LColour As Color = Color.FromName(Lrx.GetValue("ForeColour")) txtConsole.ForeColor = LColour The code MsgBox(LColour.ToString & Chr(13) & Lrx.GetValue("ForeColour")) returns: "Color [Color [A=255, R=255, G=255, B=128]] Color [A=255, R=255, G=255, B=128]" I have no idea where the extra word 'color' came from nor the end ] but the colour is not changed on my RTB. Has nobody ever done anything similar before? I get no compile errors not errors when it is supposed to change the colour. Hugh Also,
Console.WriteLineLColour.ToString & Chr(13) & Lrx.GetValue("ForeColour") & Chr(13) & txtConsole.ForeColor.ToString) returns this: Color [Color [A=255, R=255, G=128, B=0]] Color [A=255, R=255, G=128, B=0] Color [Color [A=255, R=255, G=128, B=0]] As you can see, it has the same colour as the colour object but on the form it is displayed as black. SOLVED.
Well, after sheer playing around and guessing (it tends to work when experience doesn't!!!) I have solved it although I have no idea why this works and it never before did. So here is the code: Private ForeC As Drawing.Color Private BackC As Drawing.Color ---------------------- 'This is part of the sub that shows the colour picker and then sets the colours. Dim ColChooser As New ColorDialog ColChooser.ShowDialog() txtConsole.ForeColor = ColChooser.Color ForeC = ColChooser.Color ColChooser.ShowDialog() txtConsole.BackColor = ColChooser.Color BackC = ColChooser.Color --------------------------------- 'This is part of the sub that writes to the registry. Srx.SetValue("ForeColour", ForeC.ToArgb.ToString) ' RColour) Srx.SetValue("BackColour", BackC.ToArgb.ToString) --------------------------------- 'This is the part which loads from registry on startup. ForeC = Drawing.Color.FromArgb(Lrx.GetValue("ForeColour").ToString) txtConsole.ForeColor = ForeC BackC = Drawing.Color.FromArgb(Lrx.GetValue("BackColour").ToString) txtConsole.BackColor = BackC
Show quote
Hide quote
"Hugh Janus" <my-junk-acco***@hotmail.com> schrieb: \\\> I am saving the fore and back colour of a RTB to the registry like > this: > > Srx.SetValue("ForeColour", Console.ForeColor.ToArgb.ToString) > Srx.SetValue("BackColour", Console.BackColor.ToArgb.ToString) > > Then, I try to read the colours back in at runtime and change the > colour of the RTB like this: > > Dim ForeCol As New System.Drawing.Color > Dim BackCol As New System.Drawing.Color > > ForeCol.FromName(Lrx.GetValue("ForeColour")) Me.RichTextBox1.BackColor = _ Color.FromName(CInt(Lrx.GetValue("ForeColor"))) /// -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> > \\\ Thanks, but still no joy. It is just ignored. Here is my modified> Me.RichTextBox1.BackColor = _ > Color.FromName(CInt(Lrx.GetValue("ForeColor"))) > /// > code. Srx.SetValue("ForeColour", Console.ForeColor.Name) Srx.SetValue("BackColour", Console.BackColor.Name) Console.ForeColor = System.Drawing.Color.FromName(CInt(Lrx.GetValue("ForeColor"))) Console.BackColor = System.Drawing.Color.FromName(CInt(Lrx.GetValue("BackColor"))) The values in the registry are: ForeColour - ffff8080 BackColour - ff408080 Hugh "Hugh Janus" <my-junk-acco***@hotmail.com> schrieb: Sorry for the typo, I actually wanted to type 'Color.FromArgb'! If you are >> Me.RichTextBox1.BackColor = _ >> Color.FromName(CInt(Lrx.GetValue("ForeColor"))) >> /// >> > > Thanks, but still no joy. It is just ignored. Here is my modified > code. storing color names in the registry, use 'Color.FromName'. If you are storing color values, use 'Color.FromArgb'. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> > Sorry for the typo, I actually wanted to type 'Color.FromArgb'! If you are Hmmm, now I am even more confused than ever. Is there not an easier> storing color names in the registry, use 'Color.FromName'. If you are > storing color values, use 'Color.FromArgb'. > way? I simply want to store the colour as a string in the registry (be it in the format ffff8080 or whatever) and then on load, read the value and set the colour of the RTB!! Lost! Please help! Hugh |
|||||||||||||||||||||||