728x90
728x90
SMALL

전체 글 216

[C#] 문자열을 속성으로 갖는 클래스 만들기

1. 소스using System.Reflection; /// /// 문자열을 속성으로 갖는 클래스 /// public class StringValue : System.Attribute { private string _value; /// 문자열 속성값 /// /// 속성값을 설정한다. /// /// 속성값 public StringValue(string value) { _value = value; } /// /// 속성값을 가져온다. /// public string Value { get { return _value; } } } /// /// 자료형 enum에 문자열을 사용할 수 있게 하는 클래스 /// public static class StringEnum { /// /// enum에 Str..

유용한 정보 2025.04.16

[C#] INI Parser

1. 소스/// /// INI파일의 파서 /// [ComVisible(true)] [ClassInterface(ClassInterfaceType.None)] public class IniParser : IIniParser { private Hashtable KeyPairs = new Hashtable(); private string IniFilePath = ""; /// /// 대소문자 구분을 하는지의 여부 /// private bool ToCase = false; /// /// INI파일을 오픈했는지의 여부 /// public bool IsOpened = false; [StructLayout(LayoutKind.Sequential, Pack = 1)] private class StringPa..

유용한 정보 2025.04.16

[C#] 컨트롤에 들어갈 문자열의 폭과 높이 구하기

1. 소스/// /// 컨트롤에 들어갈 문자열의 폭과 높이를 구한다. /// /// 문자열 /// 컨트롤 /// 폭과 높이 static public SizeF GetStringSize(string str, Control ctrl) { try { float wi = float.MinValue, hi; Font font = ctrl.Font; Bitmap tmpBit = new Bitmap(1, 1); Graphics graphic = Graphics.FromImage(tmpBit); Brush TextColor = Brushes.Black; graphic.DrawString(str, font, TextColor, new PointF(0, 0), StringFormat.GenericDefault); va..

유용한 정보 2025.04.16

[C#] 컨트롤에 들어갈 문자열에서 가장 큰 폭과 높이 구하기

1. 소스/// /// 컨트롤에 들어갈 문자열에서 가장 큰 폭과 높이를 구한다. /// /// 문자열 /// 컨트롤 /// 폭과 높이 static public SizeF GetMaxSize(IEnumerable strings, Control ctrl) { try { float wi = float.MinValue, hi = 0; foreach (string v in strings) { SizeF size = GetStringSize(v, ctrl); hi += size.Height; if (size.Width > wi) wi = size.Width; } return new SizeF(wi, hi); } catch (Exception ex) { KLog.Write(ex.ToString()); } retu..

유용한 정보 2025.04.16

[C#] DataGridView 에 수직스크롤바가 있는지의 여부 판단하기

1. 소스/// /// 주어진 DataGridView 컨트롤에 수직스크롤바가 있는지의 여부를 구한다. /// /// /// /// - true : 수직스크롤바가 있다. /// - false : 수직스크롤바가 없다. /// bool ExistsVScroll(DataGridView dgv) { try { int height; if (dgv.Rows.Count > 0) height = dgv.Rows[0].Height; else height = dgv.ColumnHeadersHeight; return height * dgv.Rows.Count >= (dgv.Height - dgv.ColumnHeadersHeight); } catch (Exception ex) { KLog.Write(ex.ToStrin..

유용한 정보 2025.04.16

[C#] DataGridView 의 RowHeader 에 일련번호 자동생성하기

/// /// DataGridView 의 RowHeader 에 일련번호 자동생성 /// /// DataGridView 컨트롤 /// 이벤트정보 static void DGV_AutoRowIndex(object sender, DataGridViewRowPostPaintEventArgs e) { DataGridView dgv = sender as DataGridView; try { if (dgv != null && dgv.Rows.Count > 0 && e.RowIndex >= 0) { String rowIdx = (e.RowIndex + 1).ToString(); StringFormat centerFormat = new StringFormat() { Alignment = StringAlignment.Ce..

유용한 정보 2025.04.16

[C#] DataGridView 의 데이터 검색하기

/// /// DataGridView 컨트롤에서 데이터를 검색한다. /// 검색하려는 데이터의 개수와 인덱스의 개수는 같아야 한다. /// /// DataGridView 컨트롤 /// 검색하려는 데이터 /// 검색하려는 열의 인덱스 /// 검색 시작 행의 인덱스 /// 검색된 데이터 List FindDataGridView(DataGridView dgv, IEnumerable values, IEnumerable columns, int startindex = 0) { List results = new List(); if (dgv == null || dgv.RowCount || values == null || values.Count() || columns == null || columns.Count() |..

유용한 정보 2025.04.16

[C#] DataGridView에서 행이 비어있는지 체크

/// /// 주어진 행이 비어있는지 체크한다. /// /// 행번호(zero-based) /// 주어진 행이 비어있으면 참, 그렇지않으면 거짓 bool IsNullOrEmpty(DataGridViewRow row) { try { foreach (DataGridViewCell cell in row.Cells) { string cellvalue = cell.Value as string; if (cellvalue != null && !string.IsNullOrEmpty(cellvalue.Trim())) return false; } } catch (Exception ex) { KLog.Write(ex.ToString()); } return true; }

유용한 정보 2025.04.16
728x90
728x90
LIST