Anchor and Docking Madness

TALSOFT

Active member
Joined
Feb 23, 2012
Messages
34
Programming Experience
5-10
While I am not a novice in certain areas of VB.NET, I have to admit I feel a bit n00bish from time to time, especially since I have no formalized education (all self taught)

My current issue is based with my latest feature I am working on for my software suite SpeakSoft Xavier's SpeakSoft | Free software downloads at SourceForge.net which is a feature I am calling I want. Basically its a full screen window with 16 buttons made out of image boxes. I am trying to get these image boxes (the gray squares) to maintain their distance between each other as well as stretch to the proper screen dimensions.

It seems no matter what combination I use between anchoring and docking they either grow to the wrong sizes, go to the wrong side of the screen etc.

Currently I am trying to stick them in a panel (the yellow area) (just the first four)

Any suggestions?
Iwant2.pngIwant.png
Also unless noted by you otherwise, proper credits will be given to you in the end product.

-Taylor
PS is anyone wants to help it with SpeakSoft it would be greatly appreciated, download the app... test it, provide input or help develop if you desire....

 
The thing about Dock and Anchor is that they only deal with how a control relates to its immediate parent. How controls relate to siblings cannot be handled by Dock and Anchor alone. If your layout is very complex then it may be impossible to handle resizing and repositioning without at least some code but, in your case, simply adding a TableLayoutPanel will probably solve your issues. Check out this example:

Anchor & Dock For Automatic Resizing
 
Thanks JMC, I will go over table layout panel and read the example after I have got some much needed sleep. (I work overnights its 6AM here in AZ) lol.

If worse comes to worse, I am sure with a half hour to an hour of trial and error I can programmically make it happen.
 
Hi Taylor,

Here are few more details to save you some time:

Having a TableLayoutPanel with rows and columns to split your display area into sections is definitely the way to go.

  • Set it to fill your Windows Form, Click the top right hand corner and configure rows and columns of the grid.
  • Do not use the "autosize" option initially, we will change it later.
Also within the section of the TableLayoutPanel you are adding your buttons or icons or whatever it is often helpful to add a FlowLayout panel.

  • You can configure the FlowLayout panel to "fill" the section of the TableLayoutPanel of interest (you can set it to span rows and columns as necessary)
  • Then drag and drop buttons, icons or whatever into it
  • Then afterwards set the FlowLayoutPanel to "AutoSize" and "GrowandShrink"
  • Then in the TableLayoutPanel set the corresponding rows and columns in which the FlowLayout panel is placed to "AutoSize"
  • You will end up with the area of the buttons, icons and whatever automatically resizing to accommodate exactly what you placed there.
  • And when the Windows Form is resized by the user, everything will remain looking pretty.
Below is an example, the FlowLayoutPanel accommodates all my "buttons" and the icon images that I placed on each "button".

  • It resizes as necessary, it is set to "Flow" from left to right, there is a "right to left" flow option if you need it.
Some other "tips" - and I am not an expert but I try to be helpful with the little that I do know:

  • Achieving accurate and "resizable" positioning of icons, buttons etc. is nearly impossible to do without a FlowLayoutPanel IMHO.
  • You can use buttons as "placeholders" for your images.
    • By setting the "button" sizes you can achieve the exact spacing your images require.
    • You can easily make the buttons inactive if there is no functionality associated with the image.
    • By putting buttons underneath each image, it provides an easy way in future to implement a procedure to handle the user clicking on the image.
    • Doubleclick the button to generate its event handler stub if you need it.
  • Do not place TextBox objects inside a FlowLayoutPanel. If you do, they will not work (or at least I cannot get them to work)
    • TextBox objects need to be placed directly within the layout grid of the TableLayoutPanel
    • TextBox objects provide a very convenient way to add labels to areas of the TableLayoutPanel,
    • set them as default to "single line" and not "multiline", then center align your text and set the background color.
    • in my "example" these are the light blue labels.
    • The corresponding rows of the TableLayoutPanel are set to "autosize"
  • DataGridView objects are very useful for visualising spreadsheet and database content.
    • Ensure the default property "CausesValidataion = True" is changed to "False".
I hope this helps you and if so please "tick my box"?

Thanks,
Rob

Rob Sherratt Screen Shot.jpg
 
Back
Top