views:

433

answers:

3

I've got a winform with 2 treeviews. my left treeview is being loaded with data from an adserver which is being loaded by clicking on a button. This triggers my backgroundworker which fetches my data and builds up my tree.

Now while doing this I'm disabling the treeview control and showing a picturebox with an animated gif on it. So when my backgroundworker is finished I enable back my treeview and hide my picturebox.

So what I want to do is that the picturebox stays in center of the treeview. both treeviews are on a splitted container. so maybe I need to get the borders of those panels? So when the size of the form changes, my picturebox stays nicely in the center of the treeview.

A: 

Not clear on how you set up your form, but you either want to put the logic in the form Resize event or the TreeView Resize event.

When either is resized, place the image at the location = half way across the TreeView, minus half the widht of your image, repeat for height.

Neil N
A: 
OnFormResize()
{
  Point ul = new Point((Form.ClientRectangle.Width - pictureBox1.Width) / 2,
      (Form.ClientRectangle.Height - pictureBox1.Height) / 2);
  pictureBox1.Location = ul;
}
Rob Elliott
A: 

Create a panel to the same size and location of your treeview. Add this treeview in the panel and set it to DockStyle.Fill. Add your picture to the panel and set the anchor to AnchorStyles.None.

this.panel1.Controls.Add(treeView2);
this.panel1.Controls.Add(pictureBox1);

this.treeView2.Dock = DockStyle.Fill;
this.pictureBox1.Anchor = AnchorStyles.None;

The anchor style AnchorStyles.None will keep your picture box in the center of the panel. Set your picture box in front of your tree view. Once, your processing is over just hide the picture box.

Francis B.
That was a simple solution :-)
Gerbrand