Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

i know how to add a class to my program, but i dont know how to link my main form to different classes, all the guides on the internet are hard to understand.

 

all i am trying to do is get a message box to pop up when i click button1, but the code for the message box is in class1.cs

 

 

so in the main form under button1 click what do i type?

 

 

 

 

 

in class1.cs i have the following

 

public Class1()

{

MessageBox.Show("Program developed by me Nov 2003", "Information");

}

 

thanks

 

if anyone knows of simple guides to writing in classes for C# preferably not console mode can you post below

  • Moderators
Posted

The messagebox should be in the form not the class. The class should return a value, there are a few way of doing this, here's one:

 

//This is in the Class:
public class Class1
{
	public string SomeMessage() {
		return "Hello from Class1";
	}
}

//This is in the form:

private void button1_Click(object sender, System.EventArgs e) {
		Class1 c = new Class1();
		MessageBox.Show( c.SomeMessage());
	}

Visit...Bassic Software

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...