Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何最大限度地提高FlowLayoutPanel的效率?_C#_Flowlayoutpanel - Fatal编程技术网

C# 如何最大限度地提高FlowLayoutPanel的效率?

C# 如何最大限度地提高FlowLayoutPanel的效率?,c#,flowlayoutpanel,C#,Flowlayoutpanel,基本目标是为每个联系人创建一张名片,并将该名片放入FlowLayoutPanel中。卡片本身由大约10个标签和3个组合框组成 不需要太多的名片,就可以使面板的初始数量花费很长时间。也许我能找到一个办法来解决这个问题 然而,一个主要问题是崩溃。它只需要大约200张卡就可以崩溃(手柄用完) 我同意有一些分页方法可以实现,因为用户一次只需要看到1到2个屏幕上显示的内容,但编写分页例程可能非常困难 关于如何最大限度地提高计划流程布局面板的效率,有什么建议吗 另外,主要问题是手柄用尽(面板中的控件太多)。

基本目标是为每个联系人创建一张名片,并将该名片放入FlowLayoutPanel中。卡片本身由大约10个标签和3个组合框组成

不需要太多的名片,就可以使面板的初始数量花费很长时间。也许我能找到一个办法来解决这个问题

然而,一个主要问题是崩溃。它只需要大约200张卡就可以崩溃(手柄用完)

我同意有一些分页方法可以实现,因为用户一次只需要看到1到2个屏幕上显示的内容,但编写分页例程可能非常困难

关于如何最大限度地提高计划流程布局面板的效率,有什么建议吗

另外,主要问题是手柄用尽(面板中的控件太多)。在担心速度之前必须解决此问题。

好的,那么:

创建一个类来存储将名片(10个标签和3个组合框)重新创建为公共、可获取/可设置属性所需的信息,并使用空的默认公共构造函数。然后,使用
XmlSerializer
将每张名片序列化为一个xml(或二进制)文件,放入一个文件夹中。然后,您可以使用类似于
string[]businessCards=Directory.GetFiles(Path.GetFullPath(“mysettings\\businessCards”)
以循环浏览长长的“缓存”名片列表。拥有一个类,该类通过调用类似于:
SerializableBusinessCardClass GetNextCard(){}
的函数来管理从
FlowLayoutPanel
添加/删除项目。这将是相当简单的实现。您还可以将长度约为5(或您希望一次加载多少)的
列表
序列化到一个XML文件中,以获得最大效率,或者如果您的名片数量实在太多(以至于浏览器在浏览文件夹时会出现延迟)。虽然二进制序列化会更快,但XML方法还有一个额外的好处,即您的客户机可以通过自己创建XML文件来指定希望您显示的新名片

在这里,我将为您提供一个具体示例,说明如何构建和序列化此类数据结构:

public class SerializableBusinessCard
{
    public SerializableBusinessCard()       { }
    public string Name                      { get; set; }
    public string Company                   { get; set; }
    public List<string> Labels              { get; set; }
    public List<ComboItem> ComboBoxes       { get; set; }

}

public class ComboItem
{   
    public ComboItem()              { }
    public string Name              { get; set; }
    public string Text              { get; set; }
    public int SelectedIndex        { get; set; }
    public Point Location           { get; set; }
    public Size size                    { get; set; }
    public List<string> Collection{ get; set; }
}
结果:

<?xml version="1.0" encoding="utf-8"?>
<SerializableBusinessCard xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <Name>CompanyXYZ_BlueTheme</Name>
  <Company>CompanyXYZ</Company>
  <Labels>
    <string>Title</string>
    <string>Description</string>
    <string>Phone</string>
    <string>Email</string>
    <string>Address</string>
    <string>label6</string>
    <string>labelN</string>
  </Labels>
  <ComboBoxes>
    <ComboItem>
      <Name>comboName</Name>
      <Text>Option1</Text>
      <SelectedIndex>0</SelectedIndex>
      <Location>
        <X>50</X>
        <Y>265</Y>
      </Location>
      <size>
        <Width>100</Width>
        <Height>21</Height>
      </size>
      <Collection>
        <string>Option1</string>
        <string>Option2</string>
      </Collection>
    </ComboItem>
  </ComboBoxes>
</SerializableBusinessCard>

希望这能有所帮助。

这可能会给你一些提示:谢谢你的快速回复,雷内。我主要关心的是手柄用完的问题。如果我不解决这个问题,就没有必要担心速度。你没有其他选择,那么让你的flowlayout虚拟(或页面,任何更方便的)一个明显的解决方案是一个带有联系人姓名的列表框和一张名片来查看/编辑所选名片。这是Windows core的限制,你不能跳过它。唯一可能的解决方案是分页。
    public void SerializeObjectXML(string filename,object obj)
    {
        using(StreamWriter streamWriter = new StreamWriter(filename))
        {
            XmlSerializer xmlSerializer = new XmlSerializer(obj.GetType());
            xmlSerializer.Serialize(streamWriter,obj);
        }
    }
<?xml version="1.0" encoding="utf-8"?>
<SerializableBusinessCard xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <Name>CompanyXYZ_BlueTheme</Name>
  <Company>CompanyXYZ</Company>
  <Labels>
    <string>Title</string>
    <string>Description</string>
    <string>Phone</string>
    <string>Email</string>
    <string>Address</string>
    <string>label6</string>
    <string>labelN</string>
  </Labels>
  <ComboBoxes>
    <ComboItem>
      <Name>comboName</Name>
      <Text>Option1</Text>
      <SelectedIndex>0</SelectedIndex>
      <Location>
        <X>50</X>
        <Y>265</Y>
      </Location>
      <size>
        <Width>100</Width>
        <Height>21</Height>
      </size>
      <Collection>
        <string>Option1</string>
        <string>Option2</string>
      </Collection>
    </ComboItem>
  </ComboBoxes>
</SerializableBusinessCard>
        public static SerializableBusinessCard DeserializeBusinessCardXML(string filename)
        {
            SerializableBusinessCard result = new SerializableBusinessCard();
            using(StreamReader streamReader = new StreamReader(filename))
            {
                XmlSerializer xmlReader = new XmlSerializer(typeof(SerializableBusinessCard));
                result = (SerializableBusinessCard) xmlReader.Deserialize(streamReader);
            }
            return result;
        }