GUI - class - dataclass


A

Anders Eriksson

I have an application that has a dataclass which have an event for error
messages

// Event handler for passing error messages to GUI

public delegate void ErrorMsgHandler(object Sender, ErrorMsgArgs e);

public event ErrorMsgHandler ErrorMsgEvent;

public class ErrorMsgArgs : EventArgs
{
/// <summary>
/// Initializes a new instance of the <see cref="ErrorMsgArgs"/> class.
/// </summary>
/// <param name="s">The s.</param>
public ErrorMsgArgs(string s) { Text = s; }

/// <summary>
/// Gets the text.
/// </summary>
public String Text { get; private set; } // readonly
}

private void RaiseErrorMsgEvent(string msg)
{
// Raise the event by using the () operator.
if (ErrorMsgEvent != null)
ErrorMsgEvent(this, new ErrorMsgArgs(msg));
}

This worked perfectly when I used the GUI class(WinForm or WPF) to
connect to the ErrorMsgEvent

le.ErrorMsgEvent += new LEngine.ErrorMsgHandler(le_ErrorMsgEvent);

le is the object that contains the event...

I have now put a class between the dataclass and the GUI class, it's
called DCMarkerScript. This so that the GUI class don't access the data
directly.

How do I forward the ErrorMsgEvent from the dataclass via the
DCMarkerScript class to the GUI Class?

// Anders
 
Ad

Advertisements

A

Anders Eriksson

Taking your question literally, the obvious answer would be to
re-implement the event in your DCMarkerScript class, and have it raise
that event when its own handler of the ErrorMsgEvent is called.

OK, I did this and it worked perfectly!
For what it's worth, you may find it useful to more closely follow the
.NET naming conventions. This makes your code more easily understood by
other readers, for those elements of the code that idiomatic in .NET.

Where can I find some document about .NET naming conventions?
Finally, I would avoid bothering to include XML comments in your code
examples posted here, especially when those XML comments don't actually
explain anything (e.g. "The s."). They just take up room, and make it
harder to read the code itself. :)
Sorry about that. I was (as always) in a hurry, and missed the comments
that where left.

Thank you very much for your answers!

// Anders
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top