Click here to Skip to main content
15,887,135 members
Home / Discussions / C#
   

C#

 
GeneralRe: LDAP Question Pin
mypicturefaded9-Jul-09 8:54
mypicturefaded9-Jul-09 8:54 
GeneralRe: LDAP Question Pin
Manas Bhardwaj9-Jul-09 8:57
professionalManas Bhardwaj9-Jul-09 8:57 
QuestionPassing a Method to a second form Pin
bwood20209-Jul-09 7:13
bwood20209-Jul-09 7:13 
AnswerRe: Passing a Method to a second form Pin
harold aptroot9-Jul-09 7:25
harold aptroot9-Jul-09 7:25 
GeneralRe: Passing a Method to a second form Pin
bwood20209-Jul-09 7:28
bwood20209-Jul-09 7:28 
GeneralRe: Passing a Method to a second form Pin
harold aptroot9-Jul-09 7:35
harold aptroot9-Jul-09 7:35 
GeneralRe: Passing a Method to a second form Pin
bwood20209-Jul-09 7:38
bwood20209-Jul-09 7:38 
AnswerRe: Passing a Method to a second form Pin
DaveyM699-Jul-09 7:32
professionalDaveyM699-Jul-09 7:32 
Form1 MainForm = new Form1(); is not going to work as it's a new instance of Form1, not the one that you started with.

The recommended way of doing this is to raise a custom event in form2, that Form1 subscribes to, so Form1 calls its own method.
using System;
using System.Windows.Forms;

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void buttonShowForm2_Click(object sender, EventArgs e)
    {
        Form2 form2 = new Form2();
        form2.DoUpdate += new EventHandler(form2_DoUpdate);
        form2.Show();
    }

    void form2_DoUpdate(object sender, EventArgs e)
    {
        // Do your thing here
        Console.Write("Update");
    }
}
using System;
using System.Windows.Forms;

public partial class Form2 : Form
{
    public event EventHandler DoUpdate;

    public Form2()
    {
        InitializeComponent();
    }

    void buttonUpdate_Click(object sender, EventArgs e)
    {
        OnDoUpdate(EventArgs.Empty);
    }

    protected virtual void OnDoUpdate(EventArgs e)
    {
        EventHandler eh = DoUpdate;
        if (eh != null)
            eh(this, e);
        Close();
    }
}
If you need to pass data along with the event, create your own class derived from EventArgs and pass an instance of that instead of EventArgs.Empty. You will need to change the EventHandler to EventHandler<YourEventArgs>

See my Events Made Simple[^] article for more details.

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: Passing a Method to a second form Pin
bwood20209-Jul-09 7:47
bwood20209-Jul-09 7:47 
AnswerRe: Passing a Method to a second form Pin
Patrik.karlin9-Jul-09 7:38
Patrik.karlin9-Jul-09 7:38 
GeneralRe: Passing a Method to a second form Pin
DaveyM699-Jul-09 7:46
professionalDaveyM699-Jul-09 7:46 
GeneralRe: Passing a Method to a second form Pin
Patrik.karlin9-Jul-09 8:11
Patrik.karlin9-Jul-09 8:11 
GeneralRe: Passing a Method to a second form Pin
Henry Minute9-Jul-09 9:39
Henry Minute9-Jul-09 9:39 
GeneralRe: Passing a Method to a second form Pin
bwood20209-Jul-09 10:21
bwood20209-Jul-09 10:21 
Question[Message Deleted] Pin
VivekUtsa9-Jul-09 7:05
VivekUtsa9-Jul-09 7:05 
AnswerRe: Browser compatability Issues Pin
Dave Kreskowiak9-Jul-09 7:46
mveDave Kreskowiak9-Jul-09 7:46 
GeneralRe: Browser compatability Issues Pin
Manas Bhardwaj9-Jul-09 8:33
professionalManas Bhardwaj9-Jul-09 8:33 
QuestionHow do I retreive and interface's IP Address(es) when starting only with "Friendly Adapter Name" Pin
Vengeful Emus9-Jul-09 6:56
Vengeful Emus9-Jul-09 6:56 
GeneralRe: How do I retreive and interface's IP Address(es) when starting only with "Friendly Adapter Name" Pin
harold aptroot9-Jul-09 7:20
harold aptroot9-Jul-09 7:20 
GeneralRe: How do I retreive and interface's IP Address(es) when starting only with "Friendly Adapter Name" Pin
Vengeful Emus9-Jul-09 7:38
Vengeful Emus9-Jul-09 7:38 
GeneralRe: How do I retreive and interface's IP Address(es) when starting only with "Friendly Adapter Name" [modified*2] Pin
harold aptroot9-Jul-09 7:44
harold aptroot9-Jul-09 7:44 
GeneralRe: How do I retreive and interface's IP Address(es) when starting only with "Friendly Adapter Name" [modified*2] Pin
Dave Kreskowiak9-Jul-09 10:31
mveDave Kreskowiak9-Jul-09 10:31 
GeneralRe: How do I retreive and interface's IP Address(es) when starting only with "Friendly Adapter Name" Pin
harold aptroot9-Jul-09 10:39
harold aptroot9-Jul-09 10:39 
GeneralRe: How do I retreive and interface's IP Address(es) when starting only with "Friendly Adapter Name" [modified] Pin
Dave Kreskowiak9-Jul-09 7:51
mveDave Kreskowiak9-Jul-09 7:51 
GeneralRe: How do I retreive and interface's IP Address(es) when starting only with "Friendly Adapter Name" Pin
harold aptroot9-Jul-09 8:05
harold aptroot9-Jul-09 8:05 

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.