Life is.

ActiveForm 활용

개발/C#2018. 9. 11. 20:41
반응형

열려있는 Form의 Control를 접근하고 싶은데 좀처럼 방법을 찾지 못하다 activeform을 사용


참조

https://msdn.microsoft.com/en-us/library/system.windows.forms.form.activeform(v=vs.110).aspx


public void DisableActiveFormControls()

{
    // Create an instance of a form and assign it the currently active form.
    Form currentForm = Form.ActiveForm;

    // Loop through all the controls on the active form.

   for (int i = 0; i < currentForm.Controls.Count; i++)
   {
     // Disable each control in the active form's control collection.
        currentForm.Controls[i].Enabled = false;
   }
}


단 여기서 마지막으로 열린 Form을 참조하고 싶었기에 이 소스를 참조함

Form frm = Application.OpenForms.Cast<Form>().Last();


출처 : http://iopeni.tistory.com/49

 

 


반응형

'개발 > C#' 카테고리의 다른 글

Farpoint Spread의 Virtual Mode  (0) 2018.09.12
단축키 구현  (0) 2018.09.11
System.Globalization 관련 DateTimePicker  (0) 2018.09.11
System.Globalization 관련 DateTime  (0) 2018.09.11
Combobox 에서 CheckBox 넣기  (0) 2018.09.11