C#
2012.12.10 09:55

C# 자주 쓰는 코드

조회 수 12281 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

+ - Up Down Comment Print
?

단축키

Prev이전 문서

Next다음 문서

+ - Up Down Comment Print

#1 실행경로

1.string aaa = Application.StartupPath + "\\version_history.txt";


#2 파일 읽기

1.using (StreamReader sr = new StreamReader(file경로, System.Text.Encoding.Default))
2.{
3. aaa = sr.ReadToEnd();
4. sr.Close();
5.}


#3 파일 쓰기

01.string strDir = "저장할경로";
02.string strPath = strDir + "\\" + 파일명;
03.
04.// 저장할 내용
05.string inputText = rtxtOrgMsg.Text;
06.
07.// 디렉토리가 존재하지 않으면 디렉토리 생성
08.if(!Directory.Exists(strDir))
09.{
10. Directory.CreateDirectory(strDir);
11.}
12.
13.// text내용을 바이트로 인코딩
14.Byte[] info = new UTF8Encoding(true).GetBytes(inputText);
15.
16.// 저장
17.FileStream fs = File.Open(strPath, FileMode.Create);
18.fs.Write(info, 0, info.Length);
19.fs.Close();


#4 크로스 쓰레드 오류 방지

1.CheckForIllegalCrossThreadCalls = false;


#5 커서 바꾸기

1.using (Cursor.Current = Cursors.WaitCursor)
2.{
3. 실행코드;
4.}


#6 사용자 확인후 진행

01.void btnRemoveEntryClick(object sender, System.EventArgs e)
02.{
03. // 사용자 확인
04. if (MessageBox.Show("This entry will be removed.", "Confirm Removal", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) != DialogResult.OK)
05. return;
06.
07. // OK 일때의 작업은 여기에
08. ~~~~
09.}


#7 진행 시간 측정

1.DateTime startTime = DateTime.Now;
2.// 작업작업
3.MessageBox.Show("Passed!\n\n" + (DateTime.Now - startTime).TotalMilliseconds + " ms.", "Test Result", MessageBoxButtons.OK, MessageBoxIcon.Information);


#8 실행 경로 구하기

1.System.Environment.CurrentDirectory
2.Application.StartupPath


#9 richTextBox 자동 스크롤

1.private void InsertTextProcess(string argText)
2.{
3. this.richTextBoxDescription.Focus();
4. this.richTextBoxDescription.AppendText(argText);
5. this.richTextBoxDescription.ScrollToCaret();
6.}
 
 

Dreamy의 코드 스크랩

내가 모으고 내가 보는

List of Articles
번호 분류 제목 날짜 조회 수 추천 수
86 일반 [VB] 파생된 수학 삼각 함수 2005.08.05 37639 0
85 LINUX CR, LF, ^M - vi로 DOS<->UNIX 줄바꿈 전환 2014.07.14 37918 0
84 C Stack 스택 (Linked List로 구현) file 2005.08.10 37976 0
83 Android 안드로이드 스마트 폰 화면 미러링: scrcpy 사용법 2021.08.18 38291 0
82 MFC 커맨드 창 속성 제어 2009.09.01 38341 0
81 Python C#에서 Python 파일 실행하고 결과 가져오기 2012.02.02 38534 0
80 C C언어용 문자열 replaceAll 함수 2009.02.09 38775 0
79 C 힙 정렬 Heap Sort file 2005.08.10 38811 0
78 C# 디렉토리 경로 입력 받기 2010.03.15 38955 0
77 C 퀵 정렬 Quick Sort file 2005.08.10 39253 0
76 일반 ClearCase 팁 1 2009.11.26 39281 0
75 Android 이클립스(Eclipse)에서 유용한 단축키 일람 1 2013.05.21 39559 0
74 C Linked List 예제 (요셉의 문제 - 환형 연결 리스트) file 2005.08.10 39776 0
73 LINUX 리눅스 파일시스템 체크 하기 fsck(e2fsck) 사용법 2016.04.15 40491 0
72 MFC 현재 실행된 어플리케이션의 디렉토리 적용하기 2008.05.07 40678 0
목록
Board Pagination ‹ Prev 1 ... 24 25 26 27 28 29 30 31 32 33 34 Next ›
/ 34

나눔글꼴 설치 안내


이 PC에는 나눔글꼴이 설치되어 있지 않습니다.

이 사이트를 나눔글꼴로 보기 위해서는
나눔글꼴을 설치해야 합니다.

설치 취소

Designed by sketchbooks.co.kr / sketchbook5 board skin

Sketchbook5, 스케치북5

Sketchbook5, 스케치북5

Sketchbook5, 스케치북5

Sketchbook5, 스케치북5