광고
광고
반응형
C# ini 사용하기
- ini 데이터 저장
- ini 데이터 가져오기
IniFile 클래스(유틸) 생성
using System.Runtime.InteropServices; using System.Text; namespace formsApp { class IniFile { [DllImport("kernel32")] private static extern long WritePrivateProfileString(string section, string key, string val, string filePath); [DllImport("kernel32")] private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath); public static void SetValue(string path, string Section, string Key, string Value) { WritePrivateProfileString(Section, Key, Value, path); } public static string GetValue(string path, string Section, string Key, string Default) { StringBuilder temp = new StringBuilder(255); int i = GetPrivateProfileString(Section, Key, Default, temp, 255, path); if (temp != null && temp.Length > 0) return temp.ToString(); else return Default; } } }
IniFile 클래스(유틸) 사용
//ini파일 경로 지정 String iniPath = Application.StartupPath + @"\config.ini"; //저장하기 IniFile.SetValue(iniPath, "Public", "Data1", "첫번째 데이터"); IniFile.SetValue(iniPath, "Public", "Data2", "두번째 데이터"); IniFile.SetValue(iniPath, "Private", "Date1", "첫 데이터"); //가져오기 String pubData1 = IniFile.GetValue(iniPath, "Public", "Data1", "기본값"); String pubData2 = IniFile.GetValue(iniPath, "Public", "Data2", "기본값"); String priData1 = IniFile.GetValue(iniPath, "Private", "Data1", "기본값");
소스 다운↓↓↓
IniFile.cs
0.00MB
반응형
'윈폼(Winform)' 카테고리의 다른 글
C# 가상키보드 띄운 후 위치, 크기 조정하기 (1) | 2021.12.05 |
---|---|
C# Reflection(클래스의 필드명 모두 가져오고, 값 넣기) (0) | 2021.11.20 |
C# 소수점 반올림, 올림, 버림(Round, Ceiling, Truncate) (0) | 2021.11.20 |
C# 동적 개수의 파라메타(params) 받기 (0) | 2021.11.20 |
C# 비밀번호 체크(영문, 숫자, 특수문자, 길이 체크) (0) | 2021.11.18 |
최근댓글