views:

347

answers:

2

Ok, I have googled, but maybe I put my search in weirdly. :/

I have a VB.NET WinForms application. I have the anchor properties set for all the controls so that it will resize all the controls to look decent when the form is maximized. (Haven't gotten around to manual resizing yet however).

Anyway, the problem:

I go to set the same properties for a button (testing with a single button for now) on the main GUI form/picture. When I go to run the program via F5, it looks decent. But when I maximize the form, the entire button covers up more than it should.

I've taken screenshots of the form so you can see a visual of what I'm talking about. :/

Before: http://zack.scudstorm.com/before.png
After: http://zack.scudstorm.com/after.png

What other propert(y|ies) do I need to set for the buttons to show up correctly? :/ (The buttons go over the boxes that say, for example, "1-1", "2-3", etc.

Thanks,
-Zack

+3  A: 

Seems like you have anchored top-left and bottom-right when what you want is just top-left.

Edit: If it's just an image that does not change when the winform changes, then don't anchor your buttons at all. Just put them where they go. If you are scaling the image, then I would either detect the clicks on the image and do the scaling math or do the scaling math and set my buttons in code in the Form.OnResize event.

JP Alioto
Kinda worked. It doesn't resize the button to cover the form now. Now, it just moves it up off the box that it's supposed to cover up.
Zack
Oh, I see, you want the button to cover the boxes. What are the boxes? An image?
JP Alioto
The boxes are laid out on an image that represent computers in a computer lab. The whole image is this ( http://zack.scudstorm.com/Workstations_828x633.png ).
Zack
Thanks for the help! :)
Zack
Sure, no problem ... glad to help.
JP Alioto
+2  A: 

As it appears that your goal is just to be able to handle clicks on the "computers"...

One option that can be useful for this sort of task is to create an "overlay" bitmap (not displayed, but which is the exact same size as your source bitmap) which uses different colors to represent all the clickable regions. (e.g. (R=0,G=0,B=0) for computer 0, (0,0,1) for computer 1, etc)

You could even generate this bitmap somewhat automatically without too much trouble (If you have a mode where you can click the top left and then bottom right corners of the image to define a new region)

When the mouse is clicked, you can check the pixel at the scaled coordinates of the mouse position in the overlay and determine what their click corresponds to. This can be a lot easier than creating loads of controls, and makes it a lot easier to have clickable regions that aren't rectangular.

Daniel LeCheminant
UP-voted because you're helpful! Even though it's a lot of work. :(Thanks for the help.
Zack
@Zack: Honestly, if you do the overlay approach, it shouldn't be so bad ... about as much trouble as placing all the buttons!
Daniel LeCheminant