views:

80

answers:

4

Hello, Could I add some custom control to the standard Message Box for read input value, for example text fields for user name and password, or I should create custom winform with "Ok,Cancel" buttons and text fields? Thanks.

A: 

Create your own.

Creating a custom modal (or otherwise) input dialog isn't all that difficult and you can built the extensibility you need for reuse.

public class ValueHolder {
    public string SomeInput { get; set; }
    public DialogResult Result { get; set; }
}

public class GimmeValues : Form {
    //... HAS A TEXTBOX and Okay Buttons...

    private GimmeValues() {
    }

    public static ValueHolder GetInput(IWin32Window owner) {
        using (GimmeValues values = new GimmeValues()) {
            DialogResult result = values.ShowDialog(owner);
            return new ValueHolder { 
                SomeInput = values.Textbox1.Text,
                Result = result
            };
        }
    }
}

Okay I just wrote that all in this editor so forgive any syntax mistakes.
You could do something like the above but clean it up a little, add the extensibility you need (in terms of buttons and inputs showing that you need etc)... then just call it like ValueHolder value = GimmeValues.GetInput(this); where this would represent an IWin32Window...

The resulting value of value would be the selected nonsense and you could perform your logic..

if(value.Result == DialogResult.OK && !string.IsNullOrEmpty(value.SomeInput)){
    //TODO: Place logic....
}
Quintin Robinson
And Is there no any solution for modify standard dialog?
jitm
@jitm Not in Winforms.
Quintin Robinson
Thanks a lot ....
jitm
"Gimme"... yuk!
CesarGon
@CesarGon HAHAHA, yeah example names are meaningless to me, I just don't always use fu/bar/biz/baz.
Quintin Robinson
@Quintin: :-) Well, I think that good, understandable names are important, especially when trying to explain things to people whose mother tongue might not be English. Using abbreviations, contractions and other forms of wordplay are "worst practices".
CesarGon
@CesarGon exactly, so if someone is primarily of another language, the already useless name as written in the native language conveys perfectly, continuing to be meaningless. Just as well, the naming is furthermore meaningless (the derived form name in this case) as long as the concept and intent is understood.
Quintin Robinson
/me rolls his eyes.
CesarGon
@CesarGon ?.. I do not understand, what are you rolling your eyes at?
Quintin Robinson
@Quintin: Sorry. I guess I should explain myself, but I tend to assume that others are aware of best practices all the time. Your reasoning is flawed. My mother tongue is not English, and I can assure you that abbreviations, contractions and other forms of wordplay in English make examples much harder to understand for me. And for my colleagues. Beyond personal experience, this is a well-acknowledged fact; some RFCs have even captured it as directives (e.g. RFC 1178; see section "Avoid alternate spellings"). That's why I say that "gimme" is a no-no.
CesarGon
@CesarGon I appreciate the explanation, I requested it because of the snide "rolls his eyes" remark that you made. I am versed in best practices and an advocate. However I think that you might be investing too much time and depth into the example given in context. This code, as stated, is not intended to be used as-is and certainly isn't boilerplate for any future standard. If you have a problem understanding from a conceptual standpoint (It is extremely straightforward IMHO) then you have the capability to modify it rather then criticize in a fashion that isn't beneficial to the community.
Quintin Robinson
@Quintin: Thanks for your understanding. My initial remark ("yuk") was intended as a joke, not as a frontal criticism to your code. Your code is fine. Please take it as that. :-)
CesarGon
@CesarGon Indeed, I do not make it a habit to take criticism of a nonsensical or constructive nature personally, especially some as flamboyant as "yuk". I found it humorous and my laughing reply was sincere. I think we are on the same page. =)
Quintin Robinson
@Quintin: We are!
CesarGon
+4  A: 

You will need to create a custom WinForm to do this. You can make it work the same way as a MessageBox by returning a DialogResult on the Show method.

rein
If you need a modal dialog use Form.ShowDialog() instead of Form.Show().
Nathan Taylor
A: 

You'll have to create a custom form to handle that.

If you want the Form to behave like MessageBox, just create a static Show() method on your Form that creates an instance and shows the box to the user. That static method can also handle returning the values you are interested in from your custom form (much like DialogResult).

Justin Niessner
A: 

you can use the Interaction.InputBox method wich is located in the Microsoft.VisualBasic namespace

try this

 Microsoft.VisualBasic.Interaction.InputBox("Entre a Value Here", "Title", "Your Default Text",200,100);
RRUZ
+1. The InputBox 'feature' has been in VB since I started programming in that language some 10 years ago.
Alex Essilfie