Improving Windows in AutoCAD
Saturday, January 24, 2026The thing that catches my eye most often when I take over a project written by someone else is the windows.
Let's take this example:

There are immediately several things that bother me:
- The OK button is spelled Ok;
- The window is too large for its content;
- The Cancel button (labeled Annuler here, sorry the screenshot comes from a French application) is stuck to the left edge of the window;
- The window background is white instead of the gray usually used for AutoCAD dialog boxes;
- The window appears in the taskbar;
- The window appears at an inappropriate position on the screen;
- There are Minimize and Maximize buttons that serve no purpose;
- The window can move to the background in certain situations.
Details, you might say, OK, but most of them can be fixed in a few clicks so it's a shame not to have fixed them.
So let's go through these problems one by one and try to solve them.
Spelling, Case
We see OK buttons all day long, they're everywhere in user interfaces. And yet, some people have apparently never realized that OK is in uppercase. Casing errors and spelling mistakes convey the image of a poor quality product.
Sometimes, some people also reverse the order of the OK and Cancel buttons, with Cancel first. This is the usual layout on macOS, and although I personally find it more intuitive, we are on Windows so we respect the platform convention. Otherwise, users may reflexively click on the wrong button.
Window Size
The window was developed in WPF. WPF uses an automatic layout system, so we can ask it to automatically adjust the window size based on its content.
Just add the SizeToContent="WidthAndHeight" property to the window and remove the Height and Width properties (as well as constraints like MinHeight, MinWidth, MaxHeight, MaxWidth).
Personally, most often, I set the width and ask WPF to calculate the height automatically with SizeToContent="Height", because input controls like TextBox and ComboBox don't have a default width, and so they take a width that depends on their content.
Cancel Button Stuck to the Right Edge
Often, we have a grid or StackPanel at the root of the window content, so to detach the content from the edge, just specify a margin with the Margin attribute. In AutoCAD, it's about nine pixels.
White Window Background
Here, just change the window background color with the Background property. In AutoCAD, the gray usually used for dialog boxes is #F0F0F0.
The Window Appears in the Taskbar
That's a WPF quirk. On the Window element, you need to add the ShowInTaskbar="False" property to prevent the window from appearing in the taskbar. It's appropriate for the application's main window, but not for all other windows, so in my opinion, Microsoft should have chosen to set this property to False by default.
The Window Appears at an Inappropriate Position on the Screen
Here it starts to get a bit more technical. To begin with, in WPF, there's a WindowStartupLocation property that can take the values CenterScreen, CenterOwner or Manual. By default, it's Manual and so the window appears wherever Windows decides, which is somewhat random.
The best approach here, since we have a modal window (a window that blocks interaction with the rest of the application), is to center it on the screen with WindowStartupLocation="CenterScreen". We use Manual when we want to specify a precise position, generally when we want to position a non-modal window in a corner of the screen so as not to interfere with content interaction.
We'll come back to the third option CenterOwner later.
Useless Minimize and Maximize Buttons
Here the window is actually a form for entering information. We don't need to occupy the whole screen for that, there are only a few fields. So no need for a Maximize button. We don't have a property to hide the Maximize button, but we can change the window's resize mode with the ResizeMode property. Since we don't need to resize the window, we use NoResize. WPF then automatically hides the Maximize button.
For the Minimize button, it's again a WPF quirk. We don't have a property to hide this button. Yet, it's inappropriate to display it in most cases.
To hide it, we need to change the window style and there, watch out, we need to bring out the heavy artillery (Interop with Win32).
using System;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Interop;
public abstract partial class WindowWithoutMinimizeButton : Window
{
const int GWL_STYLE = -16;
const int WS_MINIMIZEBOX = 0x20000;
[LibraryImport("user32.dll", EntryPoint = "GetWindowLongPtrW")]
private static partial IntPtr GetWindowLongPtr(IntPtr hWnd, int nIndex);
[LibraryImport("user32.dll", EntryPoint = "SetWindowLongPtrW")]
private static partial IntPtr SetWindowLongPtr(IntPtr hWnd, int nIndex, IntPtr dwNewLong););
protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e);
IntPtr hwnd = new WindowInteropHelper(this).Handle;
IntPtr style = GetWindowLongPtr(hwnd, GWL_STYLE);
// Remove the Minimize button
style &= ~new IntPtr(WS_MINIMIZEBOX);
SetWindowLongPtr(hwnd, GWL_STYLE, style);
}
}
We actually have to create a class derived from Window to be able to override OnSourceInitialized. This method is called when the window is initialized and is specifically intended for possibly changing the window style. We use GetWindowLongPtr and SetWindowLongPtr to modify the window style, removing the WS_MINIMIZEBOX flag.
Note that here, I use LibraryImport to import Win32 functions, which is a feature introduced in .NET 7, so this code is only valid for AutoCAD 2025 and later versions. For earlier versions, you'll need to use DllImport instead.
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr GetWindowLongPtr(IntPtr hWnd, int nIndex);
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr SetWindowLongPtr(IntPtr hWnd, int nIndex, IntPtr dwNewLong);
The Window Can Move to the Background
Last point on the list and the most complicated. In Windows, an application's windows form a hierarchy. Each window can have children and/or a parent. In WPF, this parent/child relationship must be explicitly defined. If you don't do this, the window may have behavior that isn't what you expect.
If for example, you have a modal window displayed in AutoCAD and you switch to another application, when you return to AutoCAD by clicking on its icon in the taskbar for example, AutoCAD's main window will come to the foreground and will hide your window. Since it's a modal window, AutoCAD will appear frozen.
This can be problematic because the user may think that AutoCAD has crashed when in fact, it's simply waiting for the modal window to close.
To prevent this from happening, you need to designate AutoCAD's main window as the parent of your modal window. The best way to do this is to use the Autodesk.AutoCAD.ApplicationServices.Application.ShowModalWindow() method instead of System.Windows.Window.ShowDialog().
There's an overload of this method that takes an owner as a parameter:
public static bool? ShowModalWindow(IntPtr owner, System.Windows.Window formToShow);
AutoCAD provides the handle to its main window via the Application.MainWindowHandle property. So, you can use:
var window = new MyModalWindow();
Application.ShowModalWindow(Application.MainWindow.Handle, window);
There you go, this way, the two windows will be linked and the modal window won't be able to move to the background.
Note that this ShowModalWindow() method also saves the window's position and size to restore it when it's displayed again. Personally, I prefer to keep my window centered, so I rather use:
public static bool? ShowModalWindow(System.Windows.Window owner, System.Windows.Window formToShow, bool persistSizeAndPosition);
The boolean persistSizeAndPosition allows you to specify whether the window's position and size should be saved and restored. I pass false to keep my window centered.
Finally, I told you that WindowStartupLocation had a CenterOwner option. As you can guess, instead of centering the window on the screen, you can center it on the owner window. I think this is the best option, if for example your user has an ultra-wide screen.
Conclusion
There you have it, by following these tips, you can significantly improve the user experience of your windows in AutoCAD.
Need an AutoCAD (AutoLISP, ObjectARX, .NET, VBA) development? Contact me for a free quote.