|
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)
{
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.
DaveBTW, 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)
|
|
|
|
|
Thank you for your reply. That works perfectly.
|
|
|
|
|
Hej bwood2020
You Migth whant to use a static resource that can laungh that form1 passes an event to
static class EventHandler
{
static Action Event;
public static void SetGlobalEvent(Action a)
{
Event = a;
}
public static void Execute_Event()
{
Event();
}
}
class Form1
{
public Form1()
{
EventHandler.SetGlobalEvent(Event);
}
public void Event()
{
var x = 2 + 2;
}
}
class Form2
{
public void Onclick()
{
EventHandler.Execute_Event();
this.Destroy();
}
}
There migth be a bether way of doing this if form1 creates form2 you can pass
in "this" from form1 as a parameter that way form2 whill be able to call the method on that object
Hopes this helps Patrik
|
|
|
|
|
Patrik.karlin wrote: if form1 creates form2 you can pass
in "this" from form1 as a parameter
... but now you're starting to couple unrelated classes - not a great idea. The easiest, sure - but best avoided.
DaveBTW, 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)
|
|
|
|
|
DaveyM69 wrote: ... but now you're starting to couple unrelated classes - not a great idea. The easiest, sure - but best avoided.
.... Yea Sure .. maybe the logic should be in the model....
form1 can subscribe to a datachanged event and form2 youst update's the
data in the model...
then they whill be completle seperated.
|
|
|
|
|
Does this look at all familiar? clickety[^]
[Edit]
Sorry wrong link! Try this one. here[^]
[/Edit]
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hi Henry,
It does and I tried to aply the same logic but it wasn't working. The code I used to get this to work was differnt. I think it had to do with adding another event handler to take care of it.
|
|
|
|
|
|
You're looking for the ASP.NET forum. What you asked has nothing to do with C#.
|
|
|
|
|
Dave Kreskowiak wrote: You're looking for the ASP.NET forum
Ftfy, Web Development
Manas Bhardwaj
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
Please, help.... or suggest approach; this is a second posting.
I'm sure that there have been a thousand questions on this topic, but here goes...
I have an application that uses the System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces() to retreive each friendly interface name on a machine with multiple adapters. Later, depending on other choices, the application needs to start UDP multicasting. For this I need to be able to find the IP address of the interface chosen. As I said, all I have is the friendly adpter name. How can retreive the IP address(es) of the NIC starting only the adapter name?
Raven
|
|
|
|
|
Get all interfaces again and search for the one with the right name?
|
|
|
|
|
The call that provices the adapter names has no option to produce the IP addresses assigned to the interface... therein lies the problem--how to find the IP addresses associated with the network interface
|
|
|
|
|
IIRC they are in the same order as returned by Dns.GetHostAddresses
That worked for me, anyway.
would the person who 1-voted me care to explain why? Did I remember incorrectly? (couldn't you just have told me so?) Last modified: 18mins after originally posted --
|
|
|
|
|
It lokos like you got hit by a Drive-By Univoter...
|
|
|
|
|
Yes it would seem so.. he didn't drive around the rest of the forum too much though lol
|
|
|
|
|
When you call GetAllNetworkInterfaces , each instance of the NetworkInterface object you get back has a GetIpProperties method. Call that method on each interface and you'll get an IpInterfaceProperties object with all the IP address details in it for that adapter.
modified on Thursday, July 9, 2009 4:29 PM
|
|
|
|
|
That would be better than my less-than-reliable approach.
|
|
|
|
|
Hi Harold,
I'm not the one that onevoted you, however since I liked your latest message much more than the previous one, here is a 5.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
I'm writing a Windows Mobile 6 application in C#.NET. how can i search for wifi connections nearby and get ip
This code was posted by me...
|
|
|
|
|
|
1 want to list all wi-fi network connections using C#.
This code was posted by me...
|
|
|
|
|
Try a google search.[^]
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
|
|
|
|
|
I love it, I thought I'll take a look at the results for this one. 1st link is to CP, straight back to this message
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Yeah,it's intersing result search
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
|
|
|
|