lompa Posted February 22, 2004 Posted February 22, 2004 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 Quote
Moderators Robby Posted February 22, 2004 Moderators Posted February 22, 2004 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()); } Quote Visit...Bassic Software
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.