• 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 think they mean a phone like the s6 edge where it breaks on first drop guarantee
    • This high-end GEEKOM Mini IT12 (2025 Edition) PC has been slashed by $200 by Steven Parker GEEKOM reached out to let us know of a discount it is running on its site in the U.S., where you can save $200 off the i7 model of Mini IT12 2025 Edition. That brings the already discounted price of $699 down to just $499; buying link below. Below are the full specifications of the variant on offer GEEKOM Mini IT12 (2025 Edition) Dimensions Size 117 x 112 x 45.6mm Weight 652g CPU Intel Core i7-1280P (14 Cores, 20 Threads, 24MB Cache, up to 4.80 GHz) Graphics Intel® Iris® Xe Graphics Memory 32 GB Dual-channel DDR4-3200 SODIMM; expandable up to 64GB Storage 1 TB x M.2 2280 PCIe Gen 4 x4 SSD, expandable up to 2TB 1 x M.2 2242 SATA SSD slot, expandable up to 1TB Operating System Windows 11 Pro Bluetooth Bluetooth® v5.2 Ethernet Intel® 10/100/1000/2500 Mbps RJ45 Ethernet Wireless LAN Intel® Wi-Fi 6E AX211 Kensington Lock Yes Adapter 19V power adapter, 90W, with geo-specific AC cord (IEC C5) I/O Ports 3 x USB 3.2 Gen 2 ports 1 x USB 2.0 port 2 x USB4 ports 1 x SD card reader 1 x 3.5 mm headphone jack 1 x 2.5GbE LAN port 2 x HDMI 2.0 ports 1 x DC jack 1 x Power button MSRP $699 (see below for discount price) You may remember that we reviewed the i7-1260P variant in 2023. Here are our initial impressions of the Mini IT12 at the time. Once you have the PC out of the cushioning inside the box and the foam removed, you are greeted with a Thank You envelope. Below that, after removing the cardboard "shelf," you can find the other components, such as the power lead, HDMI cable, VESA mount plate with a bag of screws, and the instruction manual. What’s In The Box 1 x Mini IT12 Mini PC 1 x VESA Mount 1 x Power Adapter 1 x HDMI Cable 1 x User Guide 1 x Thank You Card As you can see, one HDMI cable is included in the box. Since the port is not HDMI 2.1, you will need to consider purchasing a mini DisplayPort cable or a USB4 (Type-C) to DisplayPort cable to maximize the potential of the Iris Xe Graphics display options. In addition, GEEKOM offers a one-year full warranty on its products, and if needed, you can RMA or return them locally relative to your region (the U.S. has a U.S. warehouse, and the E.U. has a Germany warehouse). Buy the i7-1280P Mini IT12 (2025 Edition) for $499 (was $699) at GEEKOM U.S. Buy the i7-1280P Mini IT12 (2025 Edition) for $499 (was $699) at Amazon U.S. When checking out, use the $30 in-page coupon or NEOIT122025 coupon code. Best of all, the shipping is quick and free.
    • That's ######ing hilarious! And it sure works when you look at both of their faces.
    • When it comes to games specifically, sure, but until now the main focus has been on doing work. All you have to do is look at how hard they're pushing AI in the productivity space to see that they've got their enterprise users in mind 1st with gamers lower on the list. Now that should all change, at least for custom gaming devices like handhelds and even, I expect, custom mini-PCs that are like consoles you can put under your TV. The whole "Xbox PC" branding they had around the show says a lot IMO.
    • I'm excited to check this out. I never played the first version, but I did just finish playing through Smalland, and while I liked it, I found myself wishing for more engaging content.
  • Recent Achievements

    • Enthusiast
      the420kid went up a rank
      Enthusiast
    • Conversation Starter
      NeoToad777 earned a badge
      Conversation Starter
    • Week One Done
      VicByrd earned a badge
      Week One Done
    • Reacting Well
      NeoToad777 earned a badge
      Reacting Well
    • Reacting Well
      eric79XXL earned a badge
      Reacting Well
  • Popular Contributors

    1. 1
      +primortal
      470
    2. 2
      +FloatingFatMan
      283
    3. 3
      ATLien_0
      251
    4. 4
      snowy owl
      202
    5. 5
      Edouard
      197
  • Tell a friend

    Love Neowin? Tell a friend!