본문 바로가기

forms13

WinForms ] Anchor, Dock properties Anchor 속성의 default 값은 Top, Left인데 이 값을 변경하면 bold 체로 바뀐다. Anchor 속성 미사용시 Anchor 속성 사용 Dock 속성 default 값은 None이다. toolStrip은 top에 dock하고 statusStrip은 bottom에 dock할 수 있다. 여러 컨트롤을 같은 방향에 dock할 수 있고 어떤걸 먼저 dock하느냐에 따라 화면에 표시되는게 달라진다. textBox의 multiLine 속성을 true로하고 dock 속성을 fill로 하면 마치 메모장같은 GUI를 볼 수 있다. splitContainer를 먼저 만들고 그 안에서 컨트롤을 dock하는 것도 가능하다. 2023. 5. 14.
C#, WinForms ] CRC Checker private void button1_Click(object sender, EventArgs e) { // 초기 디렉토리 설정 openFileDialog1.InitialDirectory = "C:\\"; // 파일 필터 설정 openFileDialog1.Filter = "모든 파일 (*.*)|*.*|텍스트 파일 (*.txt)|*.txt|바이너리 파일 (*.bin)|*.bin|데이터 파일 (*.dat)|*.dat"; // 마지막으로 파일 대화 상자에서 선택한 디렉토리를 기억하고, 다음번 파일 대화 상자를 열 때에는 이전에 선택한 디렉토리를 자동으로 선택 openFileDialog1.RestoreDirectory = true; if (openFileDialog1.ShowDialog() == DialogRes.. 2023. 5. 14.
C#, WinForms ] Drag & Drop 으로 파일 경로 얻기 파일 시스템에 액세스하기위해 using System.IO; 선언 Form의 AllowDrop 속성 true 일반적으로 Form이나 Control에는 파일을 Drop할 수 없기 때문에, 해당 Form이나 Control에 AllowDrop 속성을 true로 설정해주어야 한다. this.AllowDrop = true; DragEnter, DragDrop 이벤트 핸들러 추가 this.DragDrop += new System.Windows.Forms.DragEventHandler(this.Form1_DragDrop); this.DragEnter += new System.Windows.Forms.DragEventHandler(this.Form1_DragEnter); DragEnter 이벤트 : 사용자가 무언인가를 .. 2023. 5. 14.
Winforms ] ToopStrip, MenuStrip 속성 ToolStrip 화살표클릭 - Dock 을 통해 ToolStrip의 위치를 정할 수 있으며 ToolStrip size는 Form의 size에 맞게 자동 조정된다. 그리고 아래 버튼을 클릭해 다양한 컨트롤을 ToolStrip 안에 추가할 수 있다. ToolStrip 을 선택하며 속성을 변경할 수 있고, ToolStrip 내의 컨트롤을 클릭하여 각자 속성을 변경할 수도 있다. ToolStrip 내의 컨트롤을 우클릭하여 주요 속성을 변경할 수도 있는데 ToolStripButton 의 경우 DisplayStyle 을 Text/Image/ImageAndText 중에서 선택할 수 있다. AutoSize 를 False로 하면 ToolStrip의 크기를 임의로 조절할 수 있다. 우클릭 - 이미지 설정 또는 속성의 I.. 2023. 5. 14.
WinForms ] 콘솔창 출력 솔루션 우클릭 Properties - Application 탭 - Output type : Console Application 선택 이제 Console.WriteLine();으로 출력할 수 있다. 2023. 5. 14.
WinForms ] Label vs TextBox 컨트롤 결론 : 사용자가 편집할 수 있게끔 하려면 TextBox, 아닌 경우 Label 사용 추천 There are a few pro's and con's to both. Label Pro's: Text is not copy able Cursor does not change Sets size based on text (if autosize is on, I think its on by default) Option to align text to the right (autosize off) Con's: Text is not selectable/copy able Text might outgrow form/parent with autosize TextBox Pro's: Text is copy able Fixed size.. 2023. 4. 9.
C#, WinForms ] 정수인지 실수인지 확인하기, Integer / Real number 구분 Math.Floor() 함수를 사용하면된다. 내림한게 원래 값과 같으면 정수, 아니면 실수이다. double result = first + second; if(Math.Floor(result) == result) { this.label1.Text = string.Format("{0:#,##0}", result); } else { this.label1.Text = string.Format("{0:#,##0.########################}", result); } 2023. 2. 25.
C#, WinForms ] OpenFileDialog, 이미지 pictureBox에 로드하기 private void button1_Click(object sender, EventArgs e) { OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = "Image Files (*.bmp;*.jpg;*.jpeg;*.png)|*.BMP;*.JPG;*.JPEG,*.PNG"; dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures); if(dialog.ShowDialog() == DialogResult.OK) { textBox1.Text = dialog.FileName; pictureBox1.SizeMode = PictureBoxSizeMode.S.. 2023. 2. 22.
C#, WinForms ] 문자열 앞에 (심벌)@사용 @ 심벌을 문자열 앞에 사용하면, 해당 문자열 안의 Escape 문자를 무시하고 문자 그대로 인식하도록 한다. 예를 들어, Backslash를 한번 지정하면 이는 Escape문자로 인식되기 때문에 2개의 Backslash를 사용하게 되는데, @ 심벌을 문자열 시작 부호전에 사용하면, Backslash를 그대로 Backslash로 인식하게 한다. 예시1. string filename = "C:\\Temp\\1.txt"; string filename = @"C:\Temp\1.txt"; 예시2. this.textBox1.Text = duration.ToString(@"hh\:mm\:ss\.fff"); this.textBox1.Text = duration.ToString("hh\\:mm\\:ss\\.fff");.. 2023. 2. 21.
C#, WinForms ] 스탑워치, Stopwatch 클래스, DateTime 구조체, Timer 활용 using System.Diagnostics; //... private Stopwatch stopwatch = new Stopwatch(); public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { // textBox 초기값 this.textBox2.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); this.textBox2.Text = ""; } private void button1_Click(object sender, EventArgs e) { // Stopwatch, Timer 스타트 stopwatch.Start(); this.timer1.St.. 2023. 2. 20.