In my projects (WPF) I use System.Windows.MessageBox to show the user a confirmation dialog for operations that are critical, such as a delete-operation.
My problem is that if I specify as button value MessageBoxButton.YesNo, the user cannot use the escape-key to cancel the operation. IMO this is one of the most annoying things, a program can do, showing a dialog without the possibility to cancel/close the dialog through the escape-key.
Other possibilities are MessageBoxButton.YesNoCancel, but IMO this is confusing because it shows three buttons for only two operations . Or one can use MessageBox.OKCancel, but this is IMO not clear enough. In my dialogs I want to ask the user if her really wants to execute the operation. And for this, a simple ok is not appropriate. A yes (I want) is much better than an ok (go on).
How do you handle this? Is it a non-topic or do you think as I do and have an own MessageBox-implementation or do you know a possibility to extend the System.Windows.MessageBox-class?
Make a custom message box (inheriting from Window) that has placeholders for header/message and confirmation button text. Then you can design a nice, attention-grabbing dialog that will stand out from the hundreds of standard OK/Cancel MessageBoxes a user typically sees. For example, you can use a larger header font similar to the Windows Vista dialogs, or include a custom image.
Then, you could obviously handle the Escape key yourself, and define the default Escape behavior on a per-dialog basis.
Related
I am currently working on a Windows Presentation Foundation app and I need to make use of Message boxes. I want to get few information from user inside Message Box popup.
But they appear always like this:
But I think the actual look of it should be like that:
Does anybody know, why this is, and how to solve it? I tried all everything listed
here
, but nothing worked.
I agree with Keithernet, build your own. Its more of an Input Dialog box. You may want to plan it to create a window, create it with ex: 4 parameters which you could override so you can apply them in the form including
The title,
The prompt you want the user to fill in
optional default button 1 text
optional default button 2 text.
have the input value stored into a public property in the window for the text to be bound to during entry.
If the user clicks the cancel button (or similar), clear the text entry and close the window. If ok button, just close the window.
Then, when you call it with a YourWindow.ShowDialog(), upon return, you can look at the public property for that input text value.
You could even do with a property / flag if the user cancelled directly or not. I have done similar in a couple of my WPF apps.
MessageBox is very limited. Based on your screenshot, you should just create your own child Window with your own XAML so you can get the user input.
You can find sample service implementations/NuGets for this on GitHub. Here is one I've created sometime ago: https://github.com/Dirkster99/MsgBox
Just create your own is an oversimplifying statement in my opinion because this is usually a dialog that you want to show in different parts of the application. Therefore, you have to settle for a software design pattern (I chose a service implementation as suggested here).
Likewise, there are other design decisions that should be taken. I have for instance made sure that the API has a compatible subset of Show API calls with the standard .Net MessageBox to make its application as flexible as possible. I also settled for light and dark themes hoping this will make its application easy in any other theme...
In a recent project I'm planning to allow the user to make certain configuration using a MessageBox with various CheckBoxes. The number of these CheckBoxes is variable and depending on the amount of entries the User made beforehand, so I don't know how big of a Box I need and how many CheckBoxes there will be inside it.
When the user is done checking and unchecking, he will press the "OK" Button and the values should be returned and saved.
Multiple questions to this whole thing:
1. Is this a good/logical way to approach this whole thing? (Having the user make yes/no configurations to an unknown amount of options)
2. How would I create a MessageBox/Pop-Up with an uncertain amount of CheckBoxes?
3. Is there any smart way to design that box, so that it is not to big or to small and fits every option evenly spaced?
Is this a good/logical way to approach this whole thing? (Having the user make yes/no configurations to an unknown amount of options)
Yes, what else could u do if the options to agree with depend on previous settings. So yes this design is ok.
How would I create a MessageBox/Pop-Up with an uncertain amount of CheckBoxes?
In general, i highly suggest to not use the standard MessageBox of the .NET Framework. I would make my own window, and place all in with an yes/no button.
Is there any smart way to design that box, so that it is not to big or to small and fits every option evenly spaced?
Design ur window based on a Grid. Then pick a place that can be ur viewing area. In this place add some kind of stack control ae StackPanel. Then just load dynamically ur controls into this stack and ur done.
I have a winforms app which functions as an alert system, however a lot of the people who will use my program will have multiple screens. The alerts are time sensitive, so ideally I'd like them to appear on all screen, or to be able to specify a screen, so the user is more likely to notice it. By default the message boxes appear on the main screen, and I can't find any info on anything really to do with winforms and different monitors.
The doesn't even have to be a message box, if there is another winform function which can be made to do the same functionality but also multiple screens that'd be great.
On a side note is it possible to close multiple messageboxes from only 1 being accepted?
I think the easiest thing to do is create a custom form rather than using the existing message box. That way you can use the Show method rather than ShowDialog. This would allow you show multiple forms and close all of them from a single response.
As to placing them on multiple screens: You can find the existing screens with System.Windows.Forms.Screen.AllScreens. Each one of those has a Bounds property which will show you what the coordinates and size of each screen is. After you create each custom form you can specify it's Location property to place it on the screen of your choice.
I'm trying to make an application that will test some features of an existing app and I wanted it not to be window-size dependent and not to require focusing the window or etc.
I've already figured out how to get window handles for different controls in the tested app so I can click buttons, enter text to textboxes etc. with Send/Post Message but still got a few unsolved problems.
The first is selecting an item from a pop-up menu that can be triggered by button click (TAdvGlowMenuButton class) or right click somewhere- I can't even see any messages related to it in Spy++ so I have no idea how to do it, is it possible to select an item by name? as I don't have it's id
The second thing is clicking next to something, for example 10 pixels to the right of a button.
I have the button handle so I can get it's size and it's parent but I still don't know how to get it's position inside the parent - any ideas?:)
And also a quick one but I don't believe it is possible - can I somehow get position of a label in the tested app? I can't even see it in Spy++ .
I hope you can help me to find it out ;)
Edit: I forgot about the most important thing:P , I'd like to achieve it with Send/Post Message if only it is possible.
My recommendation would be to abandon the message sending/posting model altogether and instead use UI Automation. Automated testing tools is exactly what the UI Automation APIs were designed for, and they are much more capable than SendMessage/PostMessage.
Yes, I realize that this is exactly the opposite of the answer you were looking for. But you will have no end of trouble getting messages to do what you want. A fair number of them rely on the application having the focus, and it is completely reasonable for your code to make this assumption when you receive e.g. a WM_KEYDOWN message. A testing tool should not flag that as a bug.
I notice you've tagged this question with the C# and .NET tags. In that case, you may be interested to learn that the UI Automation APIs have been wrapped in the .NET Framework.
I need to create a window similar to this:
a window similar to the types of dialog boxes that have been included with windows vista.
but I could not find exactly the same dialog boxes. very similar - it's Credential dialog and Input dialog. In the first case there are differences in the UI, in the second - the number of input fields and the absence of label. How can I make exactly the same window? Sorry for bad English.
You want to create a dialog exactly like the first dialog you've shown, the one used by FluffyApp?
You'll have to create it yourself, by hand. It's not a standard Windows dialog; it's a custom dialog resource provided by the FluffyApp application. It's obviously modeled to look a lot like the standard Windows authentication dialog, which is a good idea—users are already familiar with the native UI and will find your application to be much easier to use if it strongly resembles what they're already accustomed to. I recommend that if you decide to create your own custom dialog that you follow Windows's example as well.
But it's not entirely clear why you need your dialog to look exactly like the one that FluffyApp uses. I'm not really even sure why FluffyApp needed to create a custom dialog! It seems like the standard Windows authentication dialog would be perfectly sufficient. They have the same number of input fields, the UI designers at Microsoft have just replaced labels with cue banners. Not anything to worry about.
Those are standard windows dialogs, but instead of letting the dialog manager draw the text, they use DrawThemeText to draw the text, using one of the themed elements (not sure what, because you have several examples). You can play around with the various parameters to DrawThemeText to come up with something that works.