Click here to Skip to main content
14,872,052 members
Home / Discussions / C#
   

C#

 
QuestionRe: Select particular types tool and then change their properties at a time,How? Pin
zeeShan anSari9-Jul-08 9:08
MemberzeeShan anSari9-Jul-08 9:08 
AnswerRe: Select particular types tool and then change their properties at a time,How? Pin
hammerstein059-Jul-08 9:12
Memberhammerstein059-Jul-08 9:12 
GeneralRe: Select particular types tool and then change their properties at a time,How? Pin
zeeShan anSari9-Jul-08 9:19
MemberzeeShan anSari9-Jul-08 9:19 
Question[Message Deleted] Pin
MAW309-Jul-08 7:53
MemberMAW309-Jul-08 7:53 
AnswerRe: Message insertion to ListBox from another class using Delegates and Events Pin
Christian Graus9-Jul-08 8:16
protectorChristian Graus9-Jul-08 8:16 
GeneralRe: Message insertion to ListBox from another class using Delegates and Events Pin
MAW309-Jul-08 8:46
MemberMAW309-Jul-08 8:46 
GeneralRe: Message insertion to ListBox from another class using Delegates and Events Pin
Christian Graus9-Jul-08 9:35
protectorChristian Graus9-Jul-08 9:35 
GeneralRe: Message insertion to ListBox from another class using Delegates and Events Pin
MAW309-Jul-08 9:49
MemberMAW309-Jul-08 9:49 
Everything compiles and runs but nothing happens when the delegate runs the buttonBegin, I expected to see "Start Reactor" as I would when I click on the button itself. Here is an updated copy, which is what I originally had before playing with it to try different ideas.

Thanks,
Michael


namespace ReactorDelegates
{
public delegate void DelegateReactorMessage(String message);
public delegate void DelegatebuttonStart_Click(object sender, EventArgs e);
public delegate void DelegatebuttonBegin_Click(object sender, EventArgs e);

static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
public static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FormStartReactor());
//new FormReactor(),
}
}


namespace ReactorDelegates
{
public partial class FormStartReactor : Form
{
static FormReactor FR = new FormReactor();
Action<String> delegateReactorMessage = FR.ReactorMessage;
DelegatebuttonBegin_Click delegatebuttonBegin = new DelegatebuttonBegin_Click(FR.buttonBegin_Click);

public FormStartReactor()
{
InitializeComponent();
}

public void buttonStart_Click(object sender, EventArgs e)
{
FormReactor FR = new FormReactor();
Reactor myReactor = new Reactor();
ReactorMonitor myReactorMonitor = new ReactorMonitor(myReactor);
reactorToolStripMenuItem_Click(sender, e);
delegatebuttonBegin(sender, e);

// Set myReactor to 100 degrees Celcius
delegateReactorMessage("Setting reactor temperature to 100 degrees Celcius");
myReactor.Temperature = 100;

// Set myReactor to 500 degrees Celcius
delegateReactorMessage("Setting reactor temperature to 1500 degrees Celcius");
myReactor.Temperature = 1500;

// Set myReactor to 2000 degrees Celcius
delegateReactorMessage("Setting reactor temperature to 3000 degrees Celcius");
myReactor.Temperature = 3000;
}

private void reactorToolStripMenuItem_Click(object sender, EventArgs e)
{
FormReactor mdiChildForm = new FormReactor();
mdiChildForm.MdiParent = this;
mdiChildForm.Show();
}
}
}


namespace ReactorDelegates
{
public partial class FormReactor : Form
{

public FormReactor()
{
InitializeComponent();

this.listBoxReactor.Items.Clear();
this.listBoxReactor.Items.AddRange(new object[] {"Reactor down"});
}

public void ReactorMessage(String message)
{
listBoxReactor.BeginUpdate();
listBoxReactor.Items.Add(message);
listBoxReactor.EndUpdate();
}

public void buttonBegin_Click(object sender, EventArgs e)
{
ReactorMessage("Start Reactor");
}
}
}


namespace ReactorDelegates
{
class ReactorMonitor
{
static FormReactor FR = new FormReactor();
Action<String> delegateReactorMessage = FR.ReactorMessage;

public ReactorMonitor(Reactor myReactor)
{
myReactor.OnMeltdown += new Reactor.MeltdownHandler(DisplayMessage);
}

public void DisplayMessage(Object myReactor, MeltdownEventArgs myMEA)
{
String message = myMEA.Message;
delegateReactorMessage(message);
}
}
}


namespace ReactorDelegates
{
class Reactor
{
Int32 temperature;
String strReactorMessage;

public delegate void MeltdownHandler(Object reactor, MeltdownEventArgs myMEA);

public event MeltdownHandler OnMeltdown;


public Int32 Temperature
{
set
{
temperature = value;
if (temperature > 1000)
{
if (temperature < 2000)
{
strReactorMessage = "Reactor meltdown in progress";
}
else
{
strReactorMessage = "The reactor is critical, YOU ARE DEAD, DEAD, DEAD";
}

MeltdownEventArgs myMEA = new MeltdownEventArgs(strReactorMessage);
OnMeltdown(this, myMEA);
}
}
}
}
}


namespace ReactorDelegates
{
class MeltdownEventArgs : EventArgs
{
String message;

public MeltdownEventArgs(String message)
{
this.message = message;
}

public String Message
{
get
{
return message;
}
}
}
}
QuestionUnlimited List Pin
Saksida Bojan9-Jul-08 7:35
MemberSaksida Bojan9-Jul-08 7:35 
AnswerRe: Unlimited List Pin
Christian Graus9-Jul-08 7:39
protectorChristian Graus9-Jul-08 7:39 
GeneralRe: Unlimited List Pin
Saksida Bojan9-Jul-08 7:44
MemberSaksida Bojan9-Jul-08 7:44 
GeneralRe: Unlimited List Pin
User 66589-Jul-08 7:55
MemberUser 66589-Jul-08 7:55 
GeneralRe: Unlimited List Pin
Saksida Bojan9-Jul-08 8:16
MemberSaksida Bojan9-Jul-08 8:16 
GeneralRe: Unlimited List Pin
User 66589-Jul-08 8:53
MemberUser 66589-Jul-08 8:53 
GeneralRe: Unlimited List Pin
Christian Graus9-Jul-08 8:13
protectorChristian Graus9-Jul-08 8:13 
GeneralRe: Unlimited List Pin
Saksida Bojan9-Jul-08 8:18
MemberSaksida Bojan9-Jul-08 8:18 
GeneralRe: Unlimited List Pin
Christian Graus9-Jul-08 8:40
protectorChristian Graus9-Jul-08 8:40 
GeneralRe: Unlimited List Pin
Saksida Bojan9-Jul-08 8:56
MemberSaksida Bojan9-Jul-08 8:56 
GeneralRe: Unlimited List Pin
#realJSOP9-Jul-08 9:12
mva#realJSOP9-Jul-08 9:12 
GeneralRe: Unlimited List Pin
Saksida Bojan9-Jul-08 9:21
MemberSaksida Bojan9-Jul-08 9:21 
GeneralRe: Unlimited List Pin
Dave Kreskowiak9-Jul-08 10:15
mveDave Kreskowiak9-Jul-08 10:15 
GeneralRe: Unlimited List Pin
Saksida Bojan10-Jul-08 8:31
MemberSaksida Bojan10-Jul-08 8:31 
GeneralRe: Unlimited List Pin
leppie9-Jul-08 21:05
Memberleppie9-Jul-08 21:05 
GeneralRe: Unlimited List Pin
#realJSOP9-Jul-08 23:19
mva#realJSOP9-Jul-08 23:19 
QuestionTrying to Print a file from C# code...NEWBIE Pin
zachbob9-Jul-08 7:35
Memberzachbob9-Jul-08 7:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.