Click here to Skip to main content
16,008,010 members
Home / Discussions / C#
   

C#

 
QuestionRe: Set Control Values on Form from other class Pin
Programm3r18-Jun-09 23:55
Programm3r18-Jun-09 23:55 
AnswerRe: Set Control Values on Form from other class Pin
dan!sh 19-Jun-09 2:41
professional dan!sh 19-Jun-09 2:41 
AnswerRe: Set Control Values on Form from other class Pin
I Believe In GOD18-Jun-09 23:54
I Believe In GOD18-Jun-09 23:54 
GeneralRe: Set Control Values on Form from other class Pin
Christian Graus19-Jun-09 0:00
protectorChristian Graus19-Jun-09 0:00 
QuestionRe: Set Control Values on Form from other class Pin
Programm3r19-Jun-09 0:02
Programm3r19-Jun-09 0:02 
AnswerRe: Set Control Values on Form from other class Pin
DaveyM6919-Jun-09 0:28
professionalDaveyM6919-Jun-09 0:28 
QuestionRe: Set Control Values on Form from other class Pin
Programm3r19-Jun-09 1:21
Programm3r19-Jun-09 1:21 
AnswerRe: Set Control Values on Form from other class Pin
DaveyM6919-Jun-09 1:54
professionalDaveyM6919-Jun-09 1:54 
This is a quickie example that should help to get you started. For more details on events, search this site, google... and have a look at my article Events Made Simple[^].
// Assumes form already contains a Label (label1).
public partial class WinForm : Form
{
    private Calc calc;
    public WinForm()
    {
        InitializeComponent();
        calc = new Calc();
        calc.CalcResult += new EventHandler<CalcResultEventArgs>(calc_CalcResult);
        calc.Add(3.14159265f);
    }

    void calc_CalcResult(object sender, CalcResultEventArgs e)
    {
        label1.Text = e.ResultAsString;
    }
}

public class Calc
{
    public event EventHandler<CalcResultEventArgs> CalcResult;

    public float Value
    {
        get;
        private set;
    }

    public void Add(float number)
    {
        Value += number;
        OnCalcResult(new CalcResultEventArgs(Value.ToString()));
    }

    protected virtual void OnCalcResult(CalcResultEventArgs e)
    {
        EventHandler<CalcResultEventArgs> eh = CalcResult;
        if (eh != null)
            eh(this, e);
    }
}

public class CalcResultEventArgs : EventArgs
{
    public CalcResultEventArgs(string resultAsString)
    {
        ResultAsString = resultAsString;
    }

    public string ResultAsString
    {
        get;
        private set;
    }
}


Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
Why are you using VB6? Do you hate yourself? (Christian Graus)

GeneralRe: Set Control Values on Form from other class Pin
Programm3r19-Jun-09 1:56
Programm3r19-Jun-09 1:56 
AnswerRe: Set Control Values on Form from other class Pin
Rob Philpott19-Jun-09 1:44
Rob Philpott19-Jun-09 1:44 
GeneralRe: Set Control Values on Form from other class Pin
Programm3r19-Jun-09 1:59
Programm3r19-Jun-09 1:59 
QuestionVisual Studio 2005 method error Pin
Jem_Jumper18-Jun-09 23:29
Jem_Jumper18-Jun-09 23:29 
AnswerRe: Visual Studio 2005 method error Pin
dan!sh 18-Jun-09 23:35
professional dan!sh 18-Jun-09 23:35 
QuestionHow to run .NET application in Fedora 6(Linux) Pin
Member 305788718-Jun-09 23:12
Member 305788718-Jun-09 23:12 
AnswerRe: How to run .NET application in Fedora 6(Linux) Pin
Rob Philpott18-Jun-09 23:14
Rob Philpott18-Jun-09 23:14 
AnswerRe: How to run .NET application in Fedora 6(Linux) Pin
Simon P Stevens18-Jun-09 23:15
Simon P Stevens18-Jun-09 23:15 
QuestionSoftware Process Change Best Practices Pin
DeveloperZero18-Jun-09 22:49
DeveloperZero18-Jun-09 22:49 
AnswerRe: Software Process Change Best Practices Pin
Eddy Vluggen18-Jun-09 22:56
professionalEddy Vluggen18-Jun-09 22:56 
QuestionNested try/catch blocks Pin
Helfdane18-Jun-09 22:35
Helfdane18-Jun-09 22:35 
AnswerRe: Nested try/catch blocks Pin
Christian Graus18-Jun-09 22:41
protectorChristian Graus18-Jun-09 22:41 
GeneralRe: Nested try/catch blocks Pin
Helfdane18-Jun-09 22:45
Helfdane18-Jun-09 22:45 
JokeRe: Nested try/catch blocks Pin
DaveyM6918-Jun-09 22:49
professionalDaveyM6918-Jun-09 22:49 
GeneralRe: Nested try/catch blocks Pin
Helfdane18-Jun-09 22:53
Helfdane18-Jun-09 22:53 
GeneralOT Pin
Vikram A Punathambekar18-Jun-09 23:59
Vikram A Punathambekar18-Jun-09 23:59 
AnswerRe: Nested try/catch blocks Pin
Nagy Vilmos18-Jun-09 22:58
professionalNagy Vilmos18-Jun-09 22:58 

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.