如何在C#中的文件中保存tabcontrol,是否存在任何命令或扩展名? [英] How do I save a tabcontrol in a file in C#, exists any command or extension for this?

查看:137
本文介绍了如何在C#中的文件中保存tabcontrol,是否存在任何命令或扩展名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想从C#中的System.Windows.Forms中保存一个TabControl,其中包含文件中包含的所有选项卡(tab键,选项卡文本,tab toolpptext,tab tag,tab imageindex),然后再从中加载一份文件。没有发现这个。到目前为止,tabcontrol还没有.save扩展功能。



我尝试了什么:



我的新方法:



I simply want to save a TabControl from System.Windows.Forms in C# with all its tabs (tab key, tab text, tab tooltiptext, tab tag, tab imageindex) included in a file and then later on load it again from a file. Found nothing on this. The tabcontrol has also no ".save" extension function so far I know.

What I have tried:

My new approach:

void Button1Click(object sender, EventArgs e)
{
  foreach(TabPage Tab1 in tabControl1.TabPages)
  {
  string TabData="";			     
TabData+=Tab1.ToolTipText+","+Tab1.Text+","+Tab1.Name+","+Tab1.ImageIndex+","+Tab1.Tag+"\r\n";
  }
  File.CreateText(TabData); //Here comes the exception: Invalid FileName!
}     





如何将选项卡存储在文件中,这对于它来说是正确的框架命令? File.Save不存在,所以我选择File.CreateText,但它不会这样做。之后如何回读信息? File.Load不存在。



How do I store the tabs in the file, which would be the right framework command for it? "File.Save" does not exist, so I chose "File.CreateText", but it would not do. How would I read back the info afterwards? "File.Load" does not exists.

推荐答案

首先,没有命令 - 任何类型的保存控件都不是正常行为。 />
第二:无循环部分将使你的生活变得困难 - 因为保存某些东西的唯一原因是因为内容会发生变化 - 并且部分标签控件内容就是它的TabPages集合,每个集合都有一个嵌套的Controls集合,使它成为现实。除非你保存每个TabPage及其控件,否则你无法恢复TabControl。



从思考你想要实现的目标开始,然后找出解决方法你需要保存:我通过拥有一个存储数据库的User类来做类似的事情,我的TabControl中的每个TabPage都包含一个UserControl,它接受用户并显示他们的信息。这样,我为每个用户创建了tabpage,并为其填写用户控件:

First off, no there is no command - "saving" controls of any sort is not a normal behaviour.
And second: the "no loops" parts of this is going to make your life difficult - because the only reason for saving something is because the content is going to change - and part of the tab control content is it's TabPages collection, each of which has a nested Controls collection which "makes it what it is". Unless you save each TabPage and it's controls then you can't restore the TabControl.

Start start by thinking about what you are trying to achieve, and work out just what you need to save: I do something similar by having a User class which is DB stored, and each TabPage in my TabControl contains a single UserControl which accepts a User and displays their information. That way, I create the tabpage for each user, and fill in the usercontrol for it:
List<User> justUsers = users.Values.OrderByDescending(u => entries[u].Max(r => r.CreditLimit)).ToList();
foreach (User user in justUsers)
    {
    tp = new TabPage(user.LongName);
    tp.DoubleClick += UserTabPage_DoubleClick;
    tp.Tag = user;
    UserDataView view = new UserDataView(user, entries[user]);
    view.Dock = DockStyle.Fill;
    view.ToggleDisplay += view_ToggleDisplay;
    view.TargetValue = Properties.Settings.Default.TargetValue;
    view.TargetChanged += view_TargetChanged;
    tp.Controls.Add(view);
    tabUsers.TabPages.Add(tp);
    }


这篇关于如何在C#中的文件中保存tabcontrol,是否存在任何命令或扩展名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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