Replacement for yes/no/cancel MessageBox (C#) - c#

I am looking for a decent replacement for the standard windows YES/NO or YES/NO/CANCEL MessageBox.
I have often seen these standard dialogs misused in ways such as: "To save in plain text answer YES, or to save in html answer NO". Obviously, the text should read "Save As: and the "buttons should be labeled "Text" and "HTML". It is not a yes/no question that is being asked, and although it could be phrased that way, it would not be easy to read and understand.
Microsoft gives no way to change the text on the buttons. There is no fast/simple way to build a replacement from scratch... as evidenced by the number of applications using the awkward style mentioned above.
Is there any free C# replacement dialog or MessageBox out there that lets you at least:
- specify the number of buttons
- specify the text to appear on each button
- specify the default button
I have looked and have been unable to find one.
(I would build one myself, but I am not familiar enough with all the behaviors that a fully functional control should have, since I only need/use/know a small subset. Two examples I don't use: themes and internationalization. I need something that my coworkers will also want to use.)

Check out Dissecting the MessageBox on CodeProject. The project is a bit dated, but it's pretty much exactly what you're looking for and it shouldn't take much to update it.

Depending on your target platform, a task dialog may be a good way of doing this. There is a .NET wrapper for task dialogs in the Windows API Code Pack. However these are provided only in Windows Vista and above, not in XP or 2003.

Frankly, it is not that difficult to create such a Messagebox yourself, we have such a thing working in the current app we are developing.
What you need is a FlowLayout for the buttons that will auto-align any buttons you create. Our API then has something like (params Tuple<string,DialogResult>[] buttons)
Tuple is a helper class that contains two values. The string is the Text of the button, the Dialogresult is the one our messagebox returns when the button with said text is clicked.

I agree with Frank. It wouldn't be too difficult to create your own generic form that handles this for you. Without getting into code, the form should do the following
1) Have a property to set the message you want to show to the user.
2) Have a method for adding buttons, with 2 arguments, one for the button text, and one for the dialog result
3) When the form is displayed, it should be in modal dialog mode so that the rest of the application is inactive while until one of the options is clicked.
So, to create a Save As/Don't Save/Cancel, you would add 3 buttons in step 2, all with the appropriate button text and dialog result.
Using Flow layout, you should be able to get it to display properly regardless of the size of the message, or the number of buttons.

Related

Can Windows CE buttons sport an image?

Due to real estate/space constraints, I want to put a Printer icon on a button rather than the text "Print"
Yet I see no obvious way to do that (No "Image" property or so on the button).
Is it possible (without jumping sideways through flaming hoops)?
The standard button does not support images, no. You have to create a custom control. This was such a common request that Microsoft released an article on MSDN showing how to do it.
I'd argue that they would have been better served just creating the support in the Button (after all, they had several releases after that article) but they didn't ask me.

Reproduce the Microsoft Registry Editor "Edit Binary Value" Window in VS 2010 C# .NET Windows Forms

I am trying to reproduce a window from the Microsoft built-in Registry Editor. The window is the one which is opened when you select "Modify Binary Data..." from the context-menu when a value is clicked.
The goal is to make an identical(!) window in my .NET C# application using Windows Forms.
The problem is the textBox displayed in the window which contains the binary data. I have tried using a RichTextBox, but it isn't as simple as it seems to be especially when it comes to editing data and the behaviour of this textBox.
So I have 2 questions:
How to achieve an identical textBox in C# using Windows Forms? Maybe you know some other ways to reproduce this textBox?
I also need the font name used in this textBox, I couldn't find it :)
Thanks!
I can think of two ways you can approach this. The first is a DataGrid, painstakingly styled to have transparent grid lines and exact margins between columns, with filters to enforce hex digits only. All this, set alongside a richtextbox for the ASCII display, with your code synchronizing the selection between them.
Alternately, you can replace the DataGrid with a collection of TextBoxes, again styled for invisible borders, automatically adding new textboxes to the collection when the user adds more data.
All in all, it seems like an awful lot of work, especially in WinForms - WPF might make this a bit easier, especially the styling, but still a lot of work.
Regarding the name of that control - I tried using Spy++ to sniff it out, and it seems it's registered as a Window Class named "HEX", but I'm not sure that will really get you somewhere:
Here is an open source project containing a hex editor control for Winforms, looking at least very similar:
http://sourceforge.net/projects/hexbox/
I guess you can modify it accordingly to your requirements. But beware, the source code for the control is ~6000 lines of code (including more than a dozen utility classes). It inherits directly from "Control" and does all the text display using GDI+ (so no modified DataGrid or RichTextBox).

Getting selected item in active window

I am using C# to develop an application that works with the clipboard, an was wondering if its possible to get the contents of what the user has selected in the current window, no matter what window it is (e.g. could be FireFox, notepad, etc.).
I'm not sure if you're going to be able to get a general solution for this problem. Take a look at this link;
http://www.eggheadcafe.com/software/aspnet/33899121/get-selected-text-of-active-window-.aspx
The author of this post reports that their solution works in Notepad, but not in Wordpad or Word. I don't know much about this area, but I would guess that this means there are various means through which text selection is implemented - even within Windows.
I think this also extends to Control-C, not just text selection. I believe that there are different ways of handling the copy command depending on the context in which it's used.
For example, if you press Control-C on a dialog box in Windows, it will copy the text without you have to select it manually.
Hopefully the link above is of some use to you. This seems like an interesting problem to overcome.
Edit:
Spoke too soon - just found this link;
http://social.msdn.microsoft.com/Forums/en/winformsapplications/thread/1dc356e6-9441-44de-9eda-247003fa6ef5
Looks like this is exactly what you're after - hope that works.
If something was only selected, it won't appear in the Clipboard. But if user copied some object that he had previously selected, then, yes, it will be in the Clipboard.

How to build a Windows Forms email-aware text box?

I'm building a C# client app that allows a user to communicate with one or more existing users in a system via an email-like metaphor. I'd like to present the user with a text entry box that auto-completes on known email addresses, and allows multiple delimiter-separated addresses to be entered. Ideally, I'd also like the email addresses to turn into structured controls once they've been entered and recognized. Basically, I'm modeling the UI interaction for adding users after Facebook's model.
Are there any Windows Forms controls out there with the ability to do something like this? Is there any well-established terminology for a hybrid textbox / control list box (no, not a ComboBox) or something that I should be searching for?
Thanks,
-Patrick
I have had good luck in the past creating composite user-controls to provide specific functionality using native .NET Winforms controls. It works pretty good as long as there aren't too many of them, in which case things start to slow down.
In you case, and this is just off the top of my head, but, perhaps you could take a FlowLayoutPanel, a Button, and a Textbox which supports auto-complete and put these together to create a control that would provide the functionality you are looking for.
If there are no addresses selected in the control (e.g. in a List<string>), then the container (FlowLayoutPanel) would only display the TextBox. Once the user selected an entry, the control would automatically create a Button with the appropriate caption and insert it to the left in the FlowLayoutPanel. If the user removes an address he/she has already selected, simply remove its representation (the button) from the FlowLayoutPanel, and the TextBox can resize accordingly. There may be issues with getting the TextBox to fill up the remaining space (I can't remember how to do that), but you get the idea. The container does not have to be FlowLayoutPanel - you could use a Panel with Docked controls, or even a TableLayoutPanel for this.
A design as I described would allow the user to delete the address by clicking on the button. However, without some other visual cues, that isn't very intuitive or user-friendly, so I would consider making the "Button" be another composite control which contains a "prettied-up" label along with an tiny delete Button (X) to the right. For this you could use a Panel control and dock the X button to the right, and fill the Label on the left. You would provide public properties here as needed to control the text and provide an event handler or callback for the delete functionality.
Once the visual stuff is working, all that is left is to provide the appropriate Properties and Methods on the main control to allow it to interact as needed with outside code.
As a simple, "poor man's", implementation you could take a look at the AutoComplete* properties of the TextBox control. You could dynamically populate the AutoCompleteSource with your known addresses and when an entry matches, add to a separate, list-style control of your choice.
See this SO article for some interesting code snippets related to your question, and my suggested workaround.
Beyond the built-in AUtoComplete properties you're probably looking at having to purchase a 3rd party control from a tools vendor.
I've not seen anything like that before in WinForms. In WPF it would be another matter - if you can use that, maybe consider hosting a WPF control within your WinForms application instead?
I think you're trying to do something similar to this codeproject article: AutoComplete TextBox
And since you mention WPF in a comment, you also have this article: WPF AutoComplete Folder TextBox (should be easy enough to cut out the folder bit of the article I'd thought).
Well, there isn't such a control. If I were you, I'd create 2 textboxes to do the job. See, a normal textbox can easily be configured for autocomplete from a list, even dynamically; however, it accepts only one entry at a time.
So, I suggest you dedicate one textbox for autocomplete, and one for the addresses. So, whenever there is a qualified email address in the first textbox, and you click enter, the address gets added to the address textbox, and automatically add delimitation.
Then you need to handle the addresses in the address textbox as objects instead of characters. Code it in a way that when a user tries to delete a character in an address, the whole address is deleted.
This is the workaround I can think of. I'll help with the code if you give it a try.

Non intrusive 'live' help system

I'm searching a C# component or code snipped that does something like that:
I want to inform new users about the most important program functions if he opens a new window for example.
It should be a box showing text (formated if possible) that is of course not modal and has some mechanism to 'go out of the way' if the user enters the textbox area. So that he can access what's underneath it. Alternativly the window could also stick to the border of the window, but there needs to be a way that this also works if the window is maximized.
So I want to present him with a short introduction of what he can do in every corner of my app most painlessly.
Thank you!
I use a "bar" at the top of every window to display some information about the current window/dialog.
Use tooltips. They can be programmatically controlled, and you can have them appear at will. You'll need to add the functionality to your app to keep track of what tooltips have been shown to the user already.
You can add a "balloon" style by setting the IsBalloon property to true.
You can also replace them with smaller descriptions for when the user wants to hover over the control and have them displayed again.
I'm already using tooltips heavily. However, they aren't very practical when displaying bigger amounts of data and they are bound to specific user actions.
Have you considered having a contextual menu for each form / page which contains links to Adobe Captivate style presentations for each available task? That way the user can investigate an example of how to achieve a task relating to what they are trying to achieve from within the application / site.
This approach would require a good deal of maintenance and management if your code changes regularly but coordinating it with a training department can provide rich help features in your application.
See http://www.adobe.com/products/captivate/ for more information.

Categories