By Rico


2018-04-16 13:03:25 8 Comments

Hi I have one built created with one script in c# but now I want to create a button from other script in the same Form (the same window) that in the first script. Would be great to use a PlayButton_Click void from different script too.

Here is an example of what i'm trying:

Script 1:

using System;
using System.Windows.Forms;
using System.Drawing;
using System.IO;
using System.Collections.Generic;


public class HelloWorld : Form
{
  public static Button PlayButton;

  public void Main()
  {
    Application.Run ();
  }

  public Form1()
  {
    PlayButton = new Button();
    Controls.Add(PlayButton);
  }

  public void PlayButton_Click(object sender, EventArgs e)
  {
    MessageBox.Show ("All ok");
  }
}

Script 2:

using System;
using System.Windows.Forms;
using System.Drawing;
using System.IO;
using System.Collections.Generic;

public class HelloWorld2 : Form
{
  public static Button PlayButton2;

    public Helloworld2()
    {
        PlayButton2 = new Button();
        Controls.Add(PlayButton2);
    }

    public void PlayButton2_Click(object sender, EventArgs e)
    {
        MessageBox.Show ("I'm in the first Form :D!");
    }
}

0 comments

Related Questions

Sponsored Content

40 Answered Questions

[SOLVED] Create Excel (.XLS and .XLSX) file from C#

  • 2008-09-29 22:30:28
  • mistrmark
  • 928294 View
  • 1598 Score
  • 40 Answer
  • Tags:   c# .net excel file-io

21 Answered Questions

[SOLVED] Cast int to enum in C#

  • 2008-08-27 03:58:21
  • lomaxx
  • 1043729 View
  • 2610 Score
  • 21 Answer
  • Tags:   c# enums casting

58 Answered Questions

[SOLVED] What is the difference between String and string in C#?

29 Answered Questions

[SOLVED] How to create an HTML button that acts like a link?

25 Answered Questions

[SOLVED] Get int value from enum in C#

  • 2009-06-03 06:46:39
  • jim
  • 1137649 View
  • 1402 Score
  • 25 Answer
  • Tags:   c# enums casting int

64 Answered Questions

[SOLVED] How do I calculate someone's age in C#?

  • 2008-07-31 23:40:59
  • Jeff Atwood
  • 485323 View
  • 1743 Score
  • 64 Answer
  • Tags:   c# .net datetime

25 Answered Questions

[SOLVED] Trigger a button click with JavaScript on the Enter key in a text box

9 Answered Questions

[SOLVED] What are the correct version numbers for C#?

15 Answered Questions

[SOLVED] <button> vs. <input type="button" />. Which to use?

296 Answered Questions

[SOLVED] Hidden Features of C#?

  • 2008-08-12 16:32:24
  • Serhat Ozgel
  • 622395 View
  • 1476 Score
  • 296 Answer
  • Tags:   c# hidden-features

Sponsored Content