C# :: Aufgabe #273 :: Lösung #2

2 Lösungen Lösungen öffentlich
#273

Funktionswerte einer Parabel berechnen - Windows Forms

Anfänger - C# von paddlboot - 04.12.2019 um 16:13 Uhr
Erstelle eine Windows Form, in der Funktionswerte einer Parabel berechnet werden können.
Dafür sollen Start-, Endwert und Schrittweite über Textboxen eingelesen werden und nach dem Betätigen des Berechnen-Buttons die X- und Y-Werte in einer ListBox ausgegeben werden.
Mögliches Aussehen siehe Anhang.
#2
vote_ok
von Waldgeist (2310 Punkte) - 23.12.2019 um 16:38 Uhr
Hallo,

danke für diese Aufgabe, habe mich zum ersten mal mit der ListBox beschäftigt und viel gelernt.
Ich hoffe das passt so weit :-)

Quellcode ausblenden C#-Code
using System;
using System.Windows.Forms;

namespace Aufgabe_273_Parabel
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }



        private void Reset_Button_Click(object sender, EventArgs e)
        {
            Startwert.Text = "0";
            Endwert.Text = "0";
            Schrittweite.Text = "1";
            listBox1.Items.Clear();

        }



        private void Start_Button_Click(object sender, EventArgs e)
        {
            listBox1.Items.Add("Berechnete Werte");
            listBox1.Items.Add("- - - - - - - - - - - - - - - - -");
            double start = Convert.ToDouble(Startwert.Text);
            double schritt = Convert.ToDouble(Schrittweite.Text);
            double ende = Convert.ToDouble(Endwert.Text);


            for (double i = start; i <= ende; i = i + schritt)
            {
                listBox1.Items.Add(" X-Wert  " + i + "   Y-Wert  " + i * i);
            }
        }
    }
}



Quellcode ausblenden C#-Code
namespace Aufgabe_273_Parabel
{
    partial class Form1
    {
        /// <summary>
        /// Erforderliche Designervariable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Verwendete Ressourcen bereinigen.
        /// </summary>
        /// <param name="disposing">True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Vom Windows Form-Designer generierter Code

        /// <summary>
        /// Erforderliche Methode für die Designerunterstützung.
        /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
        /// </summary>
        private void InitializeComponent()
        {
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.Schrittweite = new System.Windows.Forms.TextBox();
            this.Endwert = new System.Windows.Forms.TextBox();
            this.Startwert = new System.Windows.Forms.TextBox();
            this.label3 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.label1 = new System.Windows.Forms.Label();
            this.listBox1 = new System.Windows.Forms.ListBox();
            this.Start_Button = new System.Windows.Forms.Button();
            this.Reset_Button = new System.Windows.Forms.Button();
            this.groupBox1.SuspendLayout();
            this.SuspendLayout();
            // 
            // groupBox1
            // 
            this.groupBox1.Controls.Add(this.Schrittweite);
            this.groupBox1.Controls.Add(this.Endwert);
            this.groupBox1.Controls.Add(this.Startwert);
            this.groupBox1.Controls.Add(this.label3);
            this.groupBox1.Controls.Add(this.label2);
            this.groupBox1.Controls.Add(this.label1);
            this.groupBox1.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
            this.groupBox1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.groupBox1.Location = new System.Drawing.Point(27, 32);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new System.Drawing.Size(200, 180);
            this.groupBox1.TabIndex = 0;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "X-Werte";
            // 
            // Schrittweite
            // 
            this.Schrittweite.Location = new System.Drawing.Point(125, 135);
            this.Schrittweite.Name = "Schrittweite";
            this.Schrittweite.Size = new System.Drawing.Size(34, 20);
            this.Schrittweite.TabIndex = 5;
            this.Schrittweite.Text = "1";
            this.Schrittweite.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
            // 
            // Endwert
            // 
            this.Endwert.Location = new System.Drawing.Point(125, 95);
            this.Endwert.Name = "Endwert";
            this.Endwert.Size = new System.Drawing.Size(34, 20);
            this.Endwert.TabIndex = 4;
            this.Endwert.Text = "0";
            this.Endwert.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
            // 
            // Startwert
            // 
            this.Startwert.Location = new System.Drawing.Point(125, 50);
            this.Startwert.Name = "Startwert";
            this.Startwert.Size = new System.Drawing.Size(34, 20);
            this.Startwert.TabIndex = 3;
            this.Startwert.Text = "0";
            this.Startwert.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
            // 
            // label3
            // 
            this.label3.AutoSize = true;
            this.label3.Location = new System.Drawing.Point(21, 135);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(74, 13);
            this.label3.TabIndex = 2;
            this.label3.Text = "Schrittweite";
            // 
            // label2
            // 
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(21, 95);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(53, 13);
            this.label2.TabIndex = 1;
            this.label2.Text = "Endwert";
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(21, 53);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(58, 13);
            this.label1.TabIndex = 0;
            this.label1.Text = "Startwert";
            // 
            // listBox1
            // 
            this.listBox1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.listBox1.FormattingEnabled = true;
            this.listBox1.Location = new System.Drawing.Point(264, 32);
            this.listBox1.Name = "listBox1";
            this.listBox1.Size = new System.Drawing.Size(211, 277);
            this.listBox1.TabIndex = 1;
            // 
            // Start_Button
            // 
            this.Start_Button.Location = new System.Drawing.Point(27, 252);
            this.Start_Button.Name = "Start_Button";
            this.Start_Button.Size = new System.Drawing.Size(90, 50);
            this.Start_Button.TabIndex = 2;
            this.Start_Button.Text = "Start";
            this.Start_Button.UseVisualStyleBackColor = true;
            this.Start_Button.Click += new System.EventHandler(this.Start_Button_Click);
            // 
            // Reset_Button
            // 
            this.Reset_Button.Location = new System.Drawing.Point(137, 252);
            this.Reset_Button.Name = "Reset_Button";
            this.Reset_Button.Size = new System.Drawing.Size(90, 50);
            this.Reset_Button.TabIndex = 3;
            this.Reset_Button.Text = "Reset";
            this.Reset_Button.UseVisualStyleBackColor = true;
            this.Reset_Button.Click += new System.EventHandler(this.Reset_Button_Click);
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(506, 340);
            this.Controls.Add(this.Reset_Button);
            this.Controls.Add(this.Start_Button);
            this.Controls.Add(this.listBox1);
            this.Controls.Add(this.groupBox1);
            this.Name = "Form1";
            this.Text = "Aufgabe_273_Funktionswerte Parabel";
            this.groupBox1.ResumeLayout(false);
            this.groupBox1.PerformLayout();
            this.ResumeLayout(false);

        }

        #endregion

        private System.Windows.Forms.GroupBox groupBox1;
        private System.Windows.Forms.TextBox Schrittweite;
        private System.Windows.Forms.TextBox Endwert;
        private System.Windows.Forms.TextBox Startwert;
        private System.Windows.Forms.Label label3;
        private System.Windows.Forms.Label label2;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.ListBox listBox1;
        private System.Windows.Forms.Button Start_Button;
        private System.Windows.Forms.Button Reset_Button;
    }
}

Kommentare:

Für diese Lösung gibt es noch keinen Kommentar

Bitte melden Sie sich an um eine Kommentar zu schreiben.
Kommentar schreiben