InputDialog ของ VB.net รุ่น C # คืออะไร?


คำตอบ:


233

เพิ่มการอ้างอิงไปMicrosoft.VisualBasic, InputBoxอยู่ในMicrosoft.VisualBasic.Interactionnamespace:

using Microsoft.VisualBasic;
string input = Interaction.InputBox("Prompt", "Title", "Default", x_coordinate, y_coordinate);

เฉพาะอาร์กิวเมนต์แรกสำหรับpromptคำสั่งบังคับเท่านั้น


จะทำอย่างไรถ้าฉันต้องการรับรหัสผ่านจากผู้ใช้
hims056

3
@ hims056 InputBoxไม่รองรับอินพุตที่ถูกปิดบังไว้ คุณจะต้องม้วนแบบฟอร์มการป้อนข้อมูลของคุณเอง
Ozgur Ozcitak

4
เพียงนำเข้าusing Microsoft.VisualBasicเพื่อให้คุณเขียนInteraction.InputBox()
Edward Karak

กล่องป้อนข้อมูล VB สามารถให้ค่าที่จะเติมลงไปในที่นั่นได้ตั้งแต่ต้นหรือไม่ (แก้ไข) ไม่เป็นไรนั่นเป็น "ค่าเริ่มต้น" ที่ฉันเห็น
Nyerguds

3
ฉันค้นหาสิ่งนี้อย่างน้อย 10 ครั้ง ส่งผลให้คำตอบนี้เสมอ จะโหวตอีกครั้งถ้าฉันทำได้ ขอบคุณ!
C4d

108

หากต้องการสรุป:

  • มีใครใน C #
  • คุณสามารถใช้กล่องโต้ตอบจาก Visual Basic โดยเพิ่มการอ้างอิงไปยัง Microsoft.VisualBasic:

    1. ในโซลูชัน Explorerคลิกขวาที่โฟลเดอร์อ้างอิง
    2. เลือกเพิ่มการอ้างอิง ...
    3. ในแท็บ. NET (ในเวอร์ชัน Visual Studio verion ใหม่ - แท็บAssembly ) - เลือกMicrosoft.VisualBasic
    4. คลิกที่ตกลง

จากนั้นคุณสามารถใช้รหัสที่กล่าวถึงก่อนหน้านี้:

string input = Microsoft.VisualBasic.Interaction.InputBox("Prompt", "Title", "Default", 0, 0);
  • เขียน InputBox ของคุณเอง
  • การใช้งานของคนอื่น

ที่กล่าวว่าฉันขอแนะนำให้คุณพิจารณาความต้องการของกล่องใส่ในตอนแรก กล่องโต้ตอบไม่ใช่วิธีที่ดีที่สุดในการทำสิ่งต่าง ๆ และบางครั้งพวกเขาก็ทำอันตรายมากกว่าดี - แต่ขึ้นอยู่กับสถานการณ์เฉพาะ


คุณสามารถใช้กล่องโต้ตอบจาก C # โดยเพิ่มการอ้างอิงนั้นด้วย
Joel Coehoorn

3
ใช่พวกเขาเป็น แต่สำหรับฉันแล้วดูเหมือนว่าในกรณีส่วนใหญ่รหัสการจัดส่งไม่ถูกต้อง
Tomas Sedovic

+1 สำหรับลิงค์โทมัสที่โพสต์ อันนี้ดีกว่า InputBox เสมือนจริง
Joe.wang

ยังดีกว่าการใช้ / ระบบย่อย: คอนโซล ... บางครั้งคุณต้องการการโต้ตอบกับผู้ใช้น้อยมากและจากนั้นคุณสามารถใช้พวกเขาแทนที่จะมี 90% ของรหัสของคุณสำหรับ UI
Nulano

ผมเลือก "ใช้คนอื่นเป็นตัวเลือก" และผมมีความสุขกับผลที่ได้จากนี้: reflectionit.nl/blog/2003/c-inputbox เหตุผลที่ฉันเลือกว่าสิ่งหนึ่งไม่มีค่าขนาด / ตำแหน่งฮาร์ดโค้ด นอกจากนี้ยังมีแนวโน้มเป็นcsharp-examples.net/inputbox-class ทั้งสองรายการแรกมีการตรวจสอบความถูกต้องของข้อความที่ป้อน คำตอบที่ยอมรับสำหรับstackoverflow.com/questions/5427020/ …ก็ดูดี แต่ไม่รวมถึงคุณสมบัติการตรวจสอบความถูกต้องของอินพุต
Developer63

106

การสร้างไดอะล็อกบ็อกซ์แบบไดนามิก คุณสามารถปรับแต่งให้เข้ากับรสนิยมของคุณ

หมายเหตุไม่มีการอ้างอิงภายนอกที่นี่ยกเว้น winform

private static DialogResult ShowInputDialog(ref string input)
    {
        System.Drawing.Size size = new System.Drawing.Size(200, 70);
        Form inputBox = new Form();

        inputBox.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
        inputBox.ClientSize = size;
        inputBox.Text = "Name";

        System.Windows.Forms.TextBox textBox = new TextBox();
        textBox.Size = new System.Drawing.Size(size.Width - 10, 23);
        textBox.Location = new System.Drawing.Point(5, 5);
        textBox.Text = input;
        inputBox.Controls.Add(textBox);

        Button okButton = new Button();
        okButton.DialogResult = System.Windows.Forms.DialogResult.OK;
        okButton.Name = "okButton";
        okButton.Size = new System.Drawing.Size(75, 23);
        okButton.Text = "&OK";
        okButton.Location = new System.Drawing.Point(size.Width - 80 - 80, 39);
        inputBox.Controls.Add(okButton);

        Button cancelButton = new Button();
        cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
        cancelButton.Name = "cancelButton";
        cancelButton.Size = new System.Drawing.Size(75, 23);
        cancelButton.Text = "&Cancel";
        cancelButton.Location = new System.Drawing.Point(size.Width - 80, 39);
        inputBox.Controls.Add(cancelButton);

        inputBox.AcceptButton = okButton;
        inputBox.CancelButton = cancelButton; 

        DialogResult result = inputBox.ShowDialog();
        input = textBox.Text;
        return result;
    }

การใช้

string input="hede";
ShowInputDialog(ref input);

3
ตกลงง่ายมากฉันพบว่า: inputBox.AcceptButton = okButton; inputBox.CancelButton = cancelButton;
FIV

1
ทำงาน! ดีกว่าโซลูชัน VB ขอบคุณ beehorf!
Filipe YaBa Polido

8
inputBox.StartPosition = FormStartPosition.CenterParent; จะกึ่งกลางของกล่องโต้ตอบบนหน้าต่างหลัก
Andrew Cash

2
+1 สำหรับการเขียนรหัสของคุณเองและแบ่งปันได้ที่นี่! คนอื่นขี้เกียจเกินไปที่จะทำเช่นนั้นและต้องการแค่คะแนนฟรีง่ายๆ
Kairan

1
แบบฟอร์มนี้ไม่ปรากฏให้เห็นเมื่อใช้ในการทดสอบหน่วยโพสต์นี้จะเป็นประโยชน์ stackoverflow.com/questions/1218517/…
Ray Cheng

9

ไม่มีเลย หากคุณต้องการใช้ VB InputBox จริงๆใน C # คุณสามารถ เพียงเพิ่มการอ้างอิงถึง Microsoft.VisualBasic.dll แล้วคุณจะพบว่าที่นั่น

แต่ฉันอยากจะแนะนำว่าอย่าใช้มัน มันน่าเกลียดและล้าสมัย IMO


18
ฉันคิดว่าคุณใจดีเกินไป มันน่าเกลียดและล้าสมัยไปกว่านี้อีกแล้ว!
BlackWasp

3
ไม่สามารถระบุได้ว่าจริงๆแล้วcancelจากempty input stringข้อผิดพลาด IMO
Joe.wang

6

ไม่เพียง แต่คุณควรเพิ่ม Microsoft.VisualBasic ลงในรายการอ้างอิงของคุณสำหรับโครงการ แต่คุณควรประกาศ 'ใช้ Microsoft.VisualBasic;' ดังนั้นคุณเพียงแค่ต้องใช้ 'Interaction.Inputbox ("... ")' แทน Microsoft.VisualBasic.Interaction.Inputbox


3
หากคุณใช้เพียงครั้งเดียวสิ่งนี้จะเพิ่มความยุ่งเหยิงหาก OP ตัดสินใจว่าพวกเขาไม่ต้องการ InputBox อีก นอกจากนี้ควรเป็นความคิดเห็น
BalinKingOfMoria คืนเงินให้ CM อีกครั้งใน

5

ส่งคืนสตริงที่ผู้ใช้ป้อน สตริงว่างถ้าพวกเขาตีCancel:

    public static String InputBox(String caption, String prompt, String defaultText)
    {
        String localInputText = defaultText;
        if (InputQuery(caption, prompt, ref localInputText))
        {
            return localInputText;
        }
        else
        {
            return "";
        }
    }

ส่งกลับค่าStringเป็นพารามิเตอร์การอ้างอิงส่งคืนtrueหากพวกเขาตีOKหรือfalseถ้าพวกเขาตีCancel:

    public static Boolean InputQuery(String caption, String prompt, ref String value)
    {
        Form form;
        form = new Form();
        form.AutoScaleMode = AutoScaleMode.Font;
        form.Font = SystemFonts.IconTitleFont;

        SizeF dialogUnits;
        dialogUnits = form.AutoScaleDimensions;

        form.FormBorderStyle = FormBorderStyle.FixedDialog;
        form.MinimizeBox = false;
        form.MaximizeBox = false;
        form.Text = caption;

        form.ClientSize = new Size(
                    Toolkit.MulDiv(180, dialogUnits.Width, 4),
                    Toolkit.MulDiv(63, dialogUnits.Height, 8));

        form.StartPosition = FormStartPosition.CenterScreen;

        System.Windows.Forms.Label lblPrompt;
        lblPrompt = new System.Windows.Forms.Label();
        lblPrompt.Parent = form;
        lblPrompt.AutoSize = true;
        lblPrompt.Left = Toolkit.MulDiv(8, dialogUnits.Width, 4);
        lblPrompt.Top = Toolkit.MulDiv(8, dialogUnits.Height, 8);
        lblPrompt.Text = prompt;

        System.Windows.Forms.TextBox edInput;
        edInput = new System.Windows.Forms.TextBox();
        edInput.Parent = form;
        edInput.Left = lblPrompt.Left;
        edInput.Top = Toolkit.MulDiv(19, dialogUnits.Height, 8);
        edInput.Width = Toolkit.MulDiv(164, dialogUnits.Width, 4);
        edInput.Text = value;
        edInput.SelectAll();


        int buttonTop = Toolkit.MulDiv(41, dialogUnits.Height, 8);
        //Command buttons should be 50x14 dlus
        Size buttonSize = Toolkit.ScaleSize(new Size(50, 14), dialogUnits.Width / 4, dialogUnits.Height / 8);

        System.Windows.Forms.Button bbOk = new System.Windows.Forms.Button();
        bbOk.Parent = form;
        bbOk.Text = "OK";
        bbOk.DialogResult = DialogResult.OK;
        form.AcceptButton = bbOk;
        bbOk.Location = new Point(Toolkit.MulDiv(38, dialogUnits.Width, 4), buttonTop);
        bbOk.Size = buttonSize;

        System.Windows.Forms.Button bbCancel = new System.Windows.Forms.Button();
        bbCancel.Parent = form;
        bbCancel.Text = "Cancel";
        bbCancel.DialogResult = DialogResult.Cancel;
        form.CancelButton = bbCancel;
        bbCancel.Location = new Point(Toolkit.MulDiv(92, dialogUnits.Width, 4), buttonTop);
        bbCancel.Size = buttonSize;

        if (form.ShowDialog() == DialogResult.OK)
        {
            value = edInput.Text;
            return true;
        }
        else
        {
            return false;
        }
    }

    /// <summary>
    /// Multiplies two 32-bit values and then divides the 64-bit result by a 
    /// third 32-bit value. The final result is rounded to the nearest integer.
    /// </summary>
    public static int MulDiv(int nNumber, int nNumerator, int nDenominator)
    {
        return (int)Math.Round((float)nNumber * nNumerator / nDenominator);
    }

หมายเหตุ : รหัสใด ๆ จะถูกปล่อยลงในโดเมนสาธารณะ ไม่ต้องระบุแหล่งที่มา


MulDiv คงที่สาธารณะแบบคงที่ (จำนวน int, ตัวเศษ int, ตัวส่วน int) {return (int) จำนวน (* ยาว) * ตัวเศษ + (ตัวส่วน >> 1)) / ตัวหาร); }
Peter Kalef 'DidiSoft

คือToolkitอะไร
Markus L

1
@markusL Toolkit MulDivเป็นชั้นเรียนของฉันที่มีการดำเนินการของ MulDivคุณสามารถเห็นความคิดเห็นของปีเตอร์สำหรับการใช้ตัวอย่างของ
Ian Boyd

4

เพิ่มการอ้างอิงถึงMicrosoft.VisualBasicและใช้ฟังก์ชันนี้:

string response =  Microsoft.VisualBasic.Interaction.InputBox("What's 1+1?", "Title", "2", 0, 0);

2 หมายเลขสุดท้ายคือตำแหน่ง X / Y เพื่อแสดงกล่องโต้ตอบการป้อนข้อมูล


3

คุณหมายถึง InputBox หรือเปล่า เพียงมองในเนมสเปซ Microsoft.VisualBasic

C # และ VB.Net แบ่งปันไลบรารี่ทั่วไป หากภาษาหนึ่งสามารถใช้ภาษาอื่นได้


2

โดยไม่ต้องเพิ่มการอ้างอิงถึง Microsoft.VisualBasic:

// "dynamic" requires reference to Microsoft.CSharp
Type tScriptControl = Type.GetTypeFromProgID("ScriptControl");
dynamic oSC = Activator.CreateInstance(tScriptControl);

oSC.Language = "VBScript";
string sFunc = @"Function InBox(prompt, title, default) 
InBox = InputBox(prompt, title, default)    
End Function
";
oSC.AddCode(sFunc);
dynamic Ret = oSC.Run("InBox", "メッセージ", "タイトル", "初期値");

ดูสิ่งเหล่านี้สำหรับข้อมูลเพิ่มเติม:
ScriptControl
MsgBox ใน JScript
Input และ MsgBox ใน JScript

.NET 2.0:

string sFunc = @"Function InBox(prompt, title, default) 
InBox = InputBox(prompt, title, default)    
End Function
";

Type tScriptControl = Type.GetTypeFromProgID("ScriptControl");
object oSC = Activator.CreateInstance(tScriptControl);

// https://github.com/mono/mono/blob/master/mcs/class/corlib/System/MonoType.cs
// System.Reflection.PropertyInfo pi = tScriptControl.GetProperty("Language", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.CreateInstance| System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.SetProperty | System.Reflection.BindingFlags.IgnoreCase);
// pi.SetValue(oSC, "VBScript", null);

tScriptControl.InvokeMember("Language", System.Reflection.BindingFlags.SetProperty, null, oSC, new object[] { "VBScript" });
tScriptControl.InvokeMember("AddCode", System.Reflection.BindingFlags.InvokeMethod, null, oSC, new object[] { sFunc });
object ret = tScriptControl.InvokeMember("Run", System.Reflection.BindingFlags.InvokeMethod, null, oSC, new object[] { "InBox", "メッセージ", "タイトル", "初期値" });
Console.WriteLine(ret);

2

ฉันสามารถทำสิ่งนี้ได้ด้วยการเขียนโค้ดของตัวเอง ฉันไม่ชอบที่จะขยายและพึ่งพาห้องสมุดขนาดใหญ่เพื่อหาอะไรที่หยาบคาย

แบบฟอร์มและนักออกแบบ:

public partial class InputBox 
    : Form
{

    public String Input
    {
        get { return textInput.Text; }
    }

    public InputBox()
    {
        InitializeComponent();
    }

    private void button2_Click(object sender, EventArgs e)
    {
        DialogResult = System.Windows.Forms.DialogResult.OK;
    }

    private void button1_Click(object sender, EventArgs e)
    {
        DialogResult = System.Windows.Forms.DialogResult.Cancel;
    }

    private void InputBox_Load(object sender, EventArgs e)
    {
        this.ActiveControl = textInput;
    }

    public static DialogResult Show(String title, String message, String inputTitle, out String inputValue)
    {
        InputBox inputBox = null;
        DialogResult results = DialogResult.None;

        using (inputBox = new InputBox() { Text = title })
        {
            inputBox.labelMessage.Text = message;
            inputBox.splitContainer2.SplitterDistance = inputBox.labelMessage.Width;
            inputBox.labelInput.Text = inputTitle;
            inputBox.splitContainer1.SplitterDistance = inputBox.labelInput.Width;
            inputBox.Size = new Size(
                inputBox.Width,
                8 + inputBox.labelMessage.Height + inputBox.splitContainer2.SplitterWidth + inputBox.splitContainer1.Height + 8 + inputBox.button2.Height + 12 + (50));
            results = inputBox.ShowDialog();
            inputValue = inputBox.Input;
        }

        return results;
    }

    void labelInput_TextChanged(object sender, System.EventArgs e)
    {
    }

}

partial class InputBox
{
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.IContainer components = null;

    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    protected override void Dispose(bool disposing)
    {
        if (disposing && (components != null))
        {
            components.Dispose();
        }
        base.Dispose(disposing);
    }

    #region Windows Form Designer generated code

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
        this.labelMessage = new System.Windows.Forms.Label();
        this.button1 = new System.Windows.Forms.Button();
        this.button2 = new System.Windows.Forms.Button();
        this.labelInput = new System.Windows.Forms.Label();
        this.textInput = new System.Windows.Forms.TextBox();
        this.splitContainer1 = new System.Windows.Forms.SplitContainer();
        this.splitContainer2 = new System.Windows.Forms.SplitContainer();
        ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
        this.splitContainer1.Panel1.SuspendLayout();
        this.splitContainer1.Panel2.SuspendLayout();
        this.splitContainer1.SuspendLayout();
        ((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).BeginInit();
        this.splitContainer2.Panel1.SuspendLayout();
        this.splitContainer2.Panel2.SuspendLayout();
        this.splitContainer2.SuspendLayout();
        this.SuspendLayout();
        // 
        // labelMessage
        // 
        this.labelMessage.AutoSize = true;
        this.labelMessage.Location = new System.Drawing.Point(3, 0);
        this.labelMessage.MaximumSize = new System.Drawing.Size(379, 0);
        this.labelMessage.Name = "labelMessage";
        this.labelMessage.Size = new System.Drawing.Size(50, 13);
        this.labelMessage.TabIndex = 99;
        this.labelMessage.Text = "Message";
        // 
        // button1
        // 
        this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
        this.button1.Location = new System.Drawing.Point(316, 126);
        this.button1.Name = "button1";
        this.button1.Size = new System.Drawing.Size(75, 23);
        this.button1.TabIndex = 3;
        this.button1.Text = "Cancel";
        this.button1.UseVisualStyleBackColor = true;
        this.button1.Click += new System.EventHandler(this.button1_Click);
        // 
        // button2
        // 
        this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
        this.button2.Location = new System.Drawing.Point(235, 126);
        this.button2.Name = "button2";
        this.button2.Size = new System.Drawing.Size(75, 23);
        this.button2.TabIndex = 2;
        this.button2.Text = "OK";
        this.button2.UseVisualStyleBackColor = true;
        this.button2.Click += new System.EventHandler(this.button2_Click);
        // 
        // labelInput
        // 
        this.labelInput.AutoSize = true;
        this.labelInput.Location = new System.Drawing.Point(3, 6);
        this.labelInput.Name = "labelInput";
        this.labelInput.Size = new System.Drawing.Size(31, 13);
        this.labelInput.TabIndex = 99;
        this.labelInput.Text = "Input";
        this.labelInput.TextChanged += new System.EventHandler(this.labelInput_TextChanged);
        // 
        // textInput
        // 
        this.textInput.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
        | System.Windows.Forms.AnchorStyles.Right)));
        this.textInput.Location = new System.Drawing.Point(3, 3);
        this.textInput.Name = "textInput";
        this.textInput.Size = new System.Drawing.Size(243, 20);
        this.textInput.TabIndex = 1;
        // 
        // splitContainer1
        // 
        this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
        this.splitContainer1.FixedPanel = System.Windows.Forms.FixedPanel.Panel2;
        this.splitContainer1.IsSplitterFixed = true;
        this.splitContainer1.Location = new System.Drawing.Point(0, 0);
        this.splitContainer1.Name = "splitContainer1";
        // 
        // splitContainer1.Panel1
        // 
        this.splitContainer1.Panel1.Controls.Add(this.labelInput);
        // 
        // splitContainer1.Panel2
        // 
        this.splitContainer1.Panel2.Controls.Add(this.textInput);
        this.splitContainer1.Size = new System.Drawing.Size(379, 50);
        this.splitContainer1.SplitterDistance = 126;
        this.splitContainer1.TabIndex = 99;
        // 
        // splitContainer2
        // 
        this.splitContainer2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
        | System.Windows.Forms.AnchorStyles.Left) 
        | System.Windows.Forms.AnchorStyles.Right)));
        this.splitContainer2.IsSplitterFixed = true;
        this.splitContainer2.Location = new System.Drawing.Point(12, 12);
        this.splitContainer2.Name = "splitContainer2";
        this.splitContainer2.Orientation = System.Windows.Forms.Orientation.Horizontal;
        // 
        // splitContainer2.Panel1
        // 
        this.splitContainer2.Panel1.Controls.Add(this.labelMessage);
        // 
        // splitContainer2.Panel2
        // 
        this.splitContainer2.Panel2.Controls.Add(this.splitContainer1);
        this.splitContainer2.Size = new System.Drawing.Size(379, 108);
        this.splitContainer2.SplitterDistance = 54;
        this.splitContainer2.TabIndex = 99;
        // 
        // InputBox
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(403, 161);
        this.Controls.Add(this.splitContainer2);
        this.Controls.Add(this.button2);
        this.Controls.Add(this.button1);
        this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
        this.MaximizeBox = false;
        this.MinimizeBox = false;
        this.Name = "InputBox";
        this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
        this.Text = "Title";
        this.TopMost = true;
        this.Load += new System.EventHandler(this.InputBox_Load);
        this.splitContainer1.Panel1.ResumeLayout(false);
        this.splitContainer1.Panel1.PerformLayout();
        this.splitContainer1.Panel2.ResumeLayout(false);
        this.splitContainer1.Panel2.PerformLayout();
        ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit();
        this.splitContainer1.ResumeLayout(false);
        this.splitContainer2.Panel1.ResumeLayout(false);
        this.splitContainer2.Panel1.PerformLayout();
        this.splitContainer2.Panel2.ResumeLayout(false);
        ((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).EndInit();
        this.splitContainer2.ResumeLayout(false);
        this.ResumeLayout(false);

    }

    #endregion

    private System.Windows.Forms.Label labelMessage;
    private System.Windows.Forms.Button button1;
    private System.Windows.Forms.Button button2;
    private System.Windows.Forms.Label labelInput;
    private System.Windows.Forms.TextBox textInput;
    private System.Windows.Forms.SplitContainer splitContainer1;
    private System.Windows.Forms.SplitContainer splitContainer2;
}

การใช้งาน:

String output = "";

result = System.Windows.Forms.DialogResult.None;

result = InputBox.Show(
    "Input Required",
    "Please enter the value (if available) below.",
    "Value",
    out output);

if (result != System.Windows.Forms.DialogResult.OK)
{
    return;
}

หมายเหตุการจัดแสดงนี้มีการปรับขนาดอัตโนมัติเล็กน้อยเพื่อให้มันดูสวยขึ้นอยู่กับจำนวนข้อความที่คุณขอให้แสดง ฉันเองก็รู้ว่ามันขาดเสียงระฆังและเสียงหวีดหวีด แต่มันก็เป็นก้าวที่มั่นคงสำหรับผู้ที่เผชิญหน้ากับปัญหาเดียวกันนี้


-2

ไม่มีสิ่งนั้น: ฉันแนะนำให้เขียนด้วยตัวคุณเองและใช้ทุกครั้งที่คุณต้องการ

โดยการใช้ไซต์ของเรา หมายความว่าคุณได้อ่านและทำความเข้าใจนโยบายคุกกี้และนโยบายความเป็นส่วนตัวของเราแล้ว
Licensed under cc by-sa 3.0 with attribution required.