Laden...

Form erstellen

Letzter Beitrag vor 18 Jahren 6 Posts 2.765 Views
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!


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



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?

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 😁 :]

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

Vielen Dank!

Hallo MS+00000,

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

herbivore