라벨이 C#인 게시물 표시

[WPF] How to programmatically click a button

Windows Forms 에서는 Button.PerformClick() 함수가 존재하였었는데,  WPF(Windows Presentation Foundation) 에서는 해당 함수가 존재하지 않는다. WPF에서 사 용할 수 있는 두가지 방법을 소개한다. <방법1. AutomationPeer 이용> Sample code : ---------------------------------------------------------------------------- using System.Windows.Automation.Peers; using System.Windows.Automation.Provider; ...  void ButtonClick() {   ButtonAutomationPeer peer = new ButtonAutomationPeer( TestButton );   IInvokeProvider invokeProv = peer.GetPattern(PatternInterface.Invoke) as IInvokeProvider;   invokeProv.Invoke();   NextFunction (); }  ----------------------------------------------------------------------------  - Invoke() 함수 로 클 릭 이벤트가 발생하여 ,  다음처리(NextFunction)가 진행 된 후 클릭이벤트가 발생한다 .  - 해당버튼이 Disabled 일 때 에는 System.Windows.Automation.ElementNotEnabledException 이 발생한다. <방법2. RaiseEvent 이용> Sample code : ---------------------------------------------------------------...

[C#] File to Byte Array, Byte Array to File

<File to Byte Array> 1. File Stream을 이용하여 파일을 Byte 배열로 변환   using System.IO; ... public byte[] FileToByteArray(string path) {   byte[] fileBytes = null;   try {     using(FileStream fileStream = new FileSystem(path, FileMode.Open)) {       fileBytes = new byte[fileStream.Length];       fileStream.Read(fileBytes, 0, fileBytes.Length);     }   } catch (Exception e) {     // Exception ...   }   return fileBytes; } <Byte Array to File> 1. FileStream을 사용하여 Byte 배열을 파일로 변환 using System.IO; ... public bool ByteArrayToFile(string path, byte[] buffer) {   try {     using(FileStream fileStream = new FileSystem(path, FileMode.Create)) {       fileStream.Write(buffer, 0, buffer.Length);     }     return true;   } catch (Exception e) { ...

[C#][System.IO.Directory.GetFiles] 지정된 폴더의 파일목록 가져오기

<설명> Directory.GetFiles(String)  - 지정된 폴더에 있는 파일의 이름(경로 포함)을 반환한다.  - 하위 폴더는 검색하지 않는다. Directory.GetFiles(String, String)  - 지정된 폴더에서 지정된 검색 패턴과 일치하는 파일 이름(파일 경로 포함)을 반환한다.  - 하위폴더는 검색하지 않는다. Directory.GetFiles(String, String, SearchOption)  - 하위 폴더를 검색할지 여부를 나타내는 값을 사용하여 지정된 디렉터리에서 지정된 검색 패턴과 일치하는 파일 이름(파일 경로 포함)을 반환한다. <특이사항>  - 지정된 폴더에 있는 숨김 파일의 이름도 반환한다. <예제>  - 지정된 확장자의 파일목록 가져오기  ---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------   string path = " PATH ";   string searchPatterns = "*.txt|*.jpg";   stirng[] files = searchPatterns                         .Split('|')                         .SelectMany(searchPattern =...