• 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

    • Denmark ditching Windows and Office for Linux as it may not want to rely on Microsoft, Trump by Sayan Sen Back in November 2021, the German state of Schleswig-Holstein announced that it was planning to move away from closed-source Microsoft products like Office and Windows to LibreOffice. About two and a half years later, we received an update on the matter, as state officials confirmed that plans for the migration were still intact. As such, about 30,000 government sector computers would be switching by 2027 or so. Following Germany, Denmark seems to be looking to make such a move. This move should resonate pretty loudly now, given that Linux developers, including The Document Foundation, are pushing to encourage users to pick GNU instead of upgrading to Windows 11 from Windows 10. Caroline Stage Olsen, the current Minister for Digital Affairs of Denmark, told the Danish media outlet Politiken that there are plans to phase out Microsoft products in her own ministry next month, and more precisely, moving away from Office 365 to LibreOffice. When discussing the potential challenges of implementing such deployments, Olsen shared a clear backup plan that her ministry has: if the new system proves too challenging at first, they will temporarily revert to the previous setup while they explore other solutions, and overall she is pretty firm on her decision as she stated, "We won't get any closer to our goal if we don't start." The report adds that, thus far, the response from her team has been positive. The minister also added that this initiative isn’t solely about Microsoft. Instead, it’s a step toward reducing an over-reliance on just a handful of providers. The report mentions that the decision could be related to recent events surrounding the International Criminal Court (ICC). For context, the ICC's chief prosecutor, Karim Khan, lost access to his Microsoft Account following Trump's sanctions (via Associated Press). There is also the issue of Trump's keen interest in Greenland, which happens to be a semi-autonomous region of Denmark.
    • Arlo Essential 2K Indoor Camera: Unpacking the features and value of this home security cam by Paul Hill Are you in the UK and looking for internal cameras to keep an eye on your pets or property? If so, the Arlo Essential 2K indoor security camera (2-pack) is now discounted by 26% from its £159.99 RRP to just £119.00. As usual, the product is available with free delivery and free returns, which is helpful if the product turns out to be defective. In addition to the discounted product, the listing also notes there’s a £10-off voucher available until Monday and a £10 Morrisons on Amazon voucher. Arlo is a reputable brand for home security cameras so this deal marks a great opportunity if you’ve been looking for this type of device. Do note that it is a wired camera so it’ll have to be plugged in somewhere. Deep dive into camera features and capabilities The Arlo Essential 2K indoor security camera comes with a very good 2K (up to 2,560x1,440) resolution that provides you with clear, detailed video, great if you want to keep an eye on smaller pets such as kittens. Not only is the camera high-quality, but the camera is equipped with black and white night vision (it can see up to 7 metres), so you can see any events that occur at night. This Arlo security cam features two-way audio with noise reduction and echo cancellation allowing you to chat with anyone coming to feed your pets. There’s also an automatic privacy lens cover that physically blocks the lens when disarmed, providing you with more privacy when at home. There is also passive infrared motion detection that has a range of 7 metres. You can use motion detection in combination with the 80 dB smart siren to scare away intruders. The siren can also be activated manually. The Arlo Essential 2K features a 130-degree wide-angle diagonal view, which is sufficient for most rooms, to capture more of what’s going on in the room and there is 12x digital zoom to take a closer look at objects. It’s compatible with pretty much all Wi-Fi devices with its 2.4GHz Wi-Fi support and it integrates with your smart home via Amazon Alexa, Google Assistant, and IFTTT. Leveraging the Arlo Secure subscription for enhanced security When you buy the Arlo Essential 2K, you get a 30-day free trial of the Arlo Secure subscription, and if you want to continue it, it costs from £11.99 per month or £119.90 per year. This subscription isn’t necessary for basic functionality, but it does unlock the full potential of the camera. When you subscribe you get secure cloud storage for video history (30 to 60 days depending on plan); AI-powered identification of people, animals, vehicles, and packages, reducing false alerts; custom activity zones that let you define areas for motion detection, minimising unwanted notifications; and interactive notifications that can be interacted with from the lock screen like view animated previews, activate siren, and call emergency services. My biggest issue with this camera is that there is no local storage for recordings, necessitating the need to buy the subscription if you want to save any footage. If you’re thinking of using this camera to protect your home from theft and want footage to give to the police, you’ll need a subscription. An alternative to a subscription is buying the Arlo SmartHub (VMB5000) which is compatible with the Arlo Essential 2K indoor camera, according to Arlo’s website. The savings on this camera twin-pack are significant and it’s the lowest price they’ve been at on Amazon UK so they’re definitely worth considering for your home. If you don’t mind the subscription or have the Arlo SmartHub already, then this camera makes sense. If not, then you may be better off with a camera that comes with an SD card slot and recording capabilities. Arlo Essential 2K Indoor Pet Security Camera (2-pack): £119 + £10-off voucher + £10 for Morrisons on Amazon (Amazon UK) / MSRP £159.99 This Amazon deal is U.K. 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 UK deals page here. Get Prime, Prime Video, Music Unlimited, Audible or Kindle Unlimited, free for the first 30 days As an Amazon Associate we earn from qualifying purchases.
    • The Nokia Lumias? Or the third-party HTC One8's? I had HTC's hardware cuz it was slick and reliable... but, yeah, the software left me wanting more and I just couldn't allocate personal time to develop all of the software I would have wanted to see (overworked in other capacities @ MSFT at the time, heh).
    • Microsoft's mobile strategy had great future vision and UX research, but mediocre engineering and inadequate support (third-party and internal business alike). The death knell for WinMo was Google's (mostly YouTube's) incessant API blocking and purposeful release of buggy WinMo builds to force consumers to stay away -- and this was conducted via sabotage of whatever partnerships they were supposed to play nice in. I still yearn for that UI on a modern smartphone...
    • Linux has always been an option but never adopted by the masses despite being free. The reasons are limited usability and features. Despite everything we all complaint about with MS , the overall experience for the general public is much better than what Linux can deliver.
  • Recent Achievements

    • Week One Done
      evershinefacilityservice earned a badge
      Week One Done
    • One Month Later
      evershinefacilityservice earned a badge
      One Month Later
    • One Month Later
      POR2GAL4EVER earned a badge
      One Month Later
    • One Year In
      Orpheus13 earned a badge
      One Year In
    • One Month Later
      Orpheus13 earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      563
    2. 2
      ATLien_0
      256
    3. 3
      +Edouard
      163
    4. 4
      +FloatingFatMan
      157
    5. 5
      Michael Scrip
      109
  • Tell a friend

    Love Neowin? Tell a friend!