我正在将.NET4类库转换为.NET标准2.0,以便可以从.NET4应用程序和.NET6应用程序调用它.这些应用程序仅适用于Windows.
我遇到的一个转换问题是,类库调用了几个WinForms MessageBox.Show()来显示简短的警告消息,并使用OK按钮关闭窗口.
由于.NET Standard 2.0不支持WinForms,复制此功能的最佳方式是什么? (显示一个简单的弹出窗口,其中包含一个短消息字符串和一个确定按钮)
=
编辑:感谢您的回答.PInvoke工作得很完美.这就是我最终学到的课程:
internal class SimpleMsgBox
{
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
static extern int MessageBox(int hWnd, String text, String caption, uint type);
internal static void Show(string message, string title)
{
MessageBox(0, message, title, 0);
}
}
然后可以这样命名:
SimpleMsgBox.Show("an error occurred", "alert");