Laden...

Form erstellen

Erstellt von MS+00000 vor 17 Jahren Letzter Beitrag vor 17 Jahren 2.702 Views
M
MS+00000 Themenstarter:in
12 Beiträge seit 2006
vor 17 Jahren
Form erstellen

hi!

ich programmiere erst seit kurzem mit C# und bring es einfach nicht fertig eine neue form zu erstellen. ich mochte sie über einen button aufrufen können. wie schreibe ich das???

wäre nett wenn mir jemand helfen könnte

danke im foraus!

57 Beiträge seit 2005
vor 17 Jahren

using System;
using System.Windows.Forms;
using System.Drawing;

public class MyForm : Form
{
	private MyForm2 tmpform;	
	private Button btAction = new Button();
	
	public  MyForm(MyForm2 tmp)
	{
		this.tmpform = tmp;
		this.Text = "My simple Form in UltraEdit";	
		this.btAction.Location = new Point(0, 0);
		this.btAction.Text = "Action";
		this.btAction.Click += new EventHandler(this.Action);
		this.Controls.Add(this.btAction);
	}
	
	private void Action(object source, EventArgs e)
	{
		this.tmpform.Show();
	}
}


public class MyForm2 : Form
{
	private TextBox txtText = new TextBox();
	public  MyForm2()
	{
		this.Text = "My simple Form in UltraEdit";	
	}
}



class MainApp
{
	public static void Main()
	{
		
		MyForm2 f2 = new MyForm2();
		MyForm f = new MyForm(f2);
		Application.Run(f);
		
	}	
}



57 Beiträge seit 2005
vor 17 Jahren

Oder so:


using System;
using System.Windows.Forms;
using System.Drawing;

public class MyForm : Form
{

	private Button btAction = new Button();
	
	public  MyForm()
	{
		this.Text = "My simple Form in UltraEdit";	
		this.btAction.Location = new Point(0, 0);
		this.btAction.Text = "Action";
		this.btAction.Click += new EventHandler(this.Action);
		this.Controls.Add(this.btAction);
	}
	
	private void Action(object source, EventArgs e)
	{
		new Form().Show();
	}
}

class MainApp
{
	public static void Main()
	{
		
		MyForm f = new MyForm();
		Application.Run(f);
		
	}	
}


Der Unterschied ist eindeutig. oder?

564 Beiträge seit 2006
vor 17 Jahren

Hi!

Die Grundidee dazu 🙂 : Du fügst in Form1 dem Click-EventHandler des Buttons eine Methode hinzu, welche Form2 instanziiert und über Show aufruft.

der Marcel

:] 😄Der größte Fehler eines modernen Computers sitzt meist davor 😁 :]

M
MS+00000 Themenstarter:in
12 Beiträge seit 2006
vor 17 Jahren

Die Grundidee war mir klar, aber ich wusste nicht wie ich es schreibe!

Vielen Dank!

49.485 Beiträge seit 2005
vor 17 Jahren

Hallo MS+00000,

liest mal bitte mindestens solange in Mehrere Fenster in einem programm , bis du auf das Wort Buch stößt. 🙂

herbivore