• 欢迎光临~

wpf 自定义Messagebox时,对话框显示不居中问题

开发技术 开发技术 2022-12-15 次浏览

在自定义Messagebox(有属性Window.SizeToContent="WidthAndHeight")时,对话框显示不居中,经过尝试,应设置如下:

msgBox.WindowStartupLocation = WindowStartupLocation.Manual;

在显示的时候用以下函数进行移动居中显示:

Win32Api.MoveWindow(Hwnd, Convert.ToInt32( (_parent.ActualWidth - this.ActualWidth) / 2 ),
Convert.ToInt32((_parent.ActualHeight - this.ActualHeight) / 2),
Convert.ToInt32(this.ActualWidth), Convert.ToInt32(this.ActualHeight), false);

程序员灯塔
转载请注明原文链接:wpf 自定义Messagebox时,对话框显示不居中问题
喜欢 (0)