473,385 Members | 1,890 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Access a method on the MAIN FORM

Hello.

I have a windows forms application (.NET 3.0)
where I have a user control ( a sort of spine) on a Form (called imaginatively enough MainForm).
In the spine I make a call to a WCF service (in a seperate thread). I need to be able to (from this seperate thread) to call a method (DisplayNotification) on the MainForm and pass it a parameter (or two).
I just can't seem to do this. I am however able (with delegates) to do this with methods/controls on the spine. But unfortunate not the MainForm.
Can someone give me a leg up on this?

Basically:

Spine(usercontrol on MainForm) ->starts thread(WCF service) ->needs to access DisplayNotification() on MainForm.
Apr 30 '07 #1
5 1195
TRScheel
638 Expert 512MB
Hello.

I have a windows forms application (.NET 3.0)
where I have a user control ( a sort of spine) on a Form (called imaginatively enough MainForm).
In the spine I make a call to a WCF service (in a seperate thread). I need to be able to (from this seperate thread) to call a method (DisplayNotification) on the MainForm and pass it a parameter (or two).
I just can't seem to do this. I am however able (with delegates) to do this with methods/controls on the spine. But unfortunate not the MainForm.
Can someone give me a leg up on this?

Basically:

Spine(usercontrol on MainForm) ->starts thread(WCF service) ->needs to access DisplayNotification() on MainForm.
At some point pass a reference to the mainform, perhaps even in the constructor of the child form. Then save it somewhere for future use.
Apr 30 '07 #2
TRScheel
638 Expert 512MB
Additionally, i believe there is a parent property inherent in forms. You could use that, combined with reflection, to grab the method you are using.
Apr 30 '07 #3
Additionally, i believe there is a parent property inherent in forms. You could use that, combined with reflection, to grab the method you are using.

I tried using FindContol() and even .Parent but I am embarassed to say...
I don't know how to use it. I can get a list of controls that match the control I want. I get it in a the form of ArrayOfFormControls[]. It's just that I don't know how to invoke properties on the say ArrayOfFormControls[0].

Can you point me towards an example? Basically I would prefer to use a METHOD in the MainForm to do my dirty work, rather than use properties on the control itself.

You mention using reflection, I'm afraid I have no experience with using reflection. Can you point towards an example or tutorial. I have googled it, and come up short....


Thanks!
May 1 '07 #4
At some point pass a reference to the mainform, perhaps even in the constructor of the child form. Then save it somewhere for future use.
Can you point me to a concrete example of this? I am not sure where to begin with this.

Thanks!
May 1 '07 #5
TRScheel
638 Expert 512MB
Can you point me to a concrete example of this? I am not sure where to begin with this.

Thanks!

Well every form you create through the designer starts with a public constructor that is empty, hence you start with something similiar to:

Expand|Select|Wrap|Line Numbers
  1. public partial class MyForm
  2. {
  3.      public MyForm()
  4.      {
  5.      }
  6. }
I am suggesting change that so that it is something similiar to:

Expand|Select|Wrap|Line Numbers
  1. public partial class MyForm
  2. {
  3.      private MyOtherFormType _Parent;
  4.  
  5.      public MyForm(MyOtherFormType Parent)
  6.      {
  7.           _Parent = Parent;
  8.      }
  9. }
Now when you call the constructor of that form from your parent form, you will have to pass the instance of the parent, but the child will have access to all its public methods/properties.
May 10 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

17
by: Trevor Best | last post by:
I don't know if this has been reported before but it appears to be a bug with Access. If I create two tables both with an identity column then create an insert trigger on table1 that inserts a...
4
by: p988 | last post by:
using System; using System.Windows.Forms; using System.Drawing; class MyForm : Form { MyForm () { Text = "Windows Forms Demo"; }
3
by: Alvo von Cossel I | last post by:
hi, i am making a word processor. i have the main form and my own version of the character map in another. the main form has a rich textbox in it. my aim is for the user to click on a character...
4
by: Daylor | last post by:
hi. i have multi thread application in vb.net is there a way NET support, so i can mark the class , to be access only for 1 thread each time ? if there is , small sytax sample will help ...
5
by: twick10 | last post by:
Hi, I am trying to execute a control method on an open form (not with focus) from a modal dialog box. I want to increment the node selected from the dialog when a certain key is pressed. Any...
2
by: Rajat Tandon | last post by:
Hi, I have a grid which is continuously updating by the data from a external event. When I close the form on which the grid is placed, then it gives the error message ... "Can not access a...
0
by: microb0x | last post by:
Is there any difference in the way an Access .mdb file is launched from directly double-clicking the file through windows explorer versus using code within another Access file to launch the...
3
by: Peted | last post by:
Hi i hope i explaine this correctly I have a class with a method that reads and writes using blocking sockets to a TCP device. Call it class IPdevice. I can use this method to send commands and...
6
by: forest demon | last post by:
i have a custom control that gets loaded at runtime. i need to be able to access a property of a control thats part of the main form, through the clcik event of the custom control. i may be...
2
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.