c # - Sådan hentes eller hentes input fra mine formularer app

Indlæg af Hanne Mølgaard Plasc

Problem



Jeg er her, min her kode og det er en kalkulator:


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;

    }
}

Bedste reference


Der er kun en NumericUpDown-kontrol i din form, så jeg antager, at du vil hente den værdi af den kontrol. Du skal bruge num1.Value for at få det værd.


Prøve


    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);
    }