-1

I am using c# and i am creating a simple design where i have a user control and some components inside it like treeviews and buttons. I am trying to fill a treeview with some nodes and drag-drop these nodes to other treeview and use the buttons to also copy nodes from side to another.

The problem i am having is that when i maximize the window containing this user control there is no effect on the inside components.

I have set the Dock property of the user control to Fill.

I have changed the anchor properties of the buttons and treeview inside the user control but the behavior wasn't as expected. For example i have tried to set the anchor property for the right treeview to be Top,Bottom,Left => and the result was a disaster

I have also done a lot of combinations for the anchor property of all the buttons but nothing gave me the right behavior. I just only need to maximize the window form and the controls will be maximized with the same proportion.

  • Screenshot? Would be much easier to understand. You want to also resize the buttons when maximazing the form? – C4d Dec 15 '14 at 14:24
  • Do you understand what dock and anchors exactly do? Because it's quite simple and any strange behavior can be solved easily by just looking at the containing control. Button usually are just anchored to a corner (top left, bottom right, etc.), so they don't resize. – Andrew Dec 15 '14 at 15:46
  • @C4ud3x i have tried to upload pics but i couldn't because this is the first time posting here and it required that i have 10 recommendations:) – MohamedSalem Dec 15 '14 at 16:33
  • @Andrew i understand a little about anchor and dock and used it for a while but when i am using it with treeview everything gets messy This is what i am trying to do: This is what i am trying to do And this what i get when i maximize: photobox.co.uk/my/photo/full?photo_id=2528891743 – MohamedSalem Dec 15 '14 at 16:40
  • This would be really similar to what I did [here](http://stackoverflow.com/questions/19074819/vb-c-resizing-two-controls-equally). – Idle_Mind Dec 15 '14 at 17:02
  • @Idle_Mind thank you that is exactly what i was trying to do :) – MohamedSalem Dec 15 '14 at 18:21

1 Answers1

0

It sounds like you want a "3 column" interface where you have a TreeView on either side and Buttons in the middle to allow movement between the two. Assuming this is correct, you can accomplish your automatic resizing by using a TableLayout.

Essentially, it would be like this:

  1. Add a TableLayout and edit the rows/columns such that there is a single row with 3 columns:
    • The first and last column would be sized at 50% (and would hold your TreeViews).
    • The middle would be an absolute size of (for example) 120. This would hold your Buttons.
  2. Set the properties of this new TableLayout to Dock -> Fill the form. This will size the entire table to grow with your form.
  3. Add your TreeView controls to the left/right columns and set them to Dock -> Fill the respective columns. Since these columns are dynamically sized, they will grow with the form.
  4. In your middle column, add a Panel and set it to Dock -> Fill. We add a Panel here to hold the multiple Buttons you use for movement. This Panel will not grow in size because the middle column is sized absolutely.
  5. Add your Buttons to the middle Panel.

Without a screenshot, I'm not completely sure what you are trying to achieve but I believe this is along the lines of it. The nice thing about this setup is there is zero code involved.

Jason Faulkner
  • 6,378
  • 2
  • 28
  • 33
  • Thank You Jason for your answer but after doing the steps you have mentioned above I have faced the following form shape: http://www.photobox.co.uk/my/photo/full?photo_id=2528881399 This is what i wasn't thinking of, i need to add the treeview in the center of the form and when maximized, it will be still in the center keeping the same proportion with the form just to be maximized and minimized easily :) – MohamedSalem Dec 15 '14 at 16:31
  • This is what i am trying to do And this what i get when i maximize: http://www.photobox.co.uk/my/photo/full?photo_id=2528891743 – MohamedSalem Dec 15 '14 at 16:35
  • @MohamedSalem - Your graphics links do work. It wants me to create an account. – Jason Faulkner Dec 15 '14 at 16:51
  • how can i share an image here because i am new in posting to stack overflow :) – MohamedSalem Dec 15 '14 at 16:54
  • @MohamedSalem - My solution should allow you to create the same interface illustrated in Idle_Mind's post (from the comment thread in your question). – Jason Faulkner Dec 15 '14 at 22:16
  • Yes thank you for your help :). First i tried it and it didn't work but i did it again and worked just fine. Thank you a lot :) – MohamedSalem Dec 16 '14 at 10:07