質問

I'm having something like this:

class MyPanel : FlowLayoutPanel
{
     public MyPanel()

     {
        this.BackColor = Color.Red;
        this.FlowDirection = System.Windows.Forms.FlowDirection.LeftToRight;

        listBox = new ListBox();

        editButton = new Button();
        //editButton.Click += editButton_Click;

        this.Controls.Add(listBox);
        this.Controls.Add(editButton);
     }
 }

and then I'm adding it into my form dynamically. The problem is the listBox is overlapping the button. However if I try to add there 2 buttons instead of list it is working as it is supposed to - buttons are organized in 1 line from left to right. I want to reach the button to be next to the list. Can somebody advice me? Thanks

役に立ちましたか?

解決

Try This Code:

class MyPanel : FlowLayoutPanel
{
     public MyPanel()

     {
        this.BackColor = Color.Red;
        this.FlowDirection = System.Windows.Forms.FlowDirection.LeftToRight;

        listBox = new ListBox();

        this.WrapContents = false;  // Use this for control not wrapped
        editButton = new Button();


        this.Controls.Add(listBox);
        this.Controls.Add(editButton);
     }
 }

他のヒント

Give a size to your dynamically added MyPanel object. It will solve your problem.

private void Form1_Load(object sender, EventArgs e)
{
    MyPanel p = new MyPanel();
    p.Size = new Size(500, 200); //give size
    this.Controls.Add(p); // add to form 
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top