✅ DialogResult and MessageBox in class (namespace)
Hi, I have a class library and wanted to know if its possible to add a dialog result and message box like the following:
DialogResult result = MessageBox.Show($"The maximum hours has been/will be reached for this employee {employee.GetName()}'s contract. Do you want to continue?", "Confirmation", MessageBoxButtons.OKCancel);
inside a class library (namespace)5 Replies
Yes, but then you are dependant of either WinAPI or Forms
Ye in this case the method that has this will be called on a WindowsForm
another issue that rises up is when I add this with all the right code it says im missing a reference so I add the system.windows.forms and then I get an error on it saying im missing an assembly reference
https://learn.microsoft.com/en-us/dotnet/core/project-sdk/msbuild-props-desktop#net-5-and-later-versions
If you're on .NET 5 and later version you can just simply add to csproj
<UseWindowsForms>true</UseWindowsForms>
Or you can implement the WinAPI function yourself. https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-messageboxunderstood ty
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.