지식공유/C# 검색 결과
//첫번째 방법 : Control 형식 그대로해서 List에 컨트롤 이름 저장하기 public partial class Form1 : Form { private List m_oLables = new List(); public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { string result_list = ""; for (int i = 0; i < this.Controls.Count; i++ ) Recursive(this.Controls[i]); foreach(var list in m_oLables) { result_list += list.Name; } MessageBox.Show(resul..
//button 2개를 같은 이벤트명으로 사용할 경우 //어떤 버튼에서 클릭했는지 알 수 있는 방법 //2번의 경우가 가장 좋지못한 코딩방법 //1. //클릭한 버튼의 이름명을 갖고옴 //output : button1 private void OnMyButtonClick(object sender, EventArgs e) { MessageBox.Show(""+((Button)sender).Name); } //2. //sender에 있는 객체명과 텍스트값을 갖고옴 //output : System.Windows.Forms.Button, Text : Ready private void OnMyButtonClick(object sender, EventArgs e) { MessageBox.Show(""+sender.T..
//소스 코드상에서 각 버튼의 태그명을 panel1로 설정해두고 //이벤트 발생 시 해당버튼의 태그명을 설정하고 그 다음 //바꿀 값을 설정하면 panel1의 색상이 이벤트에 있는대로 바뀐다. button1.Tag = panel1; button2.Tag = panel1; private void OnMyButtonClick(object sender, EventArgs e) { ((Panel)button1.Tag).BackColor = Color.DimGray; } private void OnMyButtonClick2(object sender, EventArgs e) { ((Panel)button2.Tag).BackColor = Color.DimGray; }
다른클래스에 있는 메서드를 쓰레드로 호출 class Helper { public void Run() { Console.WriteLine("Helper.Run"); } } class Program { static void Main(string[] args) { // Helper클래스의 Run메서드 호출 Helper obj = new Helper(); Thread t = new Thread(obj.Run); t.Start(); } } 쓰레드 생성의 다양한 방법 class Program { static void Main(string[] args) { // Run 메서드를 입력받아 // ThreadStart 델리게이트 타입 객체를 생성한 후 // Thread 클래스 생성자에 전달 Thread t1 = new T..
class dic_class { //딕셔너리 Value에 들어갈 클래스 public dic_class(string N_string, string V_string) { this.Name = N_string; this.Value = V_string; } public string Name { get; set; } public string Value { get; set; } } public partial class Form1 : Form { public Form1() { InitializeComponent(); Dictionary m_oMyItems = new Dictionary(); m_oMyItems.Add("test_string", new dic_class("테스트이름1", "테스트벨류1")); strin..
class Dictionary { /*키 값이 딕셔너리 안에 있는지 확인하는 방법*/ //키는 string , 벨류가 int형인 딕셔너리 생성 Dictionary dictionary = new Dictionary(); public void ContainsKey() { Dictionary dictionary = new Dictionary(); //키가 apple, 값이 1인 데이터 추가 dictionary.Add("apple", 1); //키가 banana, 값이 2인 데이터 추가 dictionary.Add("banana",2); //딕셔너리에 키가 apple인게 있는지 if(dictionary.ContainsKey("apple")) { //참인 경우 딕셔너리[키]에 해당하는 Value값 리턴 int va..
최근댓글