에 대해 얼마나 좋아
. 그런 다음 XmlSerializer
을 사용하여 각 명함을 XML (또는 바이너리) 파일로 단일 폴더로 직렬화하십시오. 그런 다음 string[] businessCards = Directory.GetFiles(Path.GetFullPath("mysettings\\businesscards"));
과 같은 것을 사용하여 긴 '캐시 된'명함 목록을 반복 할 수 있습니다. SerializableBusinessCardClass GetNextCard() {}
과 같은 함수를 호출하여 FlowLayoutPanel
항목 추가/제거를 관리하는 클래스를 갖습니다. 이것은 구현하기가 매우 쉽습니다. List<SerializableBusinessCardClass>
길이가 약 5 인 (또는 한번에로드하고 싶지만) 많은 XML 파일을 단일 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; }
}
사용법 :
: 여기
public void stackoverflow_BusinessCard_FlowLayoutPanel()
{
List<string> labels = new List<string>();
labels.Add("Title");
labels.Add("Description");
labels.Add("Phone");
labels.Add("Email");
labels.Add("Address");
labels.Add("label6");
labels.Add("labelN");
ComboItem cItem = new ComboItem();
cItem.Collection = new List<string>();
cItem.Collection.Add("Option1");
cItem.Collection.Add("Option2");
cItem.Name = "comboName";
cItem.SelectedIndex = 0;
cItem.Text = cItem.Collection[cItem.SelectedIndex];
cItem.Location = new Point(50, 265);
cItem.size = new Size(100,21);
List<ComboItem> comboItems = new List<ComboItem>();
comboItems.Add(cItem);
SerializableBusinessCard bCard1 = new SerializableBusinessCard();
bCard1.Name = "CompanyXYZ_BlueTheme";
bCard1.Company = "CompanyXYZ";
bCard1.Labels = labels;
bCard1.ComboBoxes = comboItems;
SerializeObjectXML("BusinessCard_392.xml",bCard1);
SerializableBusinessCard loaded = DeserializeBusinessCardXML("BusinessCard_392.xml");
}
직렬화 기능입니다
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;
}
희망.
이것은 힌트를 줄 수 있습니다. http://stackoverflow.com/questions/835100/winforms-suspendlayout-resumelayout-is-not-enough – rene
빠른 답장을 보내 주셔서 감사합니다, Rene. 저의 가장 큰 관심사는 핸들이 다 떨어지는 문제입니다. 이 문제를 해결하지 않으면 속도에 대해 걱정할 필요가 없습니다. – user1646737
당신은 flowlayout 가상 (또는 페이지, 무엇이든 더 convienant)을 만드는 다른 옵션이 없습니다 – rene