• 0

Strange behavior in FormBorderStyle between Fixed and Sizable


Question

I have created a simple test form with FormBorderStyle = FixedToolWindow by default and added a piece of code to the form DoubleClick event that will switch between FixedToolWindow and SizableToolWindow.

Switching the FormBorderStyle between these two seems to produce a weird effect that's causing a lot of issues on my application. The problem is that the window seems to change size and I can't have that. I just want to change the border, I need the form size to remain the same.

For instance, here's the event code:

private void Settings_DoubleClick(object sender, System.EventArgs e) {
	if(FormBorderStyle == FormBorderStyle.FixedToolWindow) {
		System.Diagnostics.Debug.WriteLine("SWITCHINGED -> SIZABLE");
		FormBorderStyle = FormBorderStyle.SizableToolWindow;
	} else {
		System.Diagnostics.Debug.WriteLine("SWITCHINGABLE -> FIXED");
		FormBorderStyle = FormBorderStyle.FixedToolWindow;
	}
}

And to debug I use this:

private void Settings_SizeChanged(object sender, System.EventArgs e) {
	System.Diagnostics.Debug.WriteLine(this.Size);
}

And here's the output when I double click:

SWITCHING: FIXED -> SIZABLE
{Width=373, Height=169}
{Width=383, Height=179}
SWITCHING: SIZABLE -> FIXED
{Width=383, Height=179}
{Width=373, Height=169}

How can I fix this behavior? And by "fix", I mean, prevent this from happening if possible. I want to be able to specify my form size and to remain like that, no matter the type of border style.

Also, a solution by subclassing the Form class would be the perfect solution for me in case anyone as any ideas to solve this problem with such a method.

7 answers to this question

Recommended Posts

  • 0

Could you maintain the size property before and after the border-style change? What could be happening is that the Window size is being modified due to the change in border size for resizeable windows.

private void Settings_DoubleClick(object sender, System.EventArgs e) {
	Size size = this.Size;
	if(FormBorderStyle == FormBorderStyle.FixedToolWindow) {
		System.Diagnostics.Debug.WriteLine("SWITCHINGED -> SIZABLE");
		FormBorderStyle = FormBorderStyle.SizableToolWindow;
	} else {
		System.Diagnostics.Debug.WriteLine("SWITCHINGABLE -> FIXED");
		FormBorderStyle = FormBorderStyle.FixedToolWindow;
	}
	this.Size = size;
}

  • 0

I made a little video to demonstrate the problem. The first test shows that the form size doesn't actually change (visually), only the location of the form changes a little bit; but the values for the Size property do change, as you can see on the debug output. The second test you will see on the debug output that the form Size property values change and the window size itself will also change.

Please look here:

http://screencast.com/t/0vT1vCoyx2u

  • 0

I switched to the classic theme to get an idea of what was happening. It appears that when switching, the thickness of the border changes probably due to the style being set to thick frame for resizing. My guess is that you're seeing that a little more dramatically with the Aero theme as the frames are thicker. I don't know that you'll be able to get around it unless you subclass and set the window to not have a WS_THICKFRAME when the form border style is sizable, but then you're modifying OS behavior to accommodate resizing with a thicker frame.

Your actual client rectangle isn't being resized at all. It's the non-client areas that are changing.

Don't ask me why fixed is larger than sizable... I couldn't say. You may want to hit the forums on MSDN.

Edited by azcodemonkey
  • 0

The border is thicker on Classic and on XP but not on Vista. On Vista, if you look closely, the border has the same size or so it looks like.

Is there anything wrong in "modifying OS behavior to accommodate resizing with a thicker frame"?

I'll put this on the MSDN forums them...

In the meantime I realized something else:

The problem lies on all types of fixed border styles like FixedDialog, Fixed3D, FixedSingle and FixedToolWindow. It does not happen on the sizable ones. This problem, like I said, it also happens only on Vista.

Let's say you have a form with any of the fixed border styles and set the starting location to 0,0. What you want here is for the form to be snapped to the top left corner of the screen. This works just fine if the form border style is one of the sizable options, if it's fixed, well, the form will be a little bit outside of the screen working area both to the left and top.

What's more strange about this is that the form location does not change, it sill is 0,0, but a few pixels of the form are still drawn outside of the working screen area.

I tested this on XP and it didn't happen, the problem is Vista specific. On XP, the only difference was the border size that change a bit between any of the styles. But the form was always perfectly snapped to position 0,0.

  • 0

It's pretty bizarre behavior, for sure. I did notice that the frame still looks the same in Vista.

I've used Spy++ to verify what I'm seeing, and the frame is indeed set to WS_THICKFRAME when sizable and in Aero. Also, I'm seeing that TOP, LEFT, BOTTOM, an RIGHT of the client rectangle are what is changing, along with the overall window rectangle size to accommodate the thicker frame. I'm guessing that MS changed how frames are rendered with Aero.

Sizable:

thickframe.jpg

Fixed:

notsizable.jpg

What it means, I'm still fuzzy on. This could be a bug in DWM.

  • 0

Some people have been helping me over at the MSDN forums and one of them provided a solution that would solve the problem. The catch was that the app would no longer work on XP...

Anyway, the reason I want to do this is to allow my application, which has a skin applied, to enable or disable that skin. The whole application is working fine with the skin and I was trying to implement a property to enable and disable the skin. The issue on this topic was one of the problems I'm having when the skin is disabled. I then realized that I also have a lot of other annoying problems to deal with if the skin is disabled. Which means I'll just forget about this feature for now and leave the skin always on in the time being. I just don't have the time to handle so many issues right now...

Thanks for all your help though :)

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • I use two of these in RAID0 for video games and other things, together they are capable of 2.8 million IOPS and 15 GB/s on Gen4. At this price, 4 TB of Gen4 is faster and less expensive than a single 2 TB Gen5 NVMe, not to mention easier to cool off. Highly recommend.
    • that is a normal sign in, they just put in a dumb location to try to hide it... and yes I think the whole MS account by default is BS too, the first question should be do you want an online profile or a local one
    • From our past comments, it looks like some ppl are defo enjoying these stories.
    • You are missing the point, we should not have to do that. Should have a do you want an MS account option on the normal sign in.
    • Hynix 2TB Platinum P41 NVMe Gen4 2280 SSD is back at a mouth-watering price by Sayan Sen If you are in the market for an SSD, especially an M.2 2280 NVMe drive, then take a look at the Platinum P41 from SK hynix, which is currently back to its lowest price in the last six or so months (purchase link down below). This is a Gen4 SSD that promises sequential reads and writes of up to 7000MB/s and 6500MB/s, respectively. Meanwhile, the sequential read and write speeds are rated at up to 1400K IOPS and 1300K IOPS, respectively. The 2TB variant of the P41 features a 2GB DDR4 DRAM cache as well, which is meant to improve write caching and random access times with quicker metadata look-ups. Hynix says that the drive can operate at temperatures of up to 70 °C and thus you should opt for a heatsink if you intend to do data transfers for longer periods at a time. That should not be a problem, as the P41 Platinum is based on 176-layer TLC NAND and has a rated endurance of up to 1200 TBW (terabytes written) for 2TB. Make sure to update the firmware for the Platinum P41, as it fixes a throttling issue wherein the SSD would drop speeds after being used for several months (via Lower-Tone-3503 on Reddit). SSD firmware updates can often resolve critical problems, like in the case of WD/SanDisk SSDs, for example, which are still blocking Windows 11 24H2 due to inappropriate firmware. Get the SK hynix P41 at the link below: SK hynix Platinum P41 M.2 2280 NVMe SSD without heatsink: $129.99 + $10 off w/ promo code SACET23323, limited offer => $119.99 (Newegg US) You can also check out the other SSD deals we have covered in these articles here. This Amazon deal is US-specific and not available in other regions unless specified. If you don't like it or want to look at more options, check out the Amazon US deals page here. Get Prime (SNAP), Prime Video, Audible Plus or Kindle / Music Unlimited. Free for 30 days. As an Amazon Associate, we earn from qualifying purchases.
  • Recent Achievements

    • Dedicated
      tesla maxwell earned a badge
      Dedicated
    • Dedicated
      Camlann earned a badge
      Dedicated
    • Week One Done
      fredss earned a badge
      Week One Done
    • Dedicated
      fabioc earned a badge
      Dedicated
    • Week One Done
      GoForma earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      629
    2. 2
      Michael Scrip
      224
    3. 3
      ATLien_0
      219
    4. 4
      +FloatingFatMan
      142
    5. 5
      Xenon
      134
  • Tell a friend

    Love Neowin? Tell a friend!