4

I was trying to resize a control with the mouse, holding down Left-button + Shift, hoping that both width and height would be adjusted proportionally (like in Photoshop). Didn't work.

I Googled to find out how to do that, sure enough that I'd have an answer within one minute. To my surprise I couldn't find anything.

Must I understand that Visual Studio, even as far as version 2013, lacks this very basic designing feature?! Or do I just keep missing it?

Please note that this isn't for a particular control only; it's a designing tool I would want to use on anything that can be "drawn" on a form / user control.

Crono
  • 10,211
  • 6
  • 43
  • 75
  • Not sure if it exists, but you could just set the size manually in the designer code or you could resize to the horizontal/vertical size you want, then use the designer code to tweak the other dimension to make the control square again – Charleh Sep 11 '14 at 12:51
  • 3
    To my surprise I have never missed it. – TaW Sep 11 '14 at 12:51
  • @Charleh This is what I'm ending up doing every time but quite frankly I could use something a tad more efficient. :/ – Crono Sep 11 '14 at 12:53
  • Not sure then bud, maybe upgrade to WPF (sorry not very constructive, and yes extremely rarely I have to maintain some legacy VB6 apps so I know your pain) – Charleh Sep 11 '14 at 12:54
  • *Very basic designing feature*... Visual Studio form designer (as well as xaml-designer) have all basic functionality, which means you will be able to change any property by using mouse and properties window. Things like *proportional* resize is simply another wish, which may seems *very important* to you, but do they? To example me, I never need that. Moreover, when you switch to wpf, you will find out using table-layouting most of time, which you also can do in winforms (`TableLayoutPanel`). – Sinatr Sep 11 '14 at 13:04
  • Would be simple to implement if control sizes were stored in floating point. Of course they're not so this can't ever do anything but annoy a programmer with accumulating off-by-one errors. You will not get this beyond the wishful thinking stage. – Hans Passant Sep 11 '14 at 15:21
  • @HansPassant I haven't thought of that. In my scenario controls are square-shaped so it wouldn't matter but indeed it wouldn't work well with rectangle-shaped controls. Still would be great to have for square though. – Crono Sep 11 '14 at 16:12
  • Just type in the number instead of mousing it. – Hans Passant Sep 11 '14 at 16:13
  • @HansPassant Right now I'm using both mouse and keyboard. Stretching the controls so they snap to edges of container or sibling controls works better than trying numbers until it gives the result I want. When I'm close enough of the desired result I then manually enter width or height number. Just thought there could be a better way, that's all. – Crono Sep 11 '14 at 16:24
  • @Crono: There is always a better way. The question is, do you want to spend time on it? If you are really bothered with that problem, write a simple Container control that will be able to have only one child, and that will layout its child so that the child's width/height are equal and match the size of the Container. Then, you should be able to place the Containers on the form (like you do with TableLayout or Panel) and put your squareish controls inside it. Voil'a. – quetzalcoatl Sep 14 '14 at 10:52
  • @Crono: Another way is to write the squareish controls so that .. they **are** square, not rectangular. Controls can control their own size, just override the correct layouting methods in the control. You can even make that behavior optional and bound to some boolean true/false property that'd be settable on that squareish controls by the Properties window or even by the handy smart-tag (the small popup window that some controls show in the designer, the popup which opens by the small triangle in the top-right corner of the control's view). – quetzalcoatl Sep 14 '14 at 10:55
  • 3
    People who voted to close this because it's "primarily opinion-based", would you care explaining how it is? Thanks. – Crono Nov 25 '14 at 13:23

1 Answers1

2

You could always extend the control you want to maintain the ratio of:

public class Panelx : Panel {

    private int _width;
    private int _height;
    private double _proportion;
    private bool _changingSize;

    [DefaultValue(false)]
    public bool MaintainRatio { get; set; }

    public Panelx() {
        MaintainRatio = false;
        _width = this.Width;
        _height = this.Height;
        _proportion = (double)_height / (double)_width;
        _changingSize = false;
    }

    protected override void OnResize(EventArgs eventargs) {
        if (MaintainRatio == true) {
            if (_changingSize == false) {
                _changingSize = true;
                try {
                    if (this.Width != _width) {
                        this.Height = (int)(this.Width * _proportion);
                        _width = this.Width;
                    };
                    if (this.Height != _height) {
                        this.Width = (int)(this.Height / _proportion);
                        _height = this.Height;
                    };
                }
                finally {
                    _changingSize = false;
                }
            }
        }
        base.OnResize(eventargs);
    }

}

Then all you need to do is set the MaintainRatio property to 'true' to have it resize appropriately.

This solution could prove quite arduous if you need it to work with many different controls, though.

Ulric
  • 826
  • 5
  • 16
  • This would only solve the issue on a specific control, which isn't what I want. I updated the question. – Crono Mar 30 '15 at 16:10
  • Yes, my solution would make a lot of work for you if you wanted it on all controls. – Ulric Mar 30 '15 at 16:22