Sco*_*ski 13 controls combobox flowlayoutpanel winforms
我在C#winform应用程序中使用flowlayoutPanel时遇到问题.我基本上有一个流程布局面板,有3个部分.
第1节是一组2个控件..两个下拉控件,它们总是以相同的顺序,在所有实例中始终可见
第2节是一组5个不同的控件......基于一系列因素,5个控件中的1个可见,所有其他控件的Visible属性设置为false
第3节是一组3个控件..就像第1节一样,它们始终处于相同的顺序并始终可见.
因此,归结为第2节是可变的,其他的是静态的.
问题来自第2节...当我改变任何控件的可见性时,它们看起来很好(IE ...第1节然后第2节然后第3节)...除了我将组合框控件设置为可见....在这种情况下,只有在这种情况下......订单变为(第1节然后第3节然后第2节)......我无法弄清楚是什么会导致订单在同步中不同步那种情况.
我在我的方法开头基本上做的是将ALL控件设置为Visible = false ...然后我设置Section 1 Visible = true ...然后循环第2节的条件并设置适当的控件Visible = true,最后set第3节控制Visible = true.
有没有人对流程布局面板控件排序有任何经验?我无法弄清楚ComboBox发生了什么.
Gar*_*del 30
Inside FlowLayoutPanel.Controls是一个方法函数SetChildIndex(Control c, int index),它允许您将对象设置为特定索引.
由于FlowLayoutPanel使用控件的索引来确定将它们绘制到哪个顺序,因此您可以将其设置为您想要交换的控件的索引,并且它会将控制索引上升一个,然后每个控制索引.
这是我的博客中关于在FlowLayoutPanel中重新排序PictureBox的片段.
在名为的WinForm上添加FlowLayoutPanel flowLayoutPanel1:
public partial class TestForm: Form
{
public TestForm()
{
InitializeComponent();
this.flowLayoutPanel1.AllowDrop = true
}
private void AddImageToBlog(System.Drawing.Image image)
{
PictureBox pbox = new PictureBox();
pbox.SizeMode = PictureBoxSizeMode.Zoom;
pbox.Height = (_picturebox_height * _ScaleFactor);
pbox.Width = (_picturebox_width * _ScaleFactor);
pbox.Visible = true;
pbox.Image = image;
pbox.MouseDown += new MouseEventHandler(pbox_MouseDown);
pbox.DragOver += new DragEventHandler(pbox_DragOver);
pbox.AllowDrop = true;
flpNewBlog.Controls.Add(pbox);
}
void pbox_DragOver(object sender, DragEventArgs e)
{
base.OnDragOver(e);
// is another dragable
if (e.Data.GetData(typeof(PictureBox)) != null)
{
FlowLayoutPanel p = (FlowLayoutPanel)(sender as PictureBox).Parent;
//Current Position
int myIndex = p.Controls.GetChildIndex((sender as PictureBox));
//Dragged to control to location of next picturebox
PictureBox q = (PictureBox) e.Data.GetData(typeof(PictureBox));
p.Controls.SetChildIndex(q, myIndex);
}
}
void pbox_MouseDown(object sender, MouseEventArgs e)
{
base.OnMouseDown(e);
DoDragDrop(sender, DragDropEffects.All);
}
}
Run Code Online (Sandbox Code Playgroud)