.Net Core WinForm makes MessageBox center control

background

The .net framework winform mentioned in the previous blog can realize the centered display of MessageBox by defining a new class, but this class has no effect in .net core winform. There is no way. This blog will customize a .net core framework Substitute the MessageBox under the class XWQMessageBox

the code

I have uploaded the code of this project to Code Cloud and Nuget. If you are interested, you can enter this link to view the source code

Rewrite the MessageBox to realize the positioning bullet box: .net core creates a new Form to realize the MessageBox positioning bullet box, and the original one can only appear in the center of the screen

If you just need to use it in the .net core winform project, you can right-click on [Dependencies] to enter the Nuget package search. The keyword of this package is XWQControls, just select the latest version to install.

use

Refer to the namespace after installing the library

using XWQControls;

Called in business code

XWQMessageBox messagebox = new(this);
var result = messagebox.Show("你最近还好吗?", XWQMessageBoxIcon.Question, XWQMessageBoxButtons.YesNo);

Effect

 

As you can see, the popup is always displayed in the center of our main form.

If we want it to be displayed in the center of a control, we only need to pass the control into the parameter of the constructor.

other

mistake

 

information

 

 

warn

 

 

Guess you like

Origin blog.csdn.net/qq_36694133/article/details/130228581