Hi, I'm new to c# and come from a C / C++ background.
My MainWindow class has a function called DrawChart.
I open an MDI Child Window and want it to make a call from
its class MDIChild to DrawChart which is the MainWindow
class. Also, I want the chart counter to be incremented
on each call to DrawChart, without being set back to its
original value.
From my MDIChild class, If I say:
MainWindow xxx = new MainWindow ();
xxx.DrawChart ();
My counter gets re-initialized every time I call DrawChart.
Can anyone provide an answer ( in code ) if possible.
Thanks in advance.
Shaun Pudwell. 5 4503
Hi Shaun,
"Shaun Pudwell" <sh***********@ tiscali.co.uk> wrote in message
news:04******** *************** *****@phx.gbl.. . Hi, I'm new to c# and come from a C / C++ background. My MainWindow class has a function called DrawChart. I open an MDI Child Window and want it to make a call from its class MDIChild to DrawChart which is the MainWindow class. Also, I want the chart counter to be incremented on each call to DrawChart, without being set back to its original value.
From my MDIChild class, If I say:
MainWindow xxx = new MainWindow (); xxx.DrawChart ();
My counter gets re-initialized every time I call DrawChart. Can anyone provide an answer ( in code ) if possible.
Hmm...The problem is apparent, but the explanation is not. You are
creating a new instance of MainWindow each time and calling DrawChart on
that. I assume that you *want* to call the DrawChart method on the instance
of the MainWindow class that encapsulates the visible MDI parent form (which
is, in turn, parent to the MDI child windows). This can most easily be done
like this:
// Within an MDI child window class.
MainWindow xxx = (MainWindow)thi s.MdiParent;
xxx.DrawChart ();
Regards,
Dan
Hi,
Thanks, I will try that one.
Didn't see anything like this in either of the two books I have nor in
the Scribble demo!
Regards
Shaun Pudwell.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Shaun,
While there is certainly nothing wrong with this approach, you will
now have a circular reference. The MDIParent object has a reference
to the MDIChild object and the MDIChild object has a reference to the
parent. You have to be Very careful with circular references.
Another approach would be to put an event in the MDIChild class. In
the MDIParent class write an event handler that calls or does your
drawing task. Then in the child you simply raise the event whenever
you want the drawing to happen.
This is just another approach FYI.
Shaun Pudwell <sh***********@ tiscali.co.uk> wrote in message news:<OX******* ******@TK2MSFTN GP12.phx.gbl>.. . Hi,
Thanks, I will try that one.
Didn't see anything like this in either of the two books I have nor in the Scribble demo!
Regards
Shaun Pudwell.
*** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
Hi Doug,
"Doug Taylor" <do*********@ac cipitersoftware .com> wrote in message
news:e1******** *************** ***@posting.goo gle.com... Shaun,
While there is certainly nothing wrong with this approach, you will now have a circular reference. The MDIParent object has a reference to the MDIChild object and the MDIChild object has a reference to the parent. You have to be Very careful with circular references.
Another approach would be to put an event in the MDIChild class. In the MDIParent class write an event handler that calls or does your drawing task. Then in the child you simply raise the event whenever you want the drawing to happen.
This is just another approach FYI.
A few things:
1. What I suggested to Shaun will not create a circular reference
situation. In the code snippet, the MainWindow variable is declared local to
the routine. Once the routine exits, the variable goes out of scope and the
reference is no more.
2. If Shaun *were* to create a circular reference situation (say he
assigns a reference to the MainWindow instance to a *member* variable of the
child window instance) this would still be no big deal. The garbage
collector implementation in .NET will still reclaim both instances when they
are no longer "reachable" by the application.
3. Subscribing to an event creates a reference from the event source
object to the event subscriber object. Thus your suggestion would, in fact,
create a circular reference situation. Fortunately this is no big deal (see
#2).
Regards,
Dan
Daniel,
All very good points. Thanks.
"Daniel Pratt" <ko************ ******@hotmail. com> wrote in message news:<ua******* *******@TK2MSFT NGP11.phx.gbl>. .. Hi Doug,
"Doug Taylor" <do*********@ac cipitersoftware .com> wrote in message news:e1******** *************** ***@posting.goo gle.com... Shaun,
While there is certainly nothing wrong with this approach, you will now have a circular reference. The MDIParent object has a reference to the MDIChild object and the MDIChild object has a reference to the parent. You have to be Very careful with circular references.
Another approach would be to put an event in the MDIChild class. In the MDIParent class write an event handler that calls or does your drawing task. Then in the child you simply raise the event whenever you want the drawing to happen.
This is just another approach FYI.
A few things:
1. What I suggested to Shaun will not create a circular reference situation. In the code snippet, the MainWindow variable is declared local to the routine. Once the routine exits, the variable goes out of scope and the reference is no more.
2. If Shaun *were* to create a circular reference situation (say he assigns a reference to the MainWindow instance to a *member* variable of the child window instance) this would still be no big deal. The garbage collector implementation in .NET will still reclaim both instances when they are no longer "reachable" by the application.
3. Subscribing to an event creates a reference from the event source object to the event subscriber object. Thus your suggestion would, in fact, create a circular reference situation. Fortunately this is no big deal (see #2).
Regards, Dan This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Cyril Vi?ville |
last post by:
Hello everybody,
I would like to know how to block the destroy of the MainWindow with
the cross and with right click and close?
I have actually a basic start :
my $window = MainWindow->new;
$window->bind("<Destroy>", sub { print "Hello\n" });
MainLoop;
|
by: Reply Via Newsgroup |
last post by:
Folks,
I was sure this could be done - or at least sure I had seen reference to
it at some point or other - but now, after having gone for a cup of tea,
am begining to doubt my original belief.
Can I have a script, available in a parent function, called from a child
window? If so, how?
And... if so, why? I mean, while sipping my tea, I realised that if the
|
by: Raffi B. |
last post by:
I have a form named MainWindow in my project. Visual Studio C# Express
automatically creates MainWindow.Designer.cs and MainWindow.resx as partial
classes on MainWindow. I am trying to add a new C# class file named
MainWindow.EventHandlers.cs to the project as a partial class of MainWindow
using...
partial class MainWindow
{
}
|
by: Marcus |
last post by:
How can I access the windows that are not the current mainwindow. For
instance with Internet Explorer (iexplore) one can create several
browser windows within the same "instance" of iexplore.
I can for get the window title of the main window (with MainWindowTitle
property), but I have not managed to get the window title for any of
the other windows of that iexplore instance. I have noticed that I can
change what window is classified as...
|
by: Opa |
last post by:
Hi ,
I have a form with javasript which launches a popup via the showModalDialog()
method. I get the dialog to open, now I am trying to first get a reference
to the calling form from the popup and then do a refresh of the calling form.
Any ideas on how to get a reference to the calling form?
I tried window.parent.location.reload() , but it doesn't work.
Thanks a lot.
| |
by: Bugs |
last post by:
Hi,
I wonder if anyone can help me out.
I'm building a vb.net application that has a form with a panel that
contains several other sub forms (as a collection of controls). What
I'm wanting to do is call a generically named public sub in the
top-most sub form in the panel.
I have the name of the top-most form as a string (eg. g_TopForm =
"frmCustomers") and I can reference the form with:
|
by: =?Utf-8?B?cmFuZHkxMjAw?= |
last post by:
The code below is pretty simple. Calling Talker() in the parent returns
"Parent", and calling Talker() in the child returns "Child".
I'm wondering how I can modify the code so that a call to the Talker() in
Parent will call the Talker() method in every child class. The kicker is that
I have many different Child classes, and not all Child classes will be loaded
when Talker() in the Parent is called.
Thanks,
Randy
|
by: Phil Thompson |
last post by:
On Sunday 04 May 2008, Lance Gamet wrote:
I think QMainWindow.setCentralWidget() is what you are looking for.
The eric4 IDE probably covers most things you'll ever need.
Phil
|
by: nupuragr82 |
last post by:
I have a parent form and on button click I am calling a child page where i have a textbox and a button. On button click of child form I am passing the value of the Textbox to the Textbox in parent page and now I want to fire an event.
Button click event on parent page- parameter is txtBlank (TextBox in parent page)
function SetRange(Src)
{
window.open("SetRange.aspx?src=" + Src, "_blank", "status = 1, ontop=true, height=110,...
|
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: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |