【问题标题】:How to fetch or grab input from my forms app如何从我的表单应用程序中获取或获取输入
【发布时间】:2011-03-26 17:16:19
【问题描述】:

我是随机人,这是我的代码,它是一个计算器:

namespace WindowsFormsApplication1
{
    partial class Form1
    {
        /// <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.num1 = new System.Windows.Forms.NumericUpDown();
            ((System.ComponentModel.ISupportInitialize)(this.num1)).BeginInit();
            this.SuspendLayout();
            // 
            // num1
            // 
            this.num1.AccessibleName = "";
            this.num1.Location = new System.Drawing.Point(12, 12);
            this.num1.Name = "num1";
            this.num1.Size = new System.Drawing.Size(120, 20);
            this.num1.TabIndex = 0;
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(284, 262);
            this.Controls.Add(this.num1);
            this.Name = "Form1";
            this.Text = "Form1";
            ((System.ComponentModel.ISupportInitialize)(this.num1)).EndInit();
            this.ResumeLayout(false);

        }

        #endregion

        private System.Windows.Forms.NumericUpDown num1;

    }
}

【问题讨论】:

  • 很简单,要得到答案,先问一个问题。
  • 代码错误。那是设计师。你想什么时候读取输入?当有人点击按钮时?
  • 当有人点击按钮或输入东西时

标签: c# windows visual-studio-2010


【解决方案1】:

您的表单中只有一个 NumericUpDown 控件,因此我假设您要获取该控件的该值。你必须使用num1.Value 来获得它的价值。

试试

    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        num1.ValueChanged += new EventHandler(numericUpDown1_ValueChanged);
    }

    void numericUpDown1_ValueChanged(object sender, EventArgs e)
    {
        MessageBox.Show("New value : " +num1.Value);
    }

【讨论】:

  • @randomdude 如果您对答案感到满意,您应该将问题标记为已解决。
  • 我在哪里把它放在第一个受保护的覆盖 void 下
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-06-01
  • 2017-12-21
  • 2021-11-17
  • 2017-02-21
相关资源
最近更新 更多