[code=C# SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "(*.dat)|*.dat";
sfd.FileName = "MyObject.dat";
if(sfd.ShowDialog ()== DialogResult .OK )
{
ArrayList saveData = new ArrayList ( List);//List 是个arraylist类型,里面保存着shape类的对象
//shape类里有成员pen,brush,font。是个图形的基类
FileStream stream = new FileStream("MyObject.dat", FileMode.Create, FileAccess.Write);
{
BinaryFormatter formater = new BinaryFormatter();
formater.Serialize(stream, saveData);
stream.Close();
MessageBox.Show("保存成功.");
}
}][/code]
运行错误,说pen,brush,font未能序列化?我在shape类前面已经加了[Serializable]。只要把Pen,brush,font成员前面加上N[NOSerializable]就不会报错?
为什么? 有什么解决办法?
sfd.Filter = "(*.dat)|*.dat";
sfd.FileName = "MyObject.dat";
if(sfd.ShowDialog ()== DialogResult .OK )
{
ArrayList saveData = new ArrayList ( List);//List 是个arraylist类型,里面保存着shape类的对象
//shape类里有成员pen,brush,font。是个图形的基类
FileStream stream = new FileStream("MyObject.dat", FileMode.Create, FileAccess.Write);
{
BinaryFormatter formater = new BinaryFormatter();
formater.Serialize(stream, saveData);
stream.Close();
MessageBox.Show("保存成功.");
}
}][/code]
运行错误,说pen,brush,font未能序列化?我在shape类前面已经加了[Serializable]。只要把Pen,brush,font成员前面加上N[NOSerializable]就不会报错?
为什么? 有什么解决办法?
解决方案 »
- c# 处理文件效率变慢
- BackGroundWorker 组件 内存释放问题
- 关于用C#自定义日历的问题!
- 如何获取用ToolboxBitmap定义的图标?
- throw抛出异常又怎么样?应用程序还是中断了,throw到底怎么理解?
- c# web编程求助
- C#高级编程-GDI+ QQ群 号码是:12834521(详情请进)
- c#怎么调用api函数GetDeviceCaps呀
- 接收返回结果集的问题?
- 正在拼音输入的情况下有没办法强制把当前内容赋给TextBox?
- 高分求助~System.Transactions.IsolationLevel枚举问题
- 请教一下使用OLEDB,将数据导入到EXCEL文件的问题,那个单引号去不掉,太难看...
sfd.Filter = "(*.dat)|*.dat";
sfd.FileName = "MyObject.dat";
if(sfd.ShowDialog ()== DialogResult .OK )
{
ArrayList saveData = new ArrayList ( List);//List 是个arraylist类型,里面保存着shape类的对象
//shape类里有成员pen,brush,font。是个图形的基类
FileStream stream = new FileStream("MyObject.dat", FileMode.Create, FileAccess.Write);
{
BinaryFormatter formater = new BinaryFormatter();
formater.Serialize(stream, saveData);
stream.Close();
MessageBox.Show("保存成功.");
}
}
运行错误,说pen,brush,font未能序列化?我在shape类前面已经加了[Serializable]。只要把Pen,brush,font成员前面加上N[NOSerializable]就不会报错?
为什么? 有什么解决办法?
System.Drawing.Brush brush = new System.Drawing.SolidBrush(System.Drawing.Color.Blue);别保存brush,保存System.Drawing.Color.Blue,反序列化时在根据System.Drawing.Color.Blue生成brush
应该是shape类的问题
public class MMShape
{
[NonSerialized ]
public Pen pen = new Pen(Color.Black, 1);
[NonSerialized]
public Brush sBrush = new SolidBrush(Color.SkyBlue);
[NonSerialized]
public Font f = new Font("Arial", 10);
[NonSerialized]
public SolidBrush fontBrush = new SolidBrush(Color.Black);
public ArrayList Lines = new ArrayList();
public virtual void Drawing(Graphics g) { }
public virtual void Move(params Point[] point) { }
public virtual void SetSize(Size size) { }
}
也不可以继承