Skip to main content

Want to cancel resize on a control?

If you are trying to cancel the resize event, it might be more difficult than you had imagined. A lot of the time you will find posts on stack overflow mentioning storing and restoring of the size before and after it resizes.

I have two problems with that:
1) it isn't actually canceling the resizing
2) that is not what the user asked for

Sadly, canceling the resize event isn't actually possible. At least not in the traditional sense. You can however, override the OnResize event of the control and then not call the base.

1
2
3
4
    protected override void OnResize(EventArgs e)
    {
        //base.OnResize(e);
    }

This will for all intents and purposes, cancel the resize event. Even though one cannot cancel the resize event, or so I was told. Maybe you can... Maybe you can't, I don't know. But I bet it won't resize anymore!

Comments

Popular posts from this blog

Connecting VS 2008 to TFS?

Trouble connecting vs 2008 to TFS? If you are running a newer version of TFS, 2008 does not understand collections. In order to fix that, you need the following installed: SP1 http://www.microsoft.com/en-us/download/details.aspx?id=13276 Team Explorer http://www.microsoft.com/en-us/download/details.aspx?id=16338 Forwards Compatibility https://www.microsoft.com/en-us/download/details.aspx?id=10834

Winforms + Transparent Background? LimeGreen? AliceBlue?

For starters, winforms will complain that you cannot set the background of the form to transparent. After a little digging, I found on a stack over flow  post that you can set the background to an obscure colour like limegreen. Lo and behold, we have a properly transparent form. I was using this for a quick and dirty way to select an area to screen capture. However there is one issue. The transparent form results in the click events going through to what ever is underneath it. As illustrated in the screen shot above, you can select text directly underneath it. This is pretty cool, especially if TopMost is set to true. However...the grip resize was also not being triggered. In other words, I cannot resize the new form. If the grip was on top of the parent form, then the resize event would work.  I tried a few approaches, such as intercepting the hittest, a few interops. But in the end the solution was quite simple.If you set the background colour to AliceBlue...

File menu opening on wrong side? [Windows 10]

If you are using windows 10 and the file menu opens on the left side, here is a fix: Run (Win+R) paste the following: shell:::{80F3F1D5-FECA-45F3-BC32-752C152E456E} click "Other" tab choose "Left-handed" Now the menu should open within the window: