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

c# current form close problem

Hi everybody.

I need some help in c# forms problem which is

i have three forms naming main form,form1 & form2. main form is the mdiparent of both form1 and form2. i also have a toolstrip in my main form which includes option close current frm and close all. what i need is when i click the close current form option the form opened state(either form1 or form2) close down.

suppose currently form 2 is currently open in the main form and i want to close that current open form how i do this.
Sep 9 '09 #1
6 3679
Plater
7,872 Expert 4TB
If you know which form is the "current" form, then you could either call the .Close() of the correct form to actually close the form, or maybe just Hide() if you only want it hidden, not closed.
Sep 9 '09 #2
Hi Plater how would i decide which form is open it can be any one either Form1 or Form2 My question is how would i check which form is open.
Sep 9 '09 #3
GaryTexmo
1,501 Expert 1GB
I've never worked with an MDI interface before, but unless it explicitly tracks which form is active (and somehow I doubt it :P), you'll need to track it yourself.

One way would be to have the form focus event (or is it activated? I'm not sure... whichever one gets raised when you activate a form) send an event to your controlling method with a reference to the most recently active form.

Then your main form can close whichever that one is.
Sep 9 '09 #4
Ok i will try this one
Sep 10 '09 #5
U can declare a static global variable which will maintain the current instance of the form.
Sep 10 '09 #6
Try this code:

void CloseChildForm(string formName)
{
foreach (Form childForm in this.MdiChildren)
{
if (childForm.Name == "formName")
{
childForm.Close();
return;
}
}
}
Sep 10 '09 #7

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

Similar topics

1
by: Steve Jorgensen | last post by:
An Access database connected to a PostgreSQL back-end. Sometimes, when I close a form, i get a message saying that the action will reset the current code in break mode. The front-end literally...
2
by: Ryan | last post by:
Access97 I hope someone out there can help. This is driving me crazy. Basically, I am trying to recreate VBA's built in navigation feature (The one that allows you to move first, next,...
1
by: Richard Coutts | last post by:
I have a Continuous Form where each record has a button that activates another form that simplifies entering values into the record. The activated form has the equivalent of a "Done" button. I'd...
8
by: Zlatko Matić | last post by:
There is a form (single form) and a combobox. I want that current record of the form is adjusted according to selected value in the combobox. Cuurrent record should be the same as the value in the...
1
by: moelleni | last post by:
Hi, I made an Access 2002 Database and wanted to automate it to sent the current record to Word 2002. So readed the article "How to send the current record to Word 2000 with automation" I tried...
4
by: ghadley_00 | last post by:
Hi, Can anyone recommend a piece of VBA code I could attach to a button in a MS Form form that will close the current form and bring the switchboard to foreground. I'm trying to integrate a form...
2
by: MLH | last post by:
Suppose that code running on FormB is moving the focus around on FormA to various textbox controls on FormA - Which form is the current form during this process? Is it FormA, which has the...
4
xpun
by: xpun | last post by:
hey all ok i have a macro set to a button(main menu ) on a customer entry form. close close openform the problem is when the button(main menu) is clicked while the customer entry form is...
5
by: 130975 | last post by:
Hi, I am working on a database. I have created a main form and three linked forms. When I enter an ID in the main form all the related information is also displayed on the linked forms. The problem...
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...
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...
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
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...

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.