On my current project the user can create a control that gets docked in a TableLayoutPanel. The controls name gets saved in a StringCollection and on every start of the program the controls get recreated. I would like to implement a feature that allows the user to change the order of the controls. The moving part is working, the problem is that next time the program gets started, the controls get recreated in the old order because they get created from the StringCollection. That means to change the order of the controls and keep that for the future i would have to change the sorting of the StringCollection. Is there any way to do that? And if yes, how would i go about that?
Currently i would move the control up with this code from a context menu:
if (this.Parent == null)
return;
var index = this.Parent.Controls.GetChildIndex(this);
if (index <= this.Parent.Controls.Count)
this.Parent.Controls.SetChildIndex(this, index - 1);
and obv. move it down with +1 instead. In the loading event i just go through the StringCollection with foreach and create the controls.
foreach (string line in Properties.Settings.Default.MessageStringCollection)
{
if (!String.IsNullOrEmpty(line))
{
createNewMessageButton(line);
}
}