Textausgabe unter C#

krizzelfix

Commander
Registriert
Sep. 2005
Beiträge
2.626
Moin

Wie kann man bei C# Texte ausgeben
Habe bisher nur mit Consolen Anwendungen gearbeite und dort geht es ja einfach mit Console.WriteLine("Hallo");.
Wie bekomme ich das unter einer C# Windows - Anwendung hin??

Warscheinlich muss ich ein Label in das Fenster einbinden...bin mir aber nicht sicher.

MFG

{-=TeWeS=-}
 
Genau. Ein Label einbinden und dann per Property einfach einen Text hinzufügen. :)

PHP:
Label myLabel = new Label();
myLabel.Text = "This is a new Label";

Hoppala ist ja PHP Highlighting. Aber weißt was gemeint ist ne? :)
 
thx für die Antwort...aber irgendwie bring mich das nich weiter...
ein label hab ich ja schon...nur wie bekomm ich das hin....habs bis jetzt nur geschafft das auszugeben was in einer Variablen steht.
Mein Code:
Code:
/*
 * Created by SharpDevelop.
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Drawing;
using System.Windows.Forms;

namespace GeldautomatDesign2
{
	/// <summary>
	/// Description of MainForm.
	/// </summary>
	public class MainForm : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.TextBox textBox1;
		private System.Windows.Forms.Button button2;
		private System.Windows.Forms.ListBox listBox1;
		public MainForm()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			
			//
			// TODO: Add constructor code after the InitializeComponent() call.
			//
		}
		
		[STAThread]
		public static void Main(string[] args)
		{
			Application.Run(new MainForm());
		}
		
		#region Windows Forms Designer generated code
		/// <summary>
		/// This method is required for Windows Forms designer support.
		/// Do not change the method contents inside the source code editor. The Forms designer might
		/// not be able to load this method if it was changed manually.
		/// </summary>
		private void InitializeComponent() {
			this.listBox1 = new System.Windows.Forms.ListBox();
			this.button2 = new System.Windows.Forms.Button();
			this.textBox1 = new System.Windows.Forms.TextBox();
			this.button1 = new System.Windows.Forms.Button();
			this.label1 = new System.Windows.Forms.Label();
			this.SuspendLayout();
			// 
			// listBox1
			// 
			this.listBox1.Location = new System.Drawing.Point(16, 128);
			this.listBox1.Name = "listBox1";
			this.listBox1.Size = new System.Drawing.Size(80, 56);
			this.listBox1.TabIndex = 3;
			// 
			// button2
			// 
			this.button2.Location = new System.Drawing.Point(16, 48);
			this.button2.Name = "button2";
			this.button2.TabIndex = 2;
			this.button2.Text = "Ausgabe";
			this.button2.Click += new System.EventHandler(this.Button2Click);
			// 
			// textBox1
			// 
			this.textBox1.Location = new System.Drawing.Point(16, 16);
			this.textBox1.Name = "textBox1";
			this.textBox1.TabIndex = 0;
			this.textBox1.Text = "";
			// 
			// button1
			// 
			this.button1.Location = new System.Drawing.Point(16, 200);
			this.button1.Name = "button1";
			this.button1.TabIndex = 4;
			this.button1.Text = "Ende";
			this.button1.Click += new System.EventHandler(this.Button1Click);
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(16, 88);
			this.label1.Name = "label1";
			this.label1.TabIndex = 5;
			this.label1.Text = "label1";
			// 
			// MainForm
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(292, 266);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.button2);
			this.Controls.Add(this.listBox1);
			this.Controls.Add(this.button1);
			this.Controls.Add(this.textBox1);
			this.Name = "MainForm";
			this.Text = "MainForm";
			this.ResumeLayout(false);
		}
		#endregion
		void Button1Click(object sender, System.EventArgs e)
		{
			
		}
		
		void Button2Click(object sender, System.EventArgs e)
		{
			int betrag = int.Parse(textBox1.Text);
			int a = 500;
			int b = 200;
			int c = 100;
			int d = 50;
			int h = 20;
			int f = 10;
			int g = 5;
			
			int aa = 0;
			int bb = 0;
			int cc = 0;
			int dd = 0;
			int hh = 0;
			int ff = 0;
			int gg = 0;
			
			while( betrag >= 500)
			{
				aa = aa + 1;
				betrag = betrag - 500;
			}
			while( betrag >= 200)
			{
				bb = bb + 1;
				betrag = betrag - 200;
			}
			while( betrag >= 100)
			{
				cc = cc +1;
				betrag = betrag - 100;
			}
			while( betrag >= 50)
			{
				dd = dd +1;
				betrag = betrag - 50;
			}
			while( betrag >= 20)
			{
				hh = hh +1;
				betrag = betrag - 20;
			}
			while( betrag >= 10)
			{
				ff = ff +1;
				betrag = betrag - 10;
			}
			while( betrag >= 5)
			{
				gg = gg +1;
				betrag = betrag - 5;
			}
			
				Label myLabel = new Label();
				myLabel.Text = "This is a new Label"; 	
			
			if( aa > 0)
			{
				listBox1.Items.Add(aa.ToString());
				listBox1.Items.Add(a.ToString());
			}
			if( bb > 0)
			{
				listBox1.Items.Add(bb.ToString());
				listBox1.Items.Add(b.ToString());
			}
			if( cc > 0)
			{
				listBox1.Items.Add(cc.ToString());
				listBox1.Items.Add(c.ToString());
			}
			if( dd > 0)
			{
				listBox1.Items.Add(dd.ToString());
				listBox1.Items.Add(d.ToString());
			}
			if( hh > 0)
			{
				listBox1.Items.Add(hh.ToString());
				listBox1.Items.Add(h.ToString());
			}
			if( ff > 0)
			{
				listBox1.Items.Add(ff.ToString());
				listBox1.Items.Add(f.ToString());
			}
			if( gg > 0)
			{
				listBox1.Items.Add(gg.ToString());
				listBox1.Items.Add(g.ToString());
			}
		}
		
	}
}
 
Dann deklarier das Label global und einfach per Text Eigenschaft:

label1.text = "Sie bekommen " + $a+ " 500 Euro Scheine";

in deiner Methode aufrufen.
 
hab nochmal eine frage.

Wie bekomm ich das hin das das Fenster geschlossen wird wenn man auf ein Button klickt??
 
Code:
private void button_Click(object sender, EventArgs e)
{
         this.Close();
}
 
Zurück
Oben