473,394 Members | 1,797 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,394 software developers and data experts.

Stupid question...

I constantly have a delima calling functions inbetween forms, for
example in a project, in frmMain.cs , I have a function called
RefMain();, I would like to call it in frmAdd.cs, but none of the
following methods work:

1:
frmMain frm;
frm.RefMain();

2:
frmMain frm = new frmMain();
frm.RefMain();

I can never seem to get the functions to call correctly between forms,
and I cannot make the function a static void, please help! :'(

Feb 1 '07 #1
4 1190
On Feb 1, 7:14 pm, a...@goldews.com wrote:
I constantly have a delima calling functions inbetween forms, for
example in a project, in frmMain.cs , I have a function called
RefMain();, I would like to call it in frmAdd.cs, but none of the
following methods work:

1:
frmMain frm;
frm.RefMain();

2:
frmMain frm = new frmMain();
frm.RefMain();

I can never seem to get the functions to call correctly between forms,
and I cannot make the function a static void, please help! :'(
In my app I have a child form called Times (in Times.cs) which has
this function:
internal string MyFunc()
{
}

(note that it is internal so it can be accessed from anywhere the app)
then in my main form I can access it:
Times frmTimes = new Times();
frmTimes.MyFunc();

Hope this example helps.

Jon
dbgurus.com.au

Feb 1 '07 #2
I constantly have a delima calling functions inbetween forms, for
example in a project, in frmMain.cs , I have a function called
RefMain();, I would like to call it in frmAdd.cs, but none of the
following methods work:

1:
frmMain frm;
frm.RefMain();

2:
frmMain frm = new frmMain();
frm.RefMain();

I can never seem to get the functions to call correctly between forms,
and I cannot make the function a static void, please help! :'(
1. would not work, as "frm" is unassigned
2. will compile, but this will call "RefMain()" on a new instance of
your form.

I think you want to call that RefMain method on an existing form. This
means you will need a reference to that *existing* form. How you do it
really depends on your architecture, but basically you need to store
that reference somewhere, where other forms can find it.

Hans Kesting
Feb 1 '07 #3
I tried passing the instance of frmMain to frmNew when it's called:

private void newToolStripMenuItem_Click(object sender,
EventArgs e)
{
frmNew fmNew = new frmNew(this);
fmNew.Show();
}

However, in frmNew, I do not need to use my function in the load of
frmNew, i need to use it in a button on click, as follows:
public frmNew(frmMain frmM)
{
InitializeComponent();
}

private void btnAdd_Click(object sender, EventArgs e)
{

As you can see, I declare what is being passed to frmNew, however, I
need to use the function in Add_Click, not frmNew(). Hope this clears
up my delima.

Feb 4 '07 #4
Smarter <ad**@goldews.comwrote:
I tried passing the instance of frmMain to frmNew when it's called:

private void newToolStripMenuItem_Click(object sender,
EventArgs e)
{
frmNew fmNew = new frmNew(this);
fmNew.Show();
}

However, in frmNew, I do not need to use my function in the load of
frmNew, i need to use it in a button on click, as follows:
public frmNew(frmMain frmM)
{
InitializeComponent();
}

private void btnAdd_Click(object sender, EventArgs e)
{

As you can see, I declare what is being passed to frmNew, however, I
need to use the function in Add_Click, not frmNew(). Hope this clears
up my delima.
So keep a reference to the main form within the other form:

frmMain creator;

public frmNew(frmMain frmM)
{
InitializeComponent();
creator = frmM;
}

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Feb 4 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

119
by: rhat | last post by:
I heard that beta 2 now makes ASP.NET xhtml compliant. Can anyone shed some light on what this will change and it will break stuff as converting HTML to XHTML pages DO break things. see,...
5
by: raz | last post by:
Greetings all. I apologize for what is almost certainly a stupid question, but I can't figure this out, and have no more time for head bashing... The short version: what is the appropriate...
4
by: IS | last post by:
At the recommendation of several people in this newsgroup I have downloaded two or three Compilers. One is the Beta version of Microsoft's Visual C++ 2005. I have entered a complete beginner code...
2
by: Ron Weldy | last post by:
I read that you don't need .cs files to deploy but I suppose if you are trying to reconstruct someone's work, you will need these files. Is that correct?
3
by: rroman | last post by:
I have a very simple form, takes information from the user, updates a SQL database, now I just want to redirect to a "Thank You For Your Time" web page within the same bowser. ASP. NET VB
6
by: Adam Smith | last post by:
I have posted this and similar questions repeatedly and can't even raise a single response. I am being led to believe that this then 'Must be a stupid question' although people say that there is no...
5
by: Alberto Salvati | last post by:
Hi, List. My company has a VERY BIG product base on db2 udb v7.x. We want to di an upgrade to v9, but.... current db has a lot of procedure (cobol..!). Therefore, we've planned to rewrite this...
2
by: Lynx101 | last post by:
Hi, Is this a stupid question? Senario: Two tables linked together with an ID number. Question: When using a combo box, which refences another table by indexed autonumber, is there a way to...
9
by: AWW | last post by:
Running XP - Visual Studio 2005 - VB Want to have duplicate projects - one safe and stable - other for experimenting Can't fine easy way to make duplicate project. Stupid question? or stupid ME?...
9
by: Alec | last post by:
Sorry guys, stupid question.... Am no programming expert and have only just started using php for creating dynamic news pages. Then I see a dynamic website without the php extension. ...
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: 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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
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...
0
Oralloy
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,...
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...
0
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...
0
tracyyun
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...

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.