C#
-
C# ini 파일 읽고 쓰기닷넷/C# 2016. 8. 18. 11:23
ini 파일은 Config 파일이나 데이터 파일을 만들때 주로 사용하는 확장자이며 파일이다. C#에서 ini파일을 어떻게 생성하고 데이터를 어떻게 저장하는지, 또 어떻게 읽는지 알아보자. 제일 먼저 InteropServices 지시문 추가 using System.Runtime.InteropServices; namespace MyNameSpace { class MyClass { // ini 파일을 불러올 때 사용되는 함수 [DllImport("kernel32")] private static extern int GetPrivateProfileString(string lpAppName, string lpKeyName, string lpDefault, StringBuilder lpReturnedString, i..
-
C# 현재위치(경로) 가져오는 방법닷넷/C# 2016. 8. 16. 17:32
출처: http://rocabilly.tistory.com/114적어 놓은 게 있었는데 없어져서,다시 작성하려고 했으나 잘 정리된 글이 있어서 퍼옴. 1. Application.StartupPath - 현재 application이 존재하는 경로- winform 인 경우에만 사용가능- 레지스트리 관계없이 실제 실행 파일- Application.ExcutablePath 와 동일- string filePath = Application.StartupPaht + @"\\testFile.txt"; 2. System.Environment.CurrentDirectory - 현재 작업 실행되는 경로- winform 이외의 개발 환경에서도 사용가능- winform 에서는 "C:\Windows\System32" 경로가 나옴..
-
C# 컨트롤 사이즈에 맞춰서 폰트 크기 자동조절닷넷/WinForms 2016. 8. 12. 17:12
Label로 예를 들면 속성 중에 Autosize를 true로 하면 폰트 크기에 따라서 Label의 크기가 달라지는데 반대로 Autosize를 false로 하고, Label의 사이즈에 따라서 글씨 크기를 조절하는 방법은 다음과 같다. public Font AutoFontSize(Label label, String text) { Font ft; Graphics gp; SizeF sz; Single Faktor, FaktorX, FaktorY; gp = label.CreateGraphics(); sz = gp.MeasureString(text, label.Font); gp.Dispose(); FaktorX = (label.Width) / sz.Width; FaktorY = (label.Height) / sz..
-
C# 폼 이동 방법닷넷/WinForms 2016. 7. 19. 18:53
폼의 타이틀을 없앴거나 타이틀 외에도 다른 부분을 클릭해서 폼을 움직이게하고자 한다면아래와 같이 코딩하면 된다. private bool onDrag = false; private Point point0; private void frmMain_MouseDown(object sender, MouseEventArgs e) { this.onDrag = true; this.point0 = new Point(e.X, e.Y); } private void frmMain_MouseMove(object sender, MouseEventArgs e) { if (this.onDrag == false) return; int x0 = this.Location.X; int y0 = this.Location.Y; int dx = ..
-
C# WindowsForm에서 배경 투명하게 하는 방법닷넷/WinForms 2016. 7. 19. 18:21
WindowsForm의 특정부분만 투명하게 하는 방법은폼 속성의 TransparencyKey을 이용하면 된다. 예를 들어 FormBorderStyle을 None으로 하고 배경이미지를 넣었을 경우에 아래와 같이 이미지 외의 배경이 폼색으로 되는데 이 것을 투명하게 해주려면 폼 속성에서 BackColor와 TransparencyKey를 같은 색상으로 맞추면 된다. 이 외에 특정영역만 투명하게 하고자 한다면 레이블이나 패널등을 이용해레이블 또는 패널의 BackColor 속성과 폼의 TransparencyKey 속성을 같은 색상으로 해주면 된다.
-
C# MSSQL 연결닷넷/C# 2016. 7. 5. 13:45
using System.Data.SqlClient; // MSSQL 연결 할 때 제일 먼저 선언해 줄 것! Sql 아닙니다. SqlClient 입니다. namespace Monitoring{ public partial class frmMain : Form { public frmMain() { InitializeComponent(); } private void frmMain_Load(object sender, EventArgs e) { SqlConnection sqlConnection = new SqlConnection("Server=서버주소;Database=데이터베이스이름;User ID=아이디;Password=비밀번호"); if (sqlConnection != null && sqlConnection.S..