473,388 Members | 1,342 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,388 software developers and data experts.

how to persist color settings in my app?

I want to be able to save the user color settings in my app and restore them
when the app is re-opened. I currently have a config file with different
settings such as:

[App Settings]
UID=jsmith
IP=127.0.0.1
Port=23

I want to be able to save the color settings in the same way, but the I
can't convert from System.Drawing.Color to String. How can I accomplish
this?

Thanks.
Jan 6 '06 #1
5 1137
Terry,

The in my opinion most simple way is the "Color.ToArgb" and the
Color.FromArgb" methods.

http://msdn2.microsoft.com/en-us/lib...or.toargb.aspx

I hope this helps,

Cor
Jan 6 '06 #2
Thanks! That worked great. Now I can't get my font to persist. I tried
writing out the font as Font.ToHfont and then reading it back in as
Font.FromHfont, but I get an error saying "This only works with TrueType
Fonts. This isn't a TrueType Font." The font actually is a TrueType font,
at least it has the .ttf suffix and has the TT logo next to its name in the
listing.

How can I persist my font?

Thanks.

"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:eT**************@TK2MSFTNGP12.phx.gbl...
Terry,

The in my opinion most simple way is the "Color.ToArgb" and the
Color.FromArgb" methods.

http://msdn2.microsoft.com/en-us/lib...or.toargb.aspx

I hope this helps,

Cor

Jan 7 '06 #3
Terry,

You are even able to serialize a font.

\\\first showed to me by Tom Shelton
Private Function SerializeFontObject(ByVal fnt As Font) As String
Dim bf As New BinaryFormatter
Dim mem As New MemoryStream
Try
bf.Serialize(mem, fnt)
Return Convert.ToBase64String(mem.ToArray())
Catch
Return String.Empty
Finally
mem.Close()
End Try
End Function
Private Function DeserializeFontObject(ByVal fnt As String) As Font
Dim bf As New BinaryFormatter
Dim mem As New MemoryStream(Convert.FromBase64String(fnt))
Try
Return DirectCast(bf.Deserialize(mem), Font)
Finally
If Not mem Is Nothing Then
mem.Close()
End If
End Try
End Function

I hope this helps,

Cor
Jan 7 '06 #4
"Terry Olsen" <to******@hotmail.com> schrieb:
Now I can't get my font to persist. I tried writing out the font as
Font.ToHfont and then reading it back in as Font.FromHfont, but I get an
error saying "This only works with TrueType Fonts. This isn't a TrueType
Font."


In addition to the other replies: The font handle you obtain using
'ToHfont' points to the font object the method is called on. This handle
won't exist any more if you restart the application.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Jan 7 '06 #5
Yup, that did it. Thanks!

"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:Oh**************@TK2MSFTNGP11.phx.gbl...
Terry,

You are even able to serialize a font.

\\\first showed to me by Tom Shelton
Private Function SerializeFontObject(ByVal fnt As Font) As String
Dim bf As New BinaryFormatter
Dim mem As New MemoryStream
Try
bf.Serialize(mem, fnt)
Return Convert.ToBase64String(mem.ToArray())
Catch
Return String.Empty
Finally
mem.Close()
End Try
End Function
Private Function DeserializeFontObject(ByVal fnt As String) As Font
Dim bf As New BinaryFormatter
Dim mem As New MemoryStream(Convert.FromBase64String(fnt))
Try
Return DirectCast(bf.Deserialize(mem), Font)
Finally
If Not mem Is Nothing Then
mem.Close()
End If
End Try
End Function

I hope this helps,

Cor

Jan 7 '06 #6

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

Similar topics

9
by: Pack Fan | last post by:
I've noticed that session variables will persist on Mac IE even after all browser windows have been closed. One must quit the program to clear the session variables. This presents a security risk...
4
by: Alberto | last post by:
Could you tell me what it's for the "Persist Security Info ..." value in a connection string. Thank you.
2
by: BH | last post by:
I developed a small web app using the FormsAuthentication class to set a cookie (FormsAuthentication.SetAuthCookie(value, isPersist)). The cookie persists fine on my local PC when "isPersist" is...
1
by: Paul Perot | last post by:
Hi All: I have a DataTable that I have defined Globally. I populate this datatable dynamically with file/folder information that I read directly from the server. I use this datatable...
3
by: FrzzMan[ | last post by:
Yesterday, all my ASP.NET running fine, at least this error didn't raise. Today, I turned on the PC at the morning and receive this error: Compiler Error Message: CS0016: Could not write to...
3
by: John Dalberg | last post by:
I am setting the HttpContext.Current.User in the Application_AuthenticateRequest event in global.asax.cs. When I use the IsInRole function in a web page, it works fine. So far so good. (Note that...
3
by: Matthew | last post by:
I'm a bit new to VB, so please be understanding. I would like to have several variables that are remembered even when the user closes the program and re-opens it. The following seems to describe...
5
by: Steve | last post by:
I was dissapointed to see that the new Settings system in 2005 doesn't appear to persist the data between application sessions. I understand that it is used for application initialization, but...
0
NeoPa
by: NeoPa | last post by:
Introduction: We get fairly frequent questions on here about why settings (including both values AND formatting) of unbound controls on a form, are not stored for reference later, but instead, each...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.