6

I've been looking for a dialog with a checkbox "Don's show me this dialog again" in C#.

I googled and search a lot, but I just could not find an elegant solution.

The dialog should work as similar as the native MessageBox.Show, but with a new property value (bool value) return to the caller.

Thanks.

Peter Lee
  • 12,931
  • 11
  • 73
  • 100

3 Answers3

8

Vista and Windows 7 applications can use the new TaskDialog features which extend the standard MessageBoxes to support a checkbox at the bottom (along with all sorts of other goodies such as Command Links, custom button text, footers etc).

alt text

Unfortunately from C# you need to do some interop to access this. If you just want the advanced TaskDialogs to target Vista/Windows 7, use the WindowsAPICodePack from http://code.msdn.microsoft.com/WindowsAPICodePack which can handle the interop complexity for you.

If you need to support XP, there is an excellent wrapper that supports the native TaskDialogs on Vista/7 with a WinForms fallback for XP here: http://www.codeproject.com/KB/vista/Vista_TaskDialog_Wrapper.aspx

Ed Andersen
  • 1,158
  • 1
  • 11
  • 14
3

Why don't you create your own. It is a very simple one. Just derive from System.Windows.Forms.Form class and mimic it like the one you want.

Aamir
  • 14,882
  • 6
  • 45
  • 69
  • 1
    It's not as simple as what I thought. MessageBox has different button selections, and icon selections, and I also need them. If I could derive from MessageBox, it's gonna be so good. but we cannot derive MessageBox, since there is no protected or public constructor. – Peter Lee Nov 25 '10 at 07:21
  • @Peter Lee - I had a similar problem in Java. The standard library provides all these nice standard looking message dialog boxes, but as soon as you want to customize the dialog at all, you lose all the standard width/height, icon resources, button placement, button widths, window margins, etc. I had to dig into the low level guts of how Java constructs its dialogs to ensure my custom dialogs followed the standard dialog look and feel. It was not fun, and it left me wanting some standardized way of doing it. At least the Visual Studio GUI designer comes with some good defaults built in. – Mike Clark Nov 25 '10 at 07:44
  • @Peter Lee: It's certainly *possible* to duplicate all of the possible styles that the standard `MessageBox` provides in your own custom dialog. It's more work, but it's something you can reuse over and over. This sample (which recreates a Vista-style TaskDialog where it is not available under previous versions of the OS) is a great example of how you could do this: http://www.codeproject.com/KB/vb/vdialog.aspx – Cody Gray - on strike Nov 25 '10 at 08:20
0

I don't feel there will be a readymade solution as such. For implementing "Do not show me again", you need to persist the information outside the dailog and also create a user profile.

If your infrastructure of persisting the user profile is there, you can simple create a class similar to the messagebox class. You can not derive from messagebox however.

Kangkan
  • 15,267
  • 10
  • 70
  • 113