Winform2 C# WinForm 동적으로 생성한 Control 접근하는 방법 C# WinForm에서 동적으로 Controls(Button, Label, ,,,)을 생성 후 작업 중 생성한 Control에 접근하는 방법을 메모해 둔다. 우선 Button을 동적으로 생성해 보자. Button btnTest = new Button(); btnTest.Name = "btnTest"; //Controls 에서 조회키가 되므로 Naming에 신경쓰자. btnTest.Text = "Test"; btnTest.Size = new System.Drawing.Size(100, 30); btnTest.Location = new System.Drawing.Point(50, 50); btnTest.Click += new System.EventHandler(btnTest_Click); this.Contr.. 2021. 5. 13. C# delegate 사용법 - 사례2 WinForm 환경에서 C#으로 개발중 스레드 혹은 이벤트 콜백 내에서 화면의 Control에 접근하게 될 경우 아래와 같은 오류가 발생한다.(*'크로스 스레드 작업이 잘못되었습니다.')SerialPort 선언 후 DataReceived 이벤트 핸들러를 등록, SeriaPort 이벤트 핸들러 내에서 스캐너로부터 받은 데이터를 ListBox에 Add 시키는 과정이다. 직접 연결해서 접근할 수 없으니 우회해서 Add 시켜줄 수 밖에 없다. 여기서도 function pointer 즉 delegate가 이용된다.SerialPort objBarcodeScanner = new SerialPort();objBarcodeScanner.PortName = "COM4";objBarcodeScanner.BaudRate = .. 2019. 1. 15. 이전 1 다음