下列代码演示了如何使用 System.IO.MemoryStream 类把 BarManager 的状态写入流中,以及从流中读取已写入的 BarManager 的状态。

C#CopyCode image复制代码
    System.IO.Stream stream = new System.IO.MemoryStream();
    barManager1.SaveLayoutToStream(stream);
    //set the stream position to the beginning
    stream.Seek(0, System.IO.SeekOrigin.Begin);

    //...

    barManager1.RestoreLayoutFromStream(stream);
    //set the stream position to the beginning
    stream.Seek(0, System.IO.SeekOrigin.Begin);
Visual BasicCopyCode image复制代码
    Dim stream As System.IO.Stream
    stream = New System.IO.MemoryStream()
    BarManager1.SaveLayoutToStream(stream)
    'set the stream position to the beginning
    stream.Seek(0, System.IO.SeekOrigin.Begin)

    '...

    BarManager1.RestoreLayoutFromStream(stream)
    'set the stream position to the beginning
    stream.Seek(0, System.IO.SeekOrigin.Begin)