我在做一个工具,用户可以通过这个工具编辑一些图形。保存的时候,我想把一些相关的信息,比如说位置、大小、颜色等等保存到本地。
如果保存成文本文件的话,在每次存储和读取的时候会很麻烦,我现在想能不能保存成一个类似dll的东西,这样直接可以读取比如Rectangle、Size、Color等信息,不用转换。
但是不知道怎么做,有经验的大侠们能不能出手指点一下呢?

解决方案 »

  1.   

    用资源文件吧(*.resx),存取都比较好处理
      

  2.   

    你自己手里多得是例子:
     每一个windows from,除了Form1.cs代码文件外,还有Form1.cs.resx,此文件就是记录本窗体的控件的样式和基本属性的,把Form1的language属性改一下,会增加一个resx文件,里面又可以做另一种设置
     使用的方法就参见Form1.cs里面自动生成的源代码。
      

  3.   

    明白,可是我现在自己生成的My.resources资源文件,为什么就不行呢。报错的意思是调用目标发生错误。我在网上下的例子用的是.resx的资源文件,就没问题。不清楚为什么,下面是我生成资源文件和调用的代码using System;
    using System.Resources;
    using System.IO;
    public class WriteResources 
    {
    public static void Main(string[] args) 
    {  
    // Create a file stream to encapsulate items.resources.
    FileStream fs = new FileStream("My.resources", 
    FileMode.OpenOrCreate,FileAccess.Write); // Open a resource writer to write from the stream.
    IResourceWriter writer = new ResourceWriter(fs);
        
    // Add resources to the resource writer.
    writer.AddResource("String 1", "First String");
    writer.AddResource("String 2", "Second String");
    writer.AddResource("String 3", "Third String"); // Generate the resources, and close the writer.
    writer.Generate();
    writer.Close();
    }
    }ResourceManager rm = new ResourceManager("Res.My",Assembly.GetAssembly(typeof(Form1)) );
    string o = rm.GetString ("String 1");
      

  4.   

    上面的代码走到string o = rm.GetString ("String 1");的时候就会出错。不知道resources和resx有什么区别呢?
      

  5.   

    解决了,还是生成resx的xml资源文件可以用。