• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1781
  • Last Modified:

URGENT vb.net converting font to string and string to font working in my computer but not in other computers

Hi, i have a application that stores button information about font family, font size, font bold and so on.

I build my application, and install it in other computer.
and start the program, i got Microsoft Sans serif 8,25pt every time
i should get  Microsoft Sans Serif, 12pt, style=Bold

I have also checked a simular problem in C# here in E-X. TypeConverter (Font) not converting correctly, i was trying this, in vb.net (convert it first) with same result.

I have also checked the C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.drawing.dll, they are equal in both computers

Windows XP sr3 on both computers (swedish version)

example of string to font
DIm H as string = "Microsoft Sans Serif, 12pt, style=Bold"
Dim tc As TypeConverter = TypeDescriptor.GetConverter(GetType(Font))
Dim Fo As Font = DirectCast(tc.ConvertFromString(H), Font)
I got "Microsoft Sans Serif, 8,25pt"

I have also tryied to take away the pt in the string.
eg. "Microsoft Sans Serif, 12, style=Bold" that gives the same result 8.25pt

I have also tryied to run my .exe file bin\release on my computer it's working good

The problem are when application  are run on  other computer than my development computer
the font converter gives wrong result.

I hope you have any idea about this problem

Brg /Richard
0
richardd65
Asked:
richardd65
  • 3
  • 3
1 Solution
 
magicdlfCommented:
Change the code a little:
Dim H As String = "Microsoft Sans Serif, 12pt, style=Bold"
Dim tc As TypeConverter = TypeDescriptor.GetConverter(GetType(Font))
Dim Fo As Font = DirectCast(tc.ConvertFromString(H), Font)
Dim str As [String] = tc.ConvertToString(Fo)
// Print/Messagebox both the str and H here
On your client, run this again, and see what you will get
0
 
magicdlfCommented:
Hello, I think this issue is related to your culture. Please try this:
Dim H As String = "Microsoft Sans Serif; 12,25pt"
Dim tc As TypeConverter = TypeDescriptor.GetConverter(GetType(Font))
Dim Fo As Font = DirectCast(tc.ConvertFromString(Nothing, System.Globalization.CultureInfo.CreateSpecificCulture("sv-SE"), H), Font)
Dim str As [String] = tc.ConvertToString(Nothing, System.Globalization.CultureInfo.CreateSpecificCulture("sv-SE"), Fo)
0
 
richardd65Author Commented:
Hi it's working fine, but there was 2 problems
1. change "," to ";"
2. use culture Globalization

Solution:
Dim H as string = "Microsoft Sans Serif; 12,25pt; style=bold"
Dim cur As CultureInfo = CultureInfo.CurrentUICulture  ' get current UI Culture
Dim Fo As Font = DirectCast(tc.ConvertFromString(Nothing, System.Globalization.CultureInfo.CreateSpecificCulture(cc), H), Font)

thanx for the help
0
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
magicdlfCommented:
Glad to know : )
0
 
richardd65Author Commented:
sorry bug in my code
change dim cur to dim cc

Solution:
Dim H as string = "Microsoft Sans Serif; 12,25pt; style=bold"
Dim cc As CultureInfo = CultureInfo.CurrentUICulture  ' get current UI Culture
Dim Fo As Font = DirectCast(tc.ConvertFromString(Nothing, System.Globalization.CultureInfo.CreateSpecificCulture(cc), H), Font)

/R
0
 
richardd65Author Commented:
good work / and good help
thanx
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now