繁体   English   中英

使用C#保存并重新加载动态生成的Windows窗体

[英]Save and reload a dynamically generated Windows Form in C#

我试图创建一个Windows窗体,用户可以在其中运行时动态添加用户控件并填写它们。

有什么方法可以保存Windows窗体的状态并在以后重新加载?

用于生成添加用户控件的代码示例:

private void assignmentToolStripMenuItem_Click(object sender, EventArgs e)
{
    counter++;
    tableLayoutPanel1.RowCount += 1;
    int index = tableLayoutPanel1.RowCount;
    tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.AutoSize));    

    userControl21 = new Test2.UserControl3(assignmentDisplayTemplate, assignmentCommandTemplate,variables);
    userControl21.DataAvailable += new EventHandler(userControl21_DataAvailable);      

    tableLayoutPanel1.Controls.Add(userControl21,1,index);

    userControl21.AutoSize = true;
    userControl21.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
    userControl21.Location = new System.Drawing.Point(28, 28);
    userControl21.Size = new System.Drawing.Size(335, 35);
    userControl21.TabIndex = 0;

    userControl21.Name = "Assignment" + counter;
}

您应该查看FluentSharp( https://github.com/o2platform/fluentsharp ),您或您的用户可以在其中以编程方式进行操作,例如:

var targetFolder = @"C:\\O2"; var sourceCodeViewer ="View C# and H2 files in folder".popupWindow() .add_SourceCodeViewer(); sourceCodeViewer.insert_Left(200) .add_TreeView() .add_Nodes(targetFolder.files(true,"*.cs","*.h2"), (file)=>file.fileName()) .after_Selected<string>((file)=>sourceCodeViewer.open(file));

有关大量示例,请参见https://github.com/o2platform/O2.Platform.Scripts

例如

这是Web自动化api的文档( https://github.com/o2platform/Book_WebAutomation/blob/master/O2Documentation.md ),但是WinForms API非常相似(功能更强大: https : //github.com/o2platform /FluentSharp/tree/master/FluentSharp.WinForms/ExtensionMethods

在某种程度上,您可以使用序列化来存储窗口实例的大小,然后在初始化窗口时可以将其更改回序列化的值。 但是总的来说,您试图做的是非常复杂且具有挑战性的任务,没有快速的答案。 在下面,我添加了两个链接。 一个描述了如何创建自定义布局引擎,另一个描述了一种序列化程序的实现,该序列化程序可以保存整个窗口的状态。 那应该给您一些方向寻找解答:

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM