tags:

views:

369

answers:

1

Hi! I am implementing an application that needs to drag and drop image boxes in a panel.Image boxes are added dynamically from the program and so I have set the autoscroll property to true in panel.But when I have drag out the boxes at bottom in the panel the panel size got reduced.I have put autosize property false in panel.The panel is docked in another panel.I want to set the size of panel at run time.How can I achieve this.

public form1(int[,] dummy, int columnSize, int rowSize)

    {
       this.dummy= dummy;
       numOfColumns = columnSize;
        numOfRows = rowSize;
        getData();
        addIds = addIdArray;
        data = mylist;
        InitializeComponent();
        //panel1.MinimumSize = new Size(columnSize * 40, rowSize * 40);
        //panel1.Height = rowSize * 40;
        //panel1.Width = columnSize * 40;
        //panel4.Height = rowSize * 40;
        //panel4.Width = columnSize * 40;
        int x, y;
        Structures.EmptyRectSpace space = new Structures.EmptyRectSpace();
        for (int i = 0; i < data.Count; i++)// set picture boxes 
        {

            space = (Structures.EmptyRectSpace)data[i];
            x = space.startingJ;
            y = space.startingI;
            int h, w;
            h = space.length;
            w = space.width;

             p = new PictureBox();
                p.Width = w * 40;
                p.Height = h * 40;
                p.BackColor = Color.DarkGreen;
                p.Image = Properties.Resources.v;
                p.BorderStyle = BorderStyle.FixedSingle;
                p.Name = addIdArray[i].ToString();
                p.Location = new Point((x + 1 - w) * 40, (y + 1 - h) * 40);

                this.panel1.Controls.Add(p);


        }


        foreach (Control c in this.panel1.Controls)
        {
            if (c is PictureBox)
            {
                c.MouseDown += new MouseEventHandler(pictureBox1_MouseDown);
            }
        }
        this.panel1.DragOver += new System.Windows.Forms.DragEventHandler(this.panel1_DragOver);
        panel1.DragOver += new DragEventHandler(panel1_DragOver);
        panel1.DragDrop += new DragEventHandler(panel1_DragDrop);
        panel1.AllowDrop = true;
        panel2.AllowDrop = true;
        foreach (Control c in this.panel2.Controls)
        {
            c.MouseDown += new MouseEventHandler(pictureBox1_MouseDown);
        }
        this.panel2.DragOver += new System.Windows.Forms.DragEventHandler(this.panel2_DragOver);
        panel2.DragOver += new DragEventHandler(panel2_DragOver);
        panel2.DragDrop += new DragEventHandler(panel2_DragDrop); 

    }

This is the constructor of the form that contained panel.When it loaded the picture boxes must be added to the panel and there drag drop events of panel are implemented.

Please give me a helping hand..

A: 

Can't you achieve this by the Panel.Height and Panel.Width properties?

Otherwise, if you wish to specify a minimum size for your panel dynamically, you can do so through the SetMinimumSize method, if I'm not mistaken. Is that what you're looking for?

Will Marcouiller
I have tired out by setting Panel.Height and Panel.Width but its size is reducing as I have removed images at the bottom line.What else can I do?
C. Karunarathne
I am using windows form and controls are picture boxes.I want to set size of panel once at run time
C. Karunarathne
I don't get what you wish to achieve then. Have you tried Anchoring it to your form's borders, and then setting a minimum size for it?
Will Marcouiller
Ok, Anchor is not an option then.
Will Marcouiller
Have you tried to set a minimum size?
Will Marcouiller
This panel is docked in another panel.If I have anchored it bottom it didn't show me the whole panel.
C. Karunarathne
Panel.Minimumsize also didn't worked as it also act as set anchor at bottom.
C. Karunarathne
Can you post a sample of your code so that we may better understand what are your requirements and needs? This would help us help you.
Will Marcouiller
I have added the code also
C. Karunarathne
Can anyone give me a helping hand please.............
C. Karunarathne
Docking is not working very well in .NET oppositely to Delphi. In .NET, you'd better set the Anchor. However, what I don't get, is how you cannot be shown the full panel when anchoring?
Will Marcouiller