SORU
24 Mart 2011, PERŞEMBE


İstemi Windows Forms İletişim

System.Windows.Forms kullanıyorum ama gariptir ki onları oluşturmak için yeteneği yok.

Nasıl javascript olmadan javascript istemi iletişim gibi bir şey alabilir miyim?

MessageBox güzel, ama kullanıcı bir giriş girmek için bir yolu yoktur.

CEVAP
25 Mart 2011, Cuma


Kendi İstemi, iletişim oluşturmanız gerekir. Belki de bunun için bir sınıf oluşturabilirsiniz.

public static class Prompt
{
    public static string ShowDialog(string text, string caption)
    {
        Form prompt = new Form();
        prompt.Width = 500;
        prompt.Height = 150;
        prompt.FormBorderStyle = FormBorderStyle.FixedDialog;
        prompt.Text = caption;
        prompt.StartPosition = FormStartPosition.CenterScreen;
        Label textLabel = new Label() { Left = 50, Top=20, Text=text };
        TextBox textBox = new TextBox() { Left = 50, Top=50, Width=400 };
        Button confirmation = new Button() { Text = "Ok", Left=350, Width=100, Top=70, DialogResult = DialogResult.OK };
        confirmation.Click  = (sender, e) => { prompt.Close(); };
        prompt.Controls.Add(textBox);
        prompt.Controls.Add(confirmation);
        prompt.Controls.Add(textLabel);
        prompt.AcceptButton = confirmation;

        return prompt.ShowDialog() == DialogResult.OK ? textBox.Text : "";
    }
}

Ve arama:

string promptValue = Prompt.ShowDialog("Test", "123");

Güncelleme:

(Eklendi . varsayılan düğme ^strong>anahtar girinve başlangıç odak yoruma dayalı ve another question.

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • BurnedInDotCom

    BurnedInDotC

    3 NİSAN 2010
  • NLthomas21

    NLthomas21

    20 Mayıs 2008
  • PC Learning Zone - Computer Training

    PC Learning

    8 EYLÜL 2006