Folge dem Video um zu sehen, wie unsere Website als Web-App auf dem Startbildschirm installiert werden kann.
Anmerkung: Diese Funktion ist in einigen Browsern möglicherweise nicht verfügbar.
//Aufruf der Klasse aus Form 1 heraus:
private void button2_Click(object sender, EventArgs e)
{
CreateButtonClass test = new CreateButtonClass();
test.Show();
}
//Klasse:
class CreateButtonClass : Form1
{
public CreateButtonClass()
{
Button btn = new Button();
btn.Name = "TestButton";
btn.Text = "TestButton";
btn.Size = new Size(80, 40);
btn.Location = new Point(5, 5);
pictureBox.Controls.Add(btn);
}
}
internal class CreateButtonClass_Reference
{
Form1 m_form1;
Button m_newButton;
public CreateButtonClass_Reference ( Form1 form1 )
{
this.m_form1 = form1;
}
public void CreateButton ()
{
this.m_newButton = new Button();
this.m_newButton.Name = "TestButton";
this.m_newButton.Text = "TestButton";
this.m_newButton.Size = new Size( 80, 40 );
this.m_newButton.Location = new Point( 5, 5 );
this.m_newButton.Click += new EventHandler( m_button_Click );
this.m_form1.pictureBox.Controls.Add( this.m_newButton );
}
void m_button_Click ( object sender, EventArgs e )
{
this.m_newButton.Dispose();
}
}
internal class CreateButtonClass_Static
{
public static void CreateButton ( PictureBox pictureBox, EventHandler eventHandler )
{
Button newButton = new Button();
newButton.Name = "TestButton";
newButton.Text = "TestButton";
newButton.Size = new Size( 80, 40 );
newButton.Location = new Point( 5, 5 );
newButton.Click += new EventHandler( eventHandler );
pictureBox.Controls.Add( newButton );
}
}
public partial class Form1 : Form
{
#region Static Access
static Form1 s_mainForm;
public static Form1 GetInstance
{
get
{
if ( s_mainForm == null ) {
lock ( typeof (Form1) ) {
s_mainForm = new Form1();
}
}
return s_mainForm;
}
}
#endregion
Button m_newButton;
CreateButtonClass_Reference m_createButtonClass_Reference;
Form1 ()
{
InitializeComponent();
}
void createButtonButton_Click ( object sender, EventArgs e )
{
this.m_newButton = new Button();
this.m_newButton.Name = "TestButton";
this.m_newButton.Text = "TestButton";
this.m_newButton.Size = new Size( 80, 40 );
this.m_newButton.Location = new Point( 5, 5 );
pictureBox.Controls.Add( this.m_newButton );
this.m_newButton.Click += new EventHandler( this.newButton_Click );
}
void createButtonByReferenceButton_Click ( object sender, EventArgs e )
{
this.m_createButtonClass_Reference = new CreateButtonClass_Reference( this );
this.m_createButtonClass_Reference.CreateButton();
}
void createButtonStaticButton_Click ( object sender, EventArgs e )
{
CreateButtonClass_Static.CreateButton( this.pictureBox, new EventHandler( this.newButton_Click ) );
}
void createButtonBySingletonButton_Click ( object sender, EventArgs e )
{
CreateButtonClass_Static.CreateButton( GetInstance.pictureBox, new EventHandler( this.newButton_Click ) );
}
void newButton_Click ( object sender, EventArgs e )
{
((Control) sender).Dispose();
}
}