【发布时间】:2021-02-19 18:39:40
【问题描述】:
据我的另一个question:
我有一个列表和一个选定的索引,我序列化:
public interface IControlListManager
{
List<ControlListManager.TargetSettings> TargetList { get; set; }
int SelectedIndex { get; set; }
}
在designer.cs里面我得到了下面的序列化代码:
//...
controlListManager1.SelectedIndex = 0;
controlListManager1.TargetList.Add(new ControlListManager.TargetSettings(this, "", DisplayModes.FollowXY, true, 0, 0, 0));
controlListManager1.TargetList.Add(new ControlListManager.TargetSettings(this.InfoPanel, "", DisplayModes.FollowXY, true, 0, 0, 0));
controlListManager1.TargetList.Add(new ControlListManager.TargetSettings(this.InfoText, "", DisplayModes.FollowXY, true, 0, 0, 0));
controlListManager1.TargetList.Add(new ControlListManager.TargetSettings(this.HLine, "", DisplayModes.FollowXY, true, 0, 0, 0));
controlListManager1.TargetList.Add(new ControlListManager.TargetSettings(this.LogiDevType, "", DisplayModes.FollowXY, true, 0, 0, 0));
controlListManager1.TargetList.Add(new ControlListManager.TargetSettings(this.LogiDevSetBtn, "", DisplayModes.FollowXY, true, 0, 0, 0));
controlListManager1.TargetList.Add(new ControlListManager.TargetSettings(this.SystrayContextMenu, "", DisplayModes.FollowXY, true, 0, 0, 0));
controlListManager1.TargetList.Add(new ControlListManager.TargetSettings(this.restoreToolStripMenuItem, "", DisplayModes.FollowXY, true, 0, 0, 0));
controlListManager1.TargetList.Add(new ControlListManager.TargetSettings(this.exitToolStripMenuItem, "", DisplayModes.FollowXY, true, 0, 0, 0));
controlListManager1.TargetList.Add(new ControlListManager.TargetSettings(this.panel1, "", DisplayModes.FollowXY, true, 0, 0, 0));
controlListManager1.TargetList.Add(new ControlListManager.TargetSettings(this.IdentifierInput, "", DisplayModes.FollowXY, true, 0, 0, 0));
controlListManager1.TargetList.Add(new ControlListManager.TargetSettings(this.ExitButton, "", DisplayModes.FollowXY, true, 0, 0, 0));
controlListManager1.TargetList.Add(new ControlListManager.TargetSettings(this.IdentifierCheckbox, "", DisplayModes.FollowXY, true, 0, 0, 0));
controlListManager1.TargetList.Add(new ControlListManager.TargetSettings(this.SaveLogFile, "", DisplayModes.FollowXY, true, 0, 0, 0));
//...
问题是SelectedIndex 应该在列表之后,因为它很好地代表了列表的索引。
如何告诉设计师把它放在列表后面?
【问题讨论】:
-
谢谢。这就是我一直在寻找的。span>
-
嗯。只是一个小问题。答案中的人说默认情况下它将按字母顺序设置。我可以将 SelectedIndex 的 var 名称更改为 ZSelectedIndex 吗? ;)
标签: c# visual-studio winforms visual-studio-2010 serialization