473,385 Members | 1,185 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.

Call method in different window: C#

Ok, so I am really and truly a beginner at C#. I have been programming for some time but just beginning to learn this language. Here is what I am trying to accomplish. I have created a little application using the main window as a MDI and a child window. There are three buttons in the main window, New Window (when pushed will add a new child window to the MDI), Cascade and Tile (these will arrange the windows within the MDI). Basically I want to disable the buttons if the child window count becomes 0.

I have the following method that I have placed in the main window and in a separate class, each causing me different challenges.

public void UpdateButtons(Boolean ButtonState)
{
if (ButtonState)
{
cascadeButton.ForeColor = Color.FromArgb(0, 0, 160);
tileButton.ForeColor = Color.FromArgb(0, 0, 160);
}
else
{
cascadeButton.ForeColor = Color.FromArgb(202, 202, 255);
tileButton.ForeColor = Color.FromArgb(202, 202, 255);
}

cascadeButton.Enabled = ButtonState;
tileButton.Enabled = ButtonState;
}

I cannot for the life of me figure out how to call this from the Closing event in the child class. I have tried to create a variable that references the main window from within the ChildWindow_FormClosing event “Form MainWin = this.MdiParent();” however the method is not there. I am sure it is a simple answer. If there is anyone that can help me I would greatly appreciate it.

P.s. I have also tryied moving the method to a separate class and calling it that way, which allows me to see the method and call it however I am not able to reference the controls.

Thanks for your help
Patrick
May 16 '07 #1
3 1971
Motoma
3,237 Expert 2GB
I cannot for the life of me figure out how to call this from the Closing event in the child class. I have tried to create a variable that references the main window from within the ChildWindow_FormClosing event “Form MainWin = this.MdiParent();” however the method is not there. I am sure it is a simple answer. If there is anyone that can help me I would greatly appreciate it.
The reason for this is that the Form class does not have an UpdateButtons() member. You will need to declare MainWin as the class of your actual form. For instance, if you have named the form class of your Main Form to be Form1 (as is the default) then you would use
Expand|Select|Wrap|Line Numbers
  1. Form1 MainWin = this.MdiParent();
  2.  
Likewise, if you named your Main form's class to be clsMainForm you would use:
Expand|Select|Wrap|Line Numbers
  1. clsMainForm MainWin = this.MdiParent();
  2.  
May 16 '07 #2
The reason for this is that the Form class does not have an UpdateButtons() member. You will need to declare MainWin as the class of your actual form. For instance, if you have named the form class of your Main Form to be Form1 (as is the default) then you would use
Expand|Select|Wrap|Line Numbers
  1. Form1 MainWin = this.MdiParent();
  2.  
Likewise, if you named your Main form's class to be clsMainForm you would use:
Expand|Select|Wrap|Line Numbers
  1. clsMainForm MainWin = this.MdiParent();
  2.  
Hi thanks for your help. I have tried the code that you provided and I receive the following error.

'System.Windows.Forms.Form.MdiParent' is a 'property' but is used like a 'method'

Is there are particular place that I should put this statement? Here is an example of how I used it.
private void ChildWindow_Load(object sender, EventArgs e)
{
//Form1 MainWin = (Form1)this.MdiParent;
Form1 MainWin = this.MdiParent();
label1.Text = "I'm window number " + parent.WinCount.ToString();
}


Thanks again,
Patrick
May 16 '07 #3
Motoma
3,237 Expert 2GB
Well, like the message says, it is a Property, not a Method...You will not need () after it.

Expand|Select|Wrap|Line Numbers
  1. Form1 MainWin = this.MdiParent;
And please, in future posts, use [code] tags.
May 16 '07 #4

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

Similar topics

5
by: Sue | last post by:
After finishing up my first quarter JavaScript on 12/12/03, I decided to improve character checking on my project. In my project I only had to do very basic validation. Therefore, I only had one...
1
by: Ricardo Garcia | last post by:
hi, i have a page with frames, and i want to call from the main frame a method in the navigation frame. how could i do it?? What i want get with this, is styling in a different way the link that...
39
by: Randell D. | last post by:
Folks, I'm sure this can be done legally, and not thru tricks of the trade - I hope someone can help. I'm writing a 'tool' (a function) which can be used generically in any of my projects. ...
2
by: rawCoder | last post by:
Hi I am having this InvalidOperationException with message Cannot call Invoke or InvokeAsync on a control until the window handle has been created This is raised when i try to invoke a method...
1
by: tony | last post by:
Hello!! I have an application that consist of several windows forms. Lets call these A,B and C for simplicity. I have one main meny where the user can choose window form A or B or C. When a...
6
by: pronerd | last post by:
Hi, I am trying to dynamically set an event handler across frames. I have no problems setting properties across frames doing something like parent.ToolMenuFrame.location.href =...
8
by: hoofbeats95 | last post by:
I don't think this should be this complicated, but I can't figure it out. I've worked with C# for several years now, but in a web environment, not with windows form. I have a form with a query...
6
by: RandomElle | last post by:
Hi there I'm hoping someone can help me out with the use of the Eval function. I am using Access2003 under WinXP Pro. I can successfully use the Eval function and get it to call any function with...
29
Frinavale
by: Frinavale | last post by:
I have 2 FireFox (version 2) browser windows opened. One is the child of the other. When the user is finished with the child window, a method in the parent window is called to refresh a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.