Recently, I was sorting out and writing a WinForm application based on C#, and then encountered a problem that other readers may also encounter, that is, the animation effect of C#'s Borderless borderless form.
In Visual Studio 2022, the C# WinForm program provides the style effect of Borderless borderless form, but it does not provide the animation effect of loading, minimizing and maximizing the form under the borderless form. . Many readers should have encountered this animation effect problem. I have searched for other examples of borderless forms, many of which only set the state of the form as minimized or maximized in the button, but this form is displayed and disappeared directly, there is no form with a title bar Animation effect. Therefore, in order to solve this problem, you need to handle the animation effect of this borderless form yourself. After some searching and coding, I finally have today's blog post about the perfect animation effect solution for borderless windows. See the following introduction for details:
1. Project directory;
See the screenshot below for the project directory. For details, please open the solution to view it.
2. Introduction of some codes;
The following is an introduction to some function codes.
1) Borderless form parent class definition;
The parent class author arranges and puts it in the BorderlessAnimation directory in the Componet directory, directly copies the directory to the corresponding project, and the specific code readers change the namespace in the Native.cs file and FormBase.cs file by themselves, and then put it in the corresponding In the component library or under the project folder, other forms used can be applied.
Some API functions used by this parent class are placed in Native.cs. The FormBase file is the inheritance class of the form, which mainly writes functions such as message processing of the form.
2) Sample code for borderless form;
The form inherits the class, mainly processes the message of the form, and then executes the operation. The following is an example, and the implementation function is under the file. Readers are invited to read for themselves. Because it is relatively simple, no comments are written.
3) Form application example;
Two examples of form usage are provided in the project. Demo1 is the original example, and Demo2 is a usage example written by the author. It is more concise and readers can modify it directly according to their needs.
3. Operation effect diagram;
Here is the effect of running:
1) The original example:
2) A concise example:
4. Source code download;
The source code download is provided here, please open the following link if you need it: https://download.csdn.net/download/lzhdim/88084280
At the end of writing, if you have any problems with this solution, you are welcome to modify and update the source code, so that the source code of this solution can help more readers who need to solve the borderless form animation effect. In fact, the parent class of the borderless window is mainly to modify the window through the API functions provided by the Windows system, and then process the related window messages for execution. Readers are asked to read the source code for details. This solution is the most perfect C# borderless window solution that the author has compiled so far. If readers have other better solutions and source codes, please provide them so that the author can also apply them.