.net紧凑框架中如何使收集项在设计时持久存在? [英] How to make collection items persist at design time in .net compact framework?

查看:42
本文介绍了.net紧凑框架中如何使收集项在设计时持久存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为.NET Compact Framework 3.5应用程序创建控件.控件之一要求集合在设计时可编辑.我可以使用内置的Visual Studio 2008集合编辑器创建项目,但是当 表格已关闭.

I'm creating controls for a .NET Compact Framework 3.5 application. One of the controls requires a collection to be editable at design time. I can create the items using the built-in Visual Studio 2008 collection editor but the items are not saved when the form is closed.

如何使收集项目持久化?

What does it take to make the collection items persistent?

公共类NotebookPage
    {
      公共NotebookPage()
       {
           
       }
       
      私人字串_Caption;
      公共字符串标题
       {
          得到{return _Caption; }
          设置{_Caption =值; }
       }

       private int _PageIndex;
       public int PageIndex
       {
          得到{return _PageIndex; }
          设置{_PageIndex =值; }
       }
    }

public class NotebookPage
    {
        public NotebookPage()
        {
            
        }
        
        private string _Caption;
        public string Caption
        {
            get { return _Caption; }
            set { _Caption = value; }
        }

        private int _PageIndex;
        public int PageIndex
        {
            get { return _PageIndex; }
            set { _PageIndex = value; }
        }
    }

  公共类NotebookPageCollection:System.Collections.ObjectModel.Collection< NotebookPage>
    {
      受保护的重写void InsertItem(int index,NotebookPage item)
       {
           base.InsertItem(index,item);

           //item.Caption = string.Format("Page {0}",index);
           item.PageIndex =索引;
       }
    }

    public class NotebookPageCollection : System.Collections.ObjectModel.Collection<NotebookPage>
    {
        protected override void InsertItem(int index, NotebookPage item)
        {
            base.InsertItem(index, item);

            //item.Caption = string.Format("Page {0}", index);
            item.PageIndex = index;
        }
    }

  公共局部类笔记本:控件
    {
      公共笔记本()
       {
           InitializeComponent();
       }

      私人NotebookPageCollection _Pages = new NotebookPageCollection();

      公用NotebookPageCollection页面
       {
          得到{return _Pages; }
          设置{_Pages =值; }
       }
    }

    public partial class Notebook : Control
    {
        public Notebook()
        {
            InitializeComponent();
        }

        private NotebookPageCollection _Pages = new NotebookPageCollection();

        public NotebookPageCollection Pages
        {
            get { return _Pages; }
            set { _Pages = value; }
        }
    }

推荐答案

朋友,

没有 很吸引您,但是您的意思是您可以在重新打开表单后查看上一个收藏集吗?   如果是这样,我建议您在关闭表单时将集合保存到文件中.重新打开时,您只需要从该文件中读取内容即可.

According to your description, I didn't quite catch you, but do you mean you can view the previous collection after reopen the form?  If so, I would suggest you to save the collection to a file when you close the form. And when you reopen, you just need to read the content from that file.

.

如何 使用CollectionEditor编辑和保留收藏集

How to Edit and Persist Collections with CollectionEditor

祝您有美好的一天!

Kristin

这篇关于.net紧凑框架中如何使收集项在设计时持久存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆