Click here to Skip to main content
15,912,665 members
Home / Discussions / C#
   

C#

 
QuestionSet Standard Input to a File Stream Pin
skatzteyp8-Jul-08 16:30
skatzteyp8-Jul-08 16:30 
AnswerRe: Set Standard Input to a File Stream Pin
Judah Gabriel Himango8-Jul-08 16:59
sponsorJudah Gabriel Himango8-Jul-08 16:59 
GeneralRe: Set Standard Input to a File Stream Pin
skatzteyp8-Jul-08 17:23
skatzteyp8-Jul-08 17:23 
GeneralRe: Set Standard Input to a File Stream Pin
leppie8-Jul-08 20:47
leppie8-Jul-08 20:47 
GeneralRe: Set Standard Input to a File Stream Pin
skatzteyp8-Jul-08 21:25
skatzteyp8-Jul-08 21:25 
GeneralRe: Set Standard Input to a File Stream Pin
leppie8-Jul-08 22:34
leppie8-Jul-08 22:34 
GeneralRe: Set Standard Input to a File Stream Pin
skatzteyp8-Jul-08 22:39
skatzteyp8-Jul-08 22:39 
QuestionNuclear reactor meltdown immenent, delegates and events. Pin
MAW308-Jul-08 15:15
MAW308-Jul-08 15:15 
The following is an example of delegates and events I found in a book with a few modifications. I am having trouble trying to make the program work using Delegates, I am trying to insert a message from one class to another classes ListBox. Please help before the reactor goes critical. I’d appreciate any help, please be specific.

Do All Delegates need to be instantiated in the Main menu as every example I see does.

Thanks,
Michael


namespace ReactorDelegates
{
// Declaration of Delegate
public delegate void DelegateReactorMessage(String message);
public delegate void DelegatebuttonStart_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);

//Reactor myReactor = new Reactor();
//ReactorMonitor myReactorMonitor = new ReactorMonitor(myReactor);
//FormReactor FR = new FormReactor();
//FormStartReactor FSR = new FormStartReactor();

Application.Run(new FormStartReactor());
//new FormReactor(),
// Instantiation of Delegate
//DelegateReactorMessage delegateReactorMessage = new DelegateReactorMessage(FR.ReactorMessage);
//DelegatebuttonStart_Click delegatebuttonStart_Click = new DelegatebuttonStart_Click(FSR.buttonStart_Click);
}
}
}

namespace ReactorDelegates
{
public partial class FormStartReactor : Form
{
static FormReactor FR = new FormReactor();
DelegateReactorMessage delegateReactorMessage = new DelegateReactorMessage(FR.ReactorMessage);
String message;

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);

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

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

// Set myReactor to 2000 degrees Celcius
message = "Setting reactor temperature to 3000 degrees Celcius";
delegateReactorMessage(message);
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
{
//static Reactor myReactor = new Reactor();
//ReactorMonitor myReactorMonitor = new ReactorMonitor(myReactor);
//static FormStartReactor FSR = new FormStartReactor();
//DelegatebuttonStart_Click delegatebuttonStart_Click = new DelegatebuttonStart_Click(FSR.buttonStart_Click);

public FormReactor()
{
InitializeComponent();

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

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

private void buttonBegin_Click(object sender, EventArgs e)
{
String startMessage = "Start Reactor";
ReactorMessage(startMessage);

//delegatebuttonStart_Click(sender, e);
}
}
}

namespace ReactorDelegates
{
class ReactorMonitor
{
static FormReactor FR = new FormReactor();
DelegateReactorMessage delegateReactorMessage = new DelegateReactorMessage(FR.ReactorMessage);

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

public void DisplayMessage(Object myReactor, MeltdownEventArgs myMEA)
{
FormReactor FR = new FormReactor();
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;
}
}
}
}
AnswerRe: Nuclear reactor meltdown immenent, delegates and events. Pin
Judah Gabriel Himango8-Jul-08 16:10
sponsorJudah Gabriel Himango8-Jul-08 16:10 
GeneralRe: Nuclear reactor meltdown immenent, delegates and events. Pin
MAW308-Jul-08 17:14
MAW308-Jul-08 17:14 
GeneralRe: Nuclear reactor meltdown immenent, delegates and events. Pin
N a v a n e e t h8-Jul-08 22:47
N a v a n e e t h8-Jul-08 22:47 
QuestionHi Pin
Member 39180288-Jul-08 13:18
Member 39180288-Jul-08 13:18 
AnswerRe: Hi Pin
DaveyM698-Jul-08 13:45
professionalDaveyM698-Jul-08 13:45 
AnswerRe: Hi Pin
Christian Graus8-Jul-08 14:27
protectorChristian Graus8-Jul-08 14:27 
GeneralRe: Hi Pin
Paul Conrad8-Jul-08 15:36
professionalPaul Conrad8-Jul-08 15:36 
AnswerRe: Hi Pin
Alan Balkany9-Jul-08 5:01
Alan Balkany9-Jul-08 5:01 
Questionrun some event after the form has been loaded Pin
netJP12L8-Jul-08 10:09
netJP12L8-Jul-08 10:09 
AnswerRe: run some event after the form has been loaded Pin
Gareth H8-Jul-08 10:24
Gareth H8-Jul-08 10:24 
GeneralRe: run some event after the form has been loaded Pin
netJP12L8-Jul-08 10:54
netJP12L8-Jul-08 10:54 
GeneralRe: run some event after the form has been loaded Pin
DaveyM698-Jul-08 10:59
professionalDaveyM698-Jul-08 10:59 
AnswerRe: run some event after the form has been loaded Pin
PIEBALDconsult8-Jul-08 10:51
mvePIEBALDconsult8-Jul-08 10:51 
Questionloading the header of document file Pin
Miss_hacker8-Jul-08 10:02
Miss_hacker8-Jul-08 10:02 
AnswerRe: loading the header of document file Pin
Nitrus8-Jul-08 10:20
Nitrus8-Jul-08 10:20 
JokeRe: loading the header of document file Pin
PIEBALDconsult8-Jul-08 10:57
mvePIEBALDconsult8-Jul-08 10:57 
GeneralRe: loading the header of document file Pin
leppie8-Jul-08 20:50
leppie8-Jul-08 20:50 

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.