본문 바로가기
컴퓨터/C#

C# 프로그래밍

by Begi 2019. 6. 15.
반응형

Form 닫기

 this.Close();

Form 크기, 위치, 상태

 this.Size
 this.Location
 this.WindowState

 

MDI Child Form 열기

 Form2 newMDIChild = new Form2(); newMDIChild.MdiParent = this; newMDIChild.Show();

 

스트링을 구분 기호로 분리, 라인 분리

 string s = " ~~~~~~\r\n~~~~~\r\n"; string[] a =   s.Split("\r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
 foreach (String item in a)
 { }

 

배열 선언, 초기화

 // 배열 선언
 int [] a = new int[10];
 int [] a = new int[3] {1,2,3); 
 int [,] a = new int[3,2];
 int [,] a = new int[3,2] { {1,2} , {3,4} , {5,6} };
 // 배열 크기
 int l = a.Length;

 

예외 처리

 try
 {
   [코드]
 }
 catch (Exception ex)
 {
   MessageBox.Show(ex.ToString());
 }

 

Mutex

 // 선언
 Mutex mtx = new Mutex(false, "MyMutex"); // 사용
 if (mtx.WaitOne(1000)) { } // 해제 mtx.ReleaseMutex();

 

파일의 아이콘 얻기

 Icon icon = System.Drawing.Icon.ExtractAssociatedIcon("c:\\icon1.ico");

아이콘을 이미지로 변환

 Image img = icon.ToBitmap();

 

현재 폴더 구하기

실행 파일이 실행되는 폴더를 문자로 반환

 string path = Directory.GetCurrentDirectory();

 

파일 함수

 bool File.Exists(string path)               // 파일 존재 여부 FileStream File.Create(string path)         // 파일 생성
 string File.ReadAllText(string path)        // 파일 읽음 File.WriteAllText(string path, string text) // 파일 쓰기

 

컴퓨터 끄기

 Process p = Process.Start("shutdown", "/s /t 0");

컴퓨터 재시작

 Process p = Process.Start("shutdown", "/r /t 0");

컴퓨터 로크오프

 Process p = Process.Start("shutdown", "/l /t 0");

 

Context Menu

 contextMenuStrip1.Items.Clear();                     // 메뉴 모든 항목 삭제
 contextMenuStrip1.Items.Add(string text);            // 항목 이름 추가
 contextMenuStrip1.Items.Add(string text, Image img); // 항목 이름,아이콘 추가

버턴을 클릭하면 바로 아래에 Context Menu 표시

 private void button1_Click(object sender, EventArgs e) {   Button btnSender = (Button)sender;   Point ptLowerLeft = new Point(0, btnSender.Height);   ptLowerLeft = btnSender.PointToScreen(ptLowerLeft);   contextMenuStrip1Show(ptLowerLeft); }

 

반응형

'컴퓨터 > C#' 카테고리의 다른 글

C# 다른 프로그램 제어  (0) 2019.06.26
C# 프로그램 중복실행 방지  (0) 2019.06.26
C# listView 사용법  (0) 2019.06.12
C# listBox 사용법  (0) 2019.06.07
C# MDI 자식 폼 만들기  (0) 2019.06.05

댓글