RESI

   
 

Berechnung von seriell und parallel geschalteten Widerständen.

 

 

Download(313KB)

 

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace RESI
{
/// <summary>
/// Zusammenfassung für Form1.
/// </summary>
public class frm_RESI : System.Windows.Forms.Form
{
private System.Windows.Forms.Button btn_ende;
private System.Windows.Forms.TextBox txt_R1;
private System.Windows.Forms.TextBox txt_R2;
private System.Windows.Forms.TextBox txt_Rg;
private System.Windows.Forms.Label lbl_R1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Button btn_rechne;
/// <summary>
/// Erforderliche Designervariable.
/// </summary>
private System.ComponentModel.Container components = null;

private double r1; //Widerstände
private double r2;
private System.Windows.Forms.Label lbl_W1;
private System.Windows.Forms.Label lbl_W2;
private System.Windows.Forms.Label lbl_Wg;
private System.Windows.Forms.GroupBox grp_schalt;
private System.Windows.Forms.RadioButton rad_par;
private System.Windows.Forms.RadioButton rad_ser;
private double rg; //Gesamtwiderstand

public frm_RESI()
{
//
// Erforderlich für die Windows Form-Designerunterstützung
//
InitializeComponent();

//
// TODO: Fügen Sie den Konstruktorcode nach dem Aufruf von InitializeComponent hinzu
//
}

/// <summary>
/// Die verwendeten Ressourcen bereinigen.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (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.btn_ende = new System.Windows.Forms.Button();
this.txt_R1 = new System.Windows.Forms.TextBox();
this.txt_R2 = new System.Windows.Forms.TextBox();
this.txt_Rg = new System.Windows.Forms.TextBox();
this.lbl_R1 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.btn_rechne = new System.Windows.Forms.Button();
this.lbl_W1 = new System.Windows.Forms.Label();
this.lbl_W2 = new System.Windows.Forms.Label();
this.lbl_Wg = new System.Windows.Forms.Label();
this.grp_schalt = new System.Windows.Forms.GroupBox();
this.rad_par = new System.Windows.Forms.RadioButton();
this.rad_ser = new System.Windows.Forms.RadioButton();
this.grp_schalt.SuspendLayout();
this.SuspendLayout();
//
// btn_ende
//
this.btn_ende.Location = new System.Drawing.Point(168, 224);
this.btn_ende.Name = "btn_ende";
this.btn_ende.Size = new System.Drawing.Size(112, 32);
this.btn_ende.TabIndex = 5;
this.btn_ende.Text = "&Ende";
this.btn_ende.Click += new System.EventHandler(this.btn_ende_Click);
//
// txt_R1
//
this.txt_R1.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.txt_R1.Location = new System.Drawing.Point(32, 56);
this.txt_R1.Name = "txt_R1";
this.txt_R1.Size = new System.Drawing.Size(64, 26);
this.txt_R1.TabIndex = 0;
this.txt_R1.Text = "";
this.txt_R1.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
this.txt_R1.Click += new System.EventHandler(this.txt_R1_Click);
//
// txt_R2
//
this.txt_R2.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.txt_R2.Location = new System.Drawing.Point(184, 56);
this.txt_R2.Name = "txt_R2";
this.txt_R2.Size = new System.Drawing.Size(64, 26);
this.txt_R2.TabIndex = 1;
this.txt_R2.Text = "";
this.txt_R2.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
this.txt_R2.Click += new System.EventHandler(this.txt_R2_Click);
//
// txt_Rg
//
this.txt_Rg.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.txt_Rg.Location = new System.Drawing.Point(184, 144);
this.txt_Rg.Name = "txt_Rg";
this.txt_Rg.ReadOnly = true;
this.txt_Rg.Size = new System.Drawing.Size(64, 26);
this.txt_Rg.TabIndex = 0;
this.txt_Rg.TabStop = false;
this.txt_Rg.Text = "123";
this.txt_Rg.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
//
// lbl_R1
//
this.lbl_R1.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))), System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.lbl_R1.Location = new System.Drawing.Point(32, 32);
this.lbl_R1.Name = "lbl_R1";
this.lbl_R1.Size = new System.Drawing.Size(64, 24);
this.lbl_R1.TabIndex = 0;
this.lbl_R1.Text = "R1";
this.lbl_R1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// label1
//
this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))), System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label1.Location = new System.Drawing.Point(184, 32);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(64, 24);
this.label1.TabIndex = 0;
this.label1.Text = "R2";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// label2
//
this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))), System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label2.Location = new System.Drawing.Point(184, 112);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(64, 32);
this.label2.TabIndex = 0;
this.label2.Text = "Rges";
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// btn_rechne
//
this.btn_rechne.Location = new System.Drawing.Point(168, 184);
this.btn_rechne.Name = "btn_rechne";
this.btn_rechne.Size = new System.Drawing.Size(112, 32);
this.btn_rechne.TabIndex = 4;
this.btn_rechne.Text = "&Berechnen";
this.btn_rechne.Click += new System.EventHandler(this.btn_rechne_Click);
//
// lbl_W1
//
this.lbl_W1.Font = new System.Drawing.Font("Symbol", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(2)));
this.lbl_W1.Location = new System.Drawing.Point(96, 56);
this.lbl_W1.Name = "lbl_W1";
this.lbl_W1.Size = new System.Drawing.Size(16, 24);
this.lbl_W1.TabIndex = 4;
this.lbl_W1.Text = "W";
this.lbl_W1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// lbl_W2
//
this.lbl_W2.Font = new System.Drawing.Font("Symbol", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(2)));
this.lbl_W2.Location = new System.Drawing.Point(248, 56);
this.lbl_W2.Name = "lbl_W2";
this.lbl_W2.Size = new System.Drawing.Size(16, 24);
this.lbl_W2.TabIndex = 5;
this.lbl_W2.Text = "W";
this.lbl_W2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// lbl_Wg
//
this.lbl_Wg.Font = new System.Drawing.Font("Symbol", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(2)));
this.lbl_Wg.Location = new System.Drawing.Point(248, 144);
this.lbl_Wg.Name = "lbl_Wg";
this.lbl_Wg.Size = new System.Drawing.Size(16, 24);
this.lbl_Wg.TabIndex = 6;
this.lbl_Wg.Text = "W";
this.lbl_Wg.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// grp_schalt
//
this.grp_schalt.Controls.Add(this.rad_par);
this.grp_schalt.Controls.Add(this.rad_ser);
this.grp_schalt.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))), System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.grp_schalt.Location = new System.Drawing.Point(16, 120);
this.grp_schalt.Name = "grp_schalt";
this.grp_schalt.Size = new System.Drawing.Size(112, 80);
this.grp_schalt.TabIndex = 7;
this.grp_schalt.TabStop = false;
this.grp_schalt.Text = "Schaltung:";
//
// rad_par
//
this.rad_par.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))), System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.rad_par.Location = new System.Drawing.Point(24, 48);
this.rad_par.Name = "rad_par";
this.rad_par.Size = new System.Drawing.Size(72, 16);
this.rad_par.TabIndex = 3;
this.rad_par.TabStop = true;
this.rad_par.Text = "parallel";
//
// rad_ser
//
this.rad_ser.Checked = true;
this.rad_ser.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))), System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.rad_ser.Location = new System.Drawing.Point(24, 24);
this.rad_ser.Name = "rad_ser";
this.rad_ser.Size = new System.Drawing.Size(72, 16);
this.rad_ser.TabIndex = 2;
this.rad_ser.TabStop = true;
this.rad_ser.Text = "seriell";
this.rad_ser.CheckedChanged += new System.EventHandler(this.rad_ser_CheckedChanged);
//
// frm_RESI
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.grp_schalt);
this.Controls.Add(this.lbl_Wg);
this.Controls.Add(this.lbl_W2);
this.Controls.Add(this.lbl_W1);
this.Controls.Add(this.btn_rechne);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.lbl_R1);
this.Controls.Add(this.txt_Rg);
this.Controls.Add(this.txt_R2);
this.Controls.Add(this.txt_R1);
this.Controls.Add(this.btn_ende);
this.Name = "frm_RESI";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "RESI";
this.grp_schalt.ResumeLayout(false);
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// Der Haupteinstiegspunkt für die Anwendung.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new frm_RESI());
}

private void btn_ende_Click(object sender, System.EventArgs e)
{
this.Close();
}

private void btn_rechne_Click(object sender, System.EventArgs e)
{
//Auslesen der Textfelder
r1=Convert.ToDouble(txt_R1.Text);
r2=Convert.ToDouble(txt_R2.Text);
//Berechnung
if(rad_par.Checked)
{
rg=par_Wid(r1,r2);
}
else
{
rg=ser_Wid(r1,r2);
}
rg=Math.Round(rg,3);
//Ausgabe
txt_Rg.Text=Convert.ToString(rg);
}
private double par_Wid(double r1,double r2)
{
if(r1+r2!=0)
{
rg=r1*r2/(r1+r2);
}
else
{
MessageBox.Show("Die Summe der Wiederstände darf nicht Null sein!");
}
return rg;
}
private double ser_Wid(double r1,double r2)
{
rg=r1+r2;
return rg;
}
private void txt_R1_Click(object sender, System.EventArgs e)
{
txt_R1.Text="";
}

private void txt_R2_Click(object sender, System.EventArgs e)
{
txt_R2.Text="";
}

private void rad_ser_CheckedChanged(object sender, System.EventArgs e)
{
btn_rechne_Click(this.rad_ser,e);
}
}
}

 

 

<<zurück>>