简体   繁体   中英

Closing an open Form from a Parent Form

I am programming an applicaion with visual studio and c#. it has a Parent Form (FormParent) which is a MdiContainer and contains a toolstrip. the FormParent Conatins and a child Form (FormChild). So I open other Forms inside of it like FormUser.

Suppose I have a open FormUser, how can I close this FormUser when I click the toolstrip button ( for example the save one)?

Thank you

I did This and worked

  FormUser obj = (FormUser)Application.OpenForms["FormUser"];                
  obj.Close(); 

also thank you to @JQSOFT answer with a little edit another solution is :

  Application.OpenForms.OfType<FormUser>().FirstOrDefault().Close();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM