先添加dll,追加命名空间using Microsoft.VisualBasic;
strSeniorAmount=Interaction.InputBox(strUnitAlertMessage,"上位転換数を入力してください","1", -1,-1);
try
{
Convert.ToDecimal(strSeniorAmount);
}
catch
{
MessageBox.Show("ご数字を入力してください。",this.Text,MessageBoxButtons.OK,MessageBoxIcon.Information);
return;
}
我的问题
1.能不能限制inputbox的输入类型和长度或者最大值,最小值
2.如何区分点inputbox的确定和取消按钮事件
当inputbox为空时,点击确定,给出提示,点取消或者关闭,不提示,终止操作
当inputbox不为空时,错误不错误都行,点击确定,判断合法性,点击取消或者关闭,不提示,终止操作

解决方案 »

  1.   

    真是怀念啊,好久没用过InPutBox了
      

  2.   

    1.使用反射,取得弹出窗体的对象(Microsoft.VisualBasic.CompilerServices.VBInputBox)
    再取得你要改的对象
    2.同上建议,自己做个VBInputBox类,比用他的好internal sealed class VBInputBox : Form
    {
        // Fields
        private Container components;
        private Label Label;
        private Button MyCancelButton;
        private Button OKButton;
        public string Output;
        private TextBox TextBox;    // Methods
        internal VBInputBox()
        {
            this.Output = "";
            this.InitializeComponent();
        }    internal VBInputBox(string Prompt, string Title, string DefaultResponse, int XPos, int YPos)
        {
            this.Output = "";
            this.InitializeComponent();
            this.InitializeInputBox(Prompt, Title, DefaultResponse, XPos, YPos);
        }    protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }    private void InitializeComponent()
        {
            ComponentResourceManager manager = new ComponentResourceManager(typeof(VBInputBox));
            this.OKButton = new Button();
            this.MyCancelButton = new Button();
            this.TextBox = new TextBox();
            this.Label = new Label();
            this.SuspendLayout();
            manager.ApplyResources(this.OKButton, "OKButton", CultureInfo.CurrentUICulture);
            this.OKButton.Name = "OKButton";
            this.MyCancelButton.DialogResult = DialogResult.Cancel;
            manager.ApplyResources(this.MyCancelButton, "MyCancelButton", CultureInfo.CurrentUICulture);
            this.MyCancelButton.Name = "MyCancelButton";
            manager.ApplyResources(this.TextBox, "TextBox", CultureInfo.CurrentUICulture);
            this.TextBox.Name = "TextBox";
            manager.ApplyResources(this.Label, "Label", CultureInfo.CurrentUICulture);
            this.Label.Name = "Label";
            this.AcceptButton = this.OKButton;
            manager.ApplyResources(this, "$this", CultureInfo.CurrentUICulture);
            this.CancelButton = this.MyCancelButton;
            this.Controls.Add(this.TextBox);
            this.Controls.Add(this.Label);
            this.Controls.Add(this.OKButton);
            this.Controls.Add(this.MyCancelButton);
            this.FormBorderStyle = FormBorderStyle.FixedDialog;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "VBInputBox";
            this.ResumeLayout(false);
            this.PerformLayout();
        }    private void InitializeInputBox(string Prompt, string Title, string DefaultResponse, int XPos, int YPos)
        {
            this.Text = Title;
            this.Label.Text = Prompt;
            this.TextBox.Text = DefaultResponse;
            this.OKButton.Click += new EventHandler(this.OKButton_Click);
            this.MyCancelButton.Click += new EventHandler(this.MyCancelButton_Click);
            Graphics graphics = this.Label.CreateGraphics();
            SizeF ef = graphics.MeasureString(Prompt, this.Label.Font, this.Label.Width);
            graphics.Dispose();
            if (ef.Height > this.Label.Height)
            {
                int num = ((int) Math.Round((double) ef.Height)) - this.Label.Height;
                Label label = this.Label;
                label.Height += num;
                TextBox textBox = this.TextBox;
                textBox.Top += num;
                this.Height += num;
            }
            if ((XPos == -1) && (YPos == -1))
            {
                this.StartPosition = FormStartPosition.CenterScreen;
            }
            else
            {
                if (XPos == -1)
                {
                    XPos = 600;
                }
                if (YPos == -1)
                {
                    YPos = 350;
                }
                this.StartPosition = FormStartPosition.Manual;
                Point point = new Point(XPos, YPos);
                this.DesktopLocation = point;
            }
        }    private void MyCancelButton_Click(object sender, EventArgs e)
        {
            this.Close();
        }    private void OKButton_Click(object sender, EventArgs e)
        {
            this.Output = this.TextBox.Text;
            this.Close();
        }

    Collapse Methods
     
      

  3.   

    为什么要用inputbox呢,接分接分
    たのみます