How does Visual Studio 2012 draw its window border? - c#

How can I achieve the same alpha border effect that can be seen in the new Visual Studio 2012 main window using windows forms? Its window seems to glow.

So I am not sure if it is the best method, but if you use Spy++ (32-bit) and you look in the windows, you can see that beneath Visual Studio's main window, you can see 4 "VisualStudioGlowWindow" objects.
I hooked the messages in Spy++, and as you could imagine, the 4 windows represent the 4 glowing borders around the form. Further inspection shows that these 4 "glow windows" implement the WS_EX_LAYERED Extended window style, so the glow itself isn't done in WPF (as far as I can tell.)!
Hopefully this clears some stuff up.

AFAIK you can do it with WPF using a mix of this chrome and a custom WPF border. Not sure if on WinForms you can, given it's limited styling options (compared with WPF). Anyway they are using WPF.

Unless you want to handle drawing the entire form yourself you cannot. Because Visual Studio 2010 and Visual Studio 2012 are written on top of WPF and used Windows not Forms.

Visual Studio 2012 draw its window border using native Win32 functions. It is not related to the WPF or WindowsForms -- you can do it with both.
The glow is rendered on a transparent window on top of the main window. The main window calls the DWM API to set the glass area to 0. This way you can draw over the original border and the system buttons. This is the correct way to do this.
You can look at code of WPF Shell (http://archive.msdn.microsoft.com/WPFShell) to see how the calls to DWM are made in order to remove the glass. The fact that its written to be compatible with WPF doesnt matter, because all you need is a handle (IntPtr) to the window.
If you have a WindowsForms codebase, don't migrate to WPF. WPF has not been improved in the latest .NET framework release and there are no roadmaps to improvements or new features as its team has been integrated into Windows 8 team.

Related

Form controls selection problem/bug on Visual Studio 2019

I experience a strange bug on Visual Studio 2019, and I want to know if you can reproduce it too on your project.
Usually, if you click on the form and then start dragging the mouse, you will see a selection dashed rectangle that shows which controls on the form will be selected. The problem I see is that if my Form is pretty large, for example 1900x995, then when I click and drag with the mouse on the right bottom area of the form, the selection rectangle is cut in the middle.
See this picture for better understanding:
https://i.ibb.co/xzZLfsD/VS219-Form1-Selection-Bug.jpg
If my calculations are right, then it looks like the selection rectangle is cut at about 1570x846 (if the Left-Top of the Form is 0x0).
To reproduce it, open a new project of type:
C# Windows Forms App (.NET Framework) A project for creating an application with a Windows Forms (WinForms) user interface.
Important note: It's not happening if I choose C# "Windows Forms App (a project template for creating a .NET Windows Forms (WinForms) App)".
Set the Form size to 1900x995, then click any point on the bottom-right area of the form, and start dragging with the mouse to the bottom right corner of the form.
Do you see the selection dashed rectangle cut out in the middle?
Please let me know, I want to know if it's happening only on my installation, or is it a bug in the Visual Studio 2019 itself.
If you have other version of Visual Studio, for example VS-2017, or VS-2020, please check it also. Maybe this problem occurs in other versions too and not only in 2019 version.
Thanks.

C# WPF Overlay for fullscreen applications?

I'm making an app that displays what keys you are pressing, and I was wondering if there was a way to overlay some image widgets on top of the screen so that they stay on top even when you are in full screen mode. I'm using WPF with Visual Studio. A link to a tutorial or a download to an example would help a ton!
You haven't clarified whether you want the widgets to appear over top of all windows, or just your WPF one.
If you want it to appear over just your window then look into use an adorner.
If you want it to appear over all windows then use this WindowSinker class which intercepts the WM_SETFOCUS message for your window and calls SetWindowPos to set the HWND_TOPMOST flag.

Own form border style

I always thought that form borders that use programs like iTunes or Visual Studio 2012 are done without border style and buttons as close button are drawn as images.
However once my Visual Studio wasn't responding and the border changed to the basic Windows border.
How can I get own form border? Is it possible in C#?
You are seeing the "ghost window", a window that the Windows window manager creates to replace the dead window. You see "Not Responding" in the title bar. That window isn't going to have to same custom styling of course, there's no way Windows knows how to do that properly.
You can use the Spy++ utility to look at the window properties of another app. VS2012 does in fact use a regular window style with a title bar. How they customized it is a well kept secret, I suspect they intercept WM_NCPAINT, a fairly difficult message to implement yourself. Using a borderless window is definitely easier.
Further to #Hans' post:
Using WPF you can set the windowstyle to none like this:
<Window WindowStyle="None">
Then you can implement your own buttons.

Visual Studio C# Office2007 Form Style not working

I'm using DotNetBar in VS for C#, and when I change the form to office2007, the design preview looks right, but then when I run the program, the style changes back to the default winform style.
Does anyone know what's causing this?
If you are running on Windows that has Glass then you need to set EnableGlass=false

Disable themed Window Border

In Windows XP's CMD, the Luna border isn't applied to it. alt text http://wedowebstuff.info/uploads/1272861285CMDNotThemed%5D.png
Is it possible to do it in a similar way in Visual C# Winforms, for an application? I just wonder how it's done, of course I am not going to force any of my applications to not use the beautiful XP/Aero theme :P
Thanks.
edit: Adding a note to this after many months. The Luna border isn't applied to CMD due to the fact that it is technically a 16-bit (old) application, so it does not use the standard Windows theming system (nor windowing, as demonstrated by the fact that it cannot be maximized). Applications like this are common in 32-bit windows (16-bit apps were removed in x64 Windows builds), for example, sysedit. The fact that it has a properly themed window border (but note, not the inside controls) in Vista/7, is due to the fact that Aero/Desktop Window Manager (DWM) overrides all window borders and renders them. If we switch to the Basic/Classic theme, that inconsistency continues.
The x64 cmd.exe doesn't have this problem. :)
I don't know how to modify the border, but on a side note, I do know how you can control the appearance of controls. As far as I know (I am a Linux programmer so I have limited knowledge in this field), without XPCommonControls enabled, you will have "old-style" controls, but with it, you will have "nice" buttons that are styled with the system style settings.

Categories

Resources