beginner struggling with classes C# VS.NET

lompa

Member
Joined
Feb 17, 2004
Messages
6
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
 
The messagebox should be in the form not the class. The class should return a value, there are a few way of doing this, heres one:

C#:
//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());
		}
 
Back
Top