Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2008 > C# 2008 aka C# 3.0
|
C# 2008 aka C# 3.0 Discuss the Visual C# 2008 (aka C# 3.0) language
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2008 aka C# 3.0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 1st, 2010, 06:07 PM
Authorized User
 
Join Date: Nov 2008
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to save a font to a file

Hi every body
I'm trying to write an phone book application and want to let the user to select the font for browsing its contacts ,and want to store the information
about that font in a file then retrieving it at form load when loading the application
i try the folowing to stotre my information
Code:
 FileStream file = new FileStream("setting.dat", FileMode.Create, FileAccess.Write);

             BinaryWriter binwriter = new BinaryWriter(file);
           //for saving tags colors 
            for(int x=0;x<6;x++)
            {
                binwriter.Write(clrIntArray[x]);
            }
          //for storing font informations
            binwriter.Write(mainDataGrd.DefaultCellStyle.Font.Name);
             binwriter.Write(mainDataGrd.DefaultCellStyle.Font.Size);
           
            file.Close();


and for loading my information

Code:
            FileStream file = new FileStream("setting.dat", FileMode.Open, FileAccess.Read);
             int[] clrIntArray = new int[6];
            BinaryReader binReader = new BinaryReader(file);

          //for reading tags colors
            for (int x = 0; x < 6; x++)
            {
                 clrIntArray[x] =binReader.ReadInt32();
            }

            //for reading font info
            string fn = binReader.ReadString();
             float sz= (float)binReader.ReadDouble();
            file.Close();
            mainDataGrd.DefaultCellStyle.Font = new System.Drawing.Font(fn,sz);

the problem is when i try to read the file for restoring myinfo i got exception error its syntax =--> "unabel to read beyond the end of the stream "
and i don't know why.
could any one help and if there a better way for storing the font than mine i will appreciate
 
Old May 1st, 2010, 06:58 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

You are trying to read a double - but you only wrote a float. Try calling ReadSingle instead.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old May 3rd, 2010, 04:53 PM
Authorized User
 
Join Date: Nov 2008
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanx samjudson you shoot the target,
could you pls tell me how to store the font style and retrived later
 
Old May 4th, 2010, 03:19 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

I thought I'd already answered that question? What else are you having trouble with?

Having you considered using project user settings rather trying to write your own file like this?
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old May 4th, 2010, 03:58 AM
Authorized User
 
Join Date: Nov 2008
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default

no i didn't use project user settings cause till now i don't know much information about it if you could explain how to use it or any tutorial link I'll be appreciate
 
Old May 4th, 2010, 04:29 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Just search for something like "c# user settings." I found this one on the Microsoft web site - its specific to visual studio 2005 but most of it should still apply I think: http://msdn.microsoft.com/en-us/libr...69(VS.80).aspx
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old May 5th, 2010, 04:30 PM
Authorized User
 
Join Date: Nov 2008
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanx i will examine it





Similar Threads
Thread Thread Starter Forum Replies Last Post
set font in text file! dpkbahuguna Beginning VB 6 2 August 23rd, 2007 07:08 AM
Write to a text file in a specific font and color shai505 C# 1 May 21st, 2006 03:03 AM
Save PDF file as text file in VB.Net kvenkatu Classic ASP Basics 0 April 7th, 2006 01:09 PM
save a PDF file as text file through VB. NET kvenkatu VB.NET 0 April 6th, 2006 12:15 PM
how to get font ,color,font size of text in win32 satishsatao Visual C++ 0 April 5th, 2006 05:05 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.