I've been doing asp.net for so long now that I have forgotten about
windows form programming so excuse this (seemingly) basic question.
I have a form A which then opens up form B. I do stuff on form B after
which I hit a close button. I want to run a method on form A as I
close form B. I don't need to pass data back (though I like to know
how this is done), just run a refresh type method back on form B.
I've got bogged down in delegates and code samples, this must be easy
right?
thanks 12 13152
> I have a form A which then opens up form B. I do stuff on form B after which I hit a close button. I want to run a method on form A as I close form B. I don't need to pass data back (though I like to know how this is done), just run a refresh type method back on form B.
I would imagine you really want access to Form B. If you prevent
the form from actually closing, and simply force it to Hide, the resources
will still be available and you can get your information back.
Further, if you show the Form B using ShowDialog, this step is handled
for you automatically. The form is not disposed fully, and in turn can
be reshown.
Then you can just access you information from properties.
--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers
Thanks for the reply, but in this case I don't need access to data from
the other form. Form B updates a datastore, then closes, then I just
want Form A to "Obtain the latest data". I have a method in form A do
to this, I just can't figure out a way to generate an event to run the
method.
Well, let's fix that up then:
public class FormA : Form {
private void DoIt() {
FormB b = new FormB();
b.DataUpdated += new EventHandler(Da taStore_Updated );
b.Show();
}
// Have a handler for the event
}
public class FormB: Form {
public event EventHandler DataUpdated;
private void OnDataUpdated(E ventArgs e) {
if ( DataUpdated != null )
DataUpdated(thi s, e);
}
}
// Just call OnDataUpdated when you are closing
}
Another option is an eventing business layer... If you are performing
multiple actions though, this can result in more than a single call. The
alternative is to add a transactional model so that you get a token when
you start updating, and you use that to end your update, then the event
that the data store is updated is fired.
--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers
<ri************ @orcon.net.nz> wrote in message
news:10******** **************@ c13g2000cwb.goo glegroups.com.. . Thanks for the reply, but in this case I don't need access to data from the other form. Form B updates a datastore, then closes, then I just want Form A to "Obtain the latest data". I have a method in form A do to this, I just can't figure out a way to generate an event to run the method.
Should probably add some invocation logic just in case:
private void DataStore_Updat ed(object sender, EventArgs e) {
this.BeginInvok e(...); // This ensures that if the event is being invoked on
another thread, very unlikely, but hell.
// Another item is, you may want the event to be invoked after Form B has
completely closed, in which
// case you want the async behavior of BeginInvoke anyway.
}
"Justin Rogers" <Ju****@games4d otnet.com> wrote in message
news:eG******** ******@TK2MSFTN GP12.phx.gbl... Well, let's fix that up then:
public class FormA : Form { private void DoIt() { FormB b = new FormB(); b.DataUpdated += new EventHandler(Da taStore_Updated ); b.Show(); }
// Have a handler for the event }
public class FormB: Form { public event EventHandler DataUpdated;
private void OnDataUpdated(E ventArgs e) { if ( DataUpdated != null ) DataUpdated(thi s, e); } }
// Just call OnDataUpdated when you are closing }
Another option is an eventing business layer... If you are performing multiple actions though, this can result in more than a single call. The alternative is to add a transactional model so that you get a token when you start updating, and you use that to end your update, then the event that the data store is updated is fired.
-- Justin Rogers DigiTec Web Consultants, LLC. Blog: http://weblogs.asp.net/justin_rogers
<ri************ @orcon.net.nz> wrote in message news:10******** **************@ c13g2000cwb.goo glegroups.com.. . Thanks for the reply, but in this case I don't need access to data from the other form. Form B updates a datastore, then closes, then I just want Form A to "Obtain the latest data". I have a method in form A do to this, I just can't figure out a way to generate an event to run the method.
Justin,
I thought monday morning may help me but alas not. This is what I have
so far along the lines you suggested so I hope you can have a quick
check for me. It won't compile - it tells me that getCurrentPrint ers()
does not match delegate - void System.EventHan dler(object,
System.EventArg s)
public class FormA : Form {
private void lnkAdd_LinkClic ked(object sender,
System.Windows. Forms.LinkLabel LinkClickedEven tArgs e)()
{
AddPrinter addform = new AddPrinter();
addform.DataUpd ated += new EventHandler(ge tCurrentPrinter s);
addform.Show();
}
private void GetInstalledPri nters()
{
// do stuff
}
}
and in formB
public class AddPrinter : Form
{
public event EventHandler DataUpdated;
private void OnDataUpdated(E ventArgs e)
{
if ( DataUpdated != null )
{
DataUpdated(thi s, e);
}
}
public void btnAdd_Click(ob ject sender, System.EventArg s e)
{
OnDataUpdated(e );
this.Close();
}
}
<ri************ @orcon.net.nz> wrote in message
news:10******** **************@ c13g2000cwb.goo glegroups.com.. . Justin, I thought monday morning may help me but alas not. This is what I have so far along the lines you suggested so I hope you can have a quick check for me. It won't compile - it tells me that getCurrentPrint ers() does not match delegate - void System.EventHan dler(object, System.EventArg s)
public class FormA : Form { private void lnkAdd_LinkClic ked(object sender, System.Windows. Forms.LinkLabel LinkClickedEven tArgs e)() { AddPrinter addform = new AddPrinter(); addform.DataUpd ated += new EventHandler(ge tCurrentPrinter s); addform.Show(); }
private void GetInstalledPri nters() { // do stuff } }
and in formB
public class AddPrinter : Form { public event EventHandler DataUpdated;
private void OnDataUpdated(E ventArgs e) { if ( DataUpdated != null ) { DataUpdated(thi s, e); } }
public void btnAdd_Click(ob ject sender, System.EventArg s e) { OnDataUpdated(e ); this.Close(); } }
The error message is correct. The getInstalledPri nters requires 2 parameters
(object sender, EventArgs e). When using delegates the VS IDE will create
the function for you to avoid these mistakes. After typing
"addform.DataUp dated +=" you press Tab once to create the "new EventHandler"
and the second tab will create the function with the correct parameters.
SP
GetInstalledPri nters do not requires 2 parameters.
SP,
Basically make sure that your event handler method getCurrentPrint ers has
signature of (object, EventArgs e)
Thanks,
Ashish
"SP" <egatsecneserp( reverse)@hotmai l.com> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. .. <ri************ @orcon.net.nz> wrote in message news:10******** **************@ c13g2000cwb.goo glegroups.com.. . Justin, I thought monday morning may help me but alas not. This is what I have so far along the lines you suggested so I hope you can have a quick check for me. It won't compile - it tells me that getCurrentPrint ers() does not match delegate - void System.EventHan dler(object, System.EventArg s)
public class FormA : Form { private void lnkAdd_LinkClic ked(object sender, System.Windows. Forms.LinkLabel LinkClickedEven tArgs e)() { AddPrinter addform = new AddPrinter(); addform.DataUpd ated += new EventHandler(ge tCurrentPrinter s); addform.Show(); }
private void GetInstalledPri nters() { // do stuff } }
and in formB
public class AddPrinter : Form { public event EventHandler DataUpdated;
private void OnDataUpdated(E ventArgs e) { if ( DataUpdated != null ) { DataUpdated(thi s, e); } }
public void btnAdd_Click(ob ject sender, System.EventArg s e) { OnDataUpdated(e ); this.Close(); } }
The error message is correct. The getInstalledPri nters requires 2 parameters (object sender, EventArgs e). When using delegates the VS IDE will create the function for you to avoid these mistakes. After typing "addform.DataUp dated +=" you press Tab once to create the "new EventHandler" and the second tab will create the function with the correct parameters.
SP
But somewhere there is probably a method getCurrentPrint ers that is being
invoked by the EventHandler delegate and does not have the correct method
signature.
I confused this with the GetInstalledPri nters method.
SP
"Ashish" <no*****@thisad dress.com> wrote in message
news:uH******** ******@TK2MSFTN GP12.phx.gbl... GetInstalledPri nters do not requires 2 parameters.
SP,
Basically make sure that your event handler method getCurrentPrint ers has signature of (object, EventArgs e)
Thanks, Ashish "SP" <egatsecneserp( reverse)@hotmai l.com> wrote in message news:%2******** ********@tk2msf tngp13.phx.gbl. .. <ri************ @orcon.net.nz> wrote in message news:10******** **************@ c13g2000cwb.goo glegroups.com.. . Justin, I thought monday morning may help me but alas not. This is what I have so far along the lines you suggested so I hope you can have a quick check for me. It won't compile - it tells me that getCurrentPrint ers() does not match delegate - void System.EventHan dler(object, System.EventArg s)
public class FormA : Form { private void lnkAdd_LinkClic ked(object sender, System.Windows. Forms.LinkLabel LinkClickedEven tArgs e)() { AddPrinter addform = new AddPrinter(); addform.DataUpd ated += new EventHandler(ge tCurrentPrinter s); addform.Show(); }
private void GetInstalledPri nters() { // do stuff } }
and in formB
public class AddPrinter : Form { public event EventHandler DataUpdated;
private void OnDataUpdated(E ventArgs e) { if ( DataUpdated != null ) { DataUpdated(thi s, e); } }
public void btnAdd_Click(ob ject sender, System.EventArg s e) { OnDataUpdated(e ); this.Close(); } }
The error message is correct. The getInstalledPri nters requires 2 parameters (object sender, EventArgs e). When using delegates the VS IDE will create the function for you to avoid these mistakes. After typing "addform.DataUp dated +=" you press Tab once to create the "new EventHandler" and the second tab will create the function with the correct parameters.
SP
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Ashish |
last post by:
GetInstalledPrinters do not requires 2 parameters.
SP,
Basically make sure that your event handler method getCurrentPrinters has
signature of (object, EventArgs e)
Thanks,
Ashish
|
by: Rajat Tandon |
last post by:
Hello there,
I am relatively new to the newsgroups and C#. I have never been disappointed
with the groups and always got the prompt replies to my queries.This is yet
another strange issue, I am facing. Please please help me to solve this as
soon as possible.
So here we go ...
I am not able to take the screen shot of the windows form based "Smart
|
by: Richard |
last post by:
I think I'm going brain dead on this one. Can someone give me an idea on how
to do this? Some sample code would be helpful.
|
by: hufaunder |
last post by:
I would like to run a windows form application (app2) within another
windows form application (app1). app2 should be displayed within a
certain area of the windows form of app1 (could be inside a panel or
similar). app1 does not need any control over app2 except for starting,
closing, hiding and showing it. Basically, app1 should look like being
a part of app2 despite the fact that they have no knowledge of each
other (except the app name,...
|
by: SadikZ |
last post by:
Hi everyone,
I want to transfer my data from windows form of Visual basic .Net 2000 to another windows form of Visual basic .Net 2000, but i am not getting the code which i have to write for extracting data, so please friends help me for that ........
| |
by: oz |
last post by:
Hi All,
I want to make a dictionary with windows application. My data is html
format. therefore, i use webBrowser control on my windows form. If the
user click any word in webBrowser control, word mean must browse to
user (like babylon).
I have a windows form. My form has webBrowser control. I fill a html
content with javascript (Dictionary.js) to webBrowser.
Javascript (dictionary.js) can obtain the word if user double click on
|
by: Pumpkin Carver |
last post by:
I have a form that has a listview on it and a serious of strings in
the listiew. When i doubel click on the listview item it opens a new
form and displays the text that i pass to the constructor. What i am
trying to do now is have a previous/next button on the form i just
opened and have it go through the list of items depending on whats
previous or next to that item. I pretty much have the logic for that,
the only issue i cant seem to...
|
by: bsturg21 |
last post by:
Hello,
I have a windows form that has a series of linklabels on it, and I
need to have each linklabel, when clicked, open a separate windows
form that has a single paramter passed into it. The form that has the
System.Windows.Forms.LinkLabel controls on it is in a different
project and under a different namespace from the file where the
LinkLabel_LinkClicked events are, so I can't just do frm.ShowDialog
under the LinkClicked method. ...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |