473,320 Members | 1,920 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Changing a richtextbox's colour!

OK, this is driving me crazy! As far as I can tell it should work. It
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.

Feb 9 '06 #1
11 2425
Hi Hugh,
Srx.SetValue("ForeColour", Console.ForeColor.ToArgb.ToString)
Srx.SetValue("BackColour", Console.BackColor.ToArgb.ToString)
It looks like your saving to an Argb value here...
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


But loading from a Name here. Use FromArgb instead.

I hope this helps.

Nick.
Feb 9 '06 #2
>
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

Feb 9 '06 #3
"Hugh Janus" <my*************@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/>
Feb 9 '06 #4
> \\\
Me.RichTextBox1.BackColor = _
Color.FromName(CInt(Lrx.GetValue("ForeColor")))
///


Thanks, but still no joy. It is just ignored. Here is my modified
code.

Srx.SetValue("ForeColour", Console.ForeColor.Name)
Srx.SetValue("BackColour", Console.BackColor.Name)

Console.ForeColor =
System.Drawing.Color.FromName(CInt(Lrx.GetValue("F oreColor")))
Console.BackColor =
System.Drawing.Color.FromName(CInt(Lrx.GetValue("B ackColor")))

The values in the registry are:
ForeColour - ffff8080
BackColour - ff408080
Hugh

Feb 9 '06 #5
"Hugh Janus" <my*************@hotmail.com> schrieb:
Me.RichTextBox1.BackColor = _
Color.FromName(CInt(Lrx.GetValue("ForeColor")))
///


Thanks, but still no joy. It is just ignored. Here is my modified
code.


Sorry for the typo, I actually wanted to type 'Color.FromArgb'! If you are
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/>

Feb 9 '06 #6
> Sorry for the typo, I actually wanted to type 'Color.FromArgb'! If you are
storing color names in the registry, use 'Color.FromName'. If you are
storing color values, use 'Color.FromArgb'.


Hmmm, now I am even more confused than ever. Is there not an easier
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

Feb 9 '06 #7
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*************@hotmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.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

Feb 9 '06 #8
Hang on a second,

Try changing the name of your rich textbox to something other than
Console...

"Nick Pateman" <a@a.com> wrote in message
news:%2****************@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*************@hotmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.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


Feb 9 '06 #9
> > 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.


OK, this is my new code after lots of playing around.

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

Feb 9 '06 #10
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.

Feb 9 '06 #11
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

Feb 9 '06 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Bruce Wolfe | last post by:
I have a RichTextBox populated with characters that include a character of a script other than the default. When I try to paste a Unicode character into the RichTextBox downstream of that character...
0
by: Jon Cooper | last post by:
Hi, I'm developing an app that uses a RichTextBox, and populates it with colour formatted text at Form Load. However, I randomly receive this error, which I believe is related to this data...
7
by: Sakharam Phapale | last post by:
Hi All, How to preserve the old font properties while changing new one? I posted same question 2 months back, but I had very small time then. eg. "Shopping for" is a text in RichTextBox and...
9
by: al jones | last post by:
Sorry, it's getting late and I'm tired. I'm trying to fill a richtect box with text derived from the array I was asking about earlier (thank you). I'm not sure what I'm seeing - since most of...
6
by: andreas | last post by:
A selected text has fontstyles like bold and italic and underscore I want to remove one of them without changing the other fontstyles. How to do that? Thanks for any response
0
by: dannyboy1990 | last post by:
I've been developing in vb.net for a few months now, well since i left school and one of my projects for my current company is to create a sql tool which is used on a daily basis to update, delete...
3
Mague
by: Mague | last post by:
Hey, I need to open a website source code into a richtextbox. Is this possible? If it is please leave code Also i have an unanswered question. I wanted to know if in the richtextbox i could...
1
by: Paul E Collins | last post by:
I want to colour certain characters as they are typed in a RichTextBox. I started with this simple event handler. private void rtb_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar...
0
by: Gouri.Mahajan7 | last post by:
Hello, I want to change the font of the text in richtextbox without affecting the colour of text. I want some text to be printed in different colours. When I try to change the font of the text...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.