TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
wone
NA
7
0
Problem between event and displaying data in a form.
Jan 11 2009 6:32 AM
Hi,
I want to cath an event thrown by the class "Class1" in the class "Form1" to display data in the textbox1. Even though the code pass by the eventhandler, as a messageBox pop-up, can someone tell me why I can't see the text "connected!", in the textbox1?
Thanks.
namespace WindowsFormsApplication1
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
namespace WindowsFormsApplication1
{
class Class1
{
public delegate void Connected_EventHandler();
public static event Connected_EventHandler OnConnected;
public void connect()
{
Form1 f = new Form1();
OnConnected += new Connected_EventHandler(f.onConnectedEventHandler);
DoSomething();
}
private void DoSomething()
{
if (OnConnected != null)
{
OnConnected();
}
}
}
}
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
Class1 cl = new Class1();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
cl.connect();
// textBox1.Text = "connected!"; If I uncomment this line, the textbox display the text
}
public void onConnectedEventHandler()
{
//MessageBox.Show("HELLO"); If I uncomment this line, the message pop-up
textBox1.Text = "connected!"; // The textbox doesn't display the data!
}
}
}
Reply
Answers (
2
)
Somebody help me on sending e-mails please
Install SQL Server on Vista