Best practice for visual validation of textbox control data - c#

I think I want to show some kind of confirmation tick type thing by a textbox - (it's traditional windows forms stuff, not WPF) - but not sure if it's a bit naff. I would like some kind of slick way of showing that a value is incorrect or valid after some tests have been done i.e. a web service is valid with that name or SMTP server seems to running with that name etc.
Should there be even any visual stuff going on or should a simple message on a status strip at the bottom of the window be enough.....
Any ideas are most welcome.
PS - if the tick thing is a good idea what's the best way to implement this with a textbox control.
Example....

You could make a custom control which contains both a textbox and an imagebox. The custom control could raise a validation event which checks the text and then sets the imagebox graphic based on whether or not the validation passed (or sets it blank if there is not text in the textbox).
The .net centric way would probably be to implement validation providers and some type of custom error provider, like what Henrik is mentioning.

You can use ErrorProvider to show a little exclamation mark when the entered value is incorrect.

you can use the ErrorProviderComponent in order to show notifications. The naming of that component is slightly unfortunate in my mind but you can easily change the icon to show other things than the typical red error "X".

Related

Get new Messagebox style - WPF

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...

Selecting an item from pop-up menu

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.

How to develop my own .NET controls?

I've been struggling for a long time with basic controls that Windows Forms offers to developers, but... right now, I am developing an application that requires more advanced control than normal "TextBox".
Since, at this time, my application is about memory management, I have to show in the form, the process memory in bytes (or other type of data) to the user, giving it the ability to modify it as he wants.
The problem comes here, because... if I show the data in a TextBox, it only allow me to display the data in read-only text because if I let the user modify the textbox directly, it will be very messy and unaesthetic.
I was reviewing some projects on SourceForge about C# and the handling of hexadecimal data, and i found a good project, called Be.HexEditor, which has a control developed and designed by its creators, but in GDI+.
The control is called HexBox, and that's just what I need to get.
Do any of you know how to develop a control like this?... I would greatly facilitate things. What kind of manuals/books should I read to learn this kind of development? I ask this because I ignore everything about GDI+.
Or... is there other way for do it?
I would use a textbox to show to the user the current value and another textbox to enter the desired value (maybe a slider will work better).
I think you'll find it's GDI+ that you have to learn
http://www.amazon.co.uk/GDI-Programming-Creating-Controls-Programmer/dp/1861006314
You may still be able to write controls in WPF and then include them somehow into your winforms app, but if you need to push pixels GDI+ is the only way.

CF UI design - How best to display validation failures

I am thinking of using a messagebox to display validation failure messages in the windows mobile app. that I am currently working on. My thinking here is that there is such limited screen realestate that I'd struggle to dedicate an area on the main form specifically for displaying these validation failures. I am a little concerned as to the usability aspect as the user will be force to close the validation messagebox after a validation failure.
Does anyone have any thoughts on this approach or experience that would suggest that there is a better way of doing this?
I know the ErrorProvider is not available within the compact framework. But maybe this would be a starting point on how to do it.
Like the ErrorProvider i would show a simple icon next to the input box that shows something is wrong. Due to the fact, that you don't have a mouse cursor to hover over it, i would in case of clicking on that icon show a concrete error message in a text box docked at the bottom that will hide again if you simply click it.
So the user gets a hint that something is wrong (maybe he already knows what) and can hit on the icon to get a clue. While the clue is showing he can still insert something within the form (he can't see everything, but currently he is only interested in this single box) and one click further (on the appeared text box) he gets back to full screen.
At a last step the box should maybe also automatically disappear if the focus is changed to another input box or the error is fixed.
I would show a message at the top of the screen (as browsers do) that summarizes the errors encountered, in the likes of "X required fields where not filled". And then a more detailed error closer to each of the fields that could not be validated.
That way, the information about the mistakes is still visible while the user is correcting them.

c# a nice notice box

Is there any code for a nice notice box (Even a dll would be fine)
Like the one kaspersky antivirus shows? Because in my script I use a lot of
message box and the end-user start to complain that they need to click okay every time.
You can look at this exemple on CodeProject.
I suggest you create a custom control, which inherits from the message box and then you design it as per your liking.
Maybe not an actual answer to your question, but if you users complain about the number of message boxes they need to "click away" (like you mention yourself), are you perhaps using them too much or for the wrong reasons?
Perhaps other ways of showing messages are more approriate in some cases, like a status bar, a dialog with a message log, or different way of structuring dialogs/workflows in your application?

Categories

Resources