달력

82025  이전 다음

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

'C#'에 해당되는 글 2건

  1. 2016.03.14 [c#] timer
  2. 2016.02.11 [c#] DataGridView

[c#] timer

c# 2016. 3. 14. 21:09

c# 에서 timer는 크게 3종류로 나뉜다는데, 이번에 사용한건 System.Threading.Timer 이다. 

아직도 Thread를 잘 이해하지 못하고 있지만, 여러가지 동작은 병렬로 수행하려면 Thread를 사용해야 할 것 같아서 이를 사용했다. 


class timerTest{

delegate void TimerEventFiredDelegate();


System.Threading.Timer timer;


static void main(string[] args)

{

timer = new System.Threading.Timer(Callback);

timer.Change(0, 1000) //dueTime 은 Timer가 시작되기 전 대기 시간(ms)

}


void Callback(obejct status)

{

BeginInvoke(new TimerEventFiredDelegate(Work));

}


private void Work()

{

//timer로 작업할 내용 

}

}




UI에서 사용할 경우는 Cross-Thread 문제가 발생하므로 Invoke 또는 BeginInvoke 를 사용해서 마샬링(?)을 통한 호출을 처리하여야 한다. 


라는 설명이 있는데 아직 잘 모르겠다.


'c#' 카테고리의 다른 글

[c#] DataGridView  (0) 2016.02.11
Posted by 초코렛과자
|

[c#] DataGridView

c# 2016. 2. 11. 23:31

일을 하다보니 c#을 하게되어 요즘 걸음마 수준으로 c#을 해나가고있다. 간단하게 UI를 구성 할 일이 있어 dataGridView를 사용해 봤는데, 생각보다 좋다. dataGridView에 buttonColumn을 추가하여 사용 하는 방법이다.

이를 응용하면 수정이나 삭제도 가능.

출처 : http://purestarman.tistory.com/m/post/248



private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
    int intchange;
    
    try
    {
        if (dataGridView1.CurrentCell != null)
        {
            // 모든 행의 CheckBox값을 False로 설정
            for (int i = 0; i < dataGridView1.RowCount; i++) 
            {
                dataGridView1[6, i].Value = false; // 6은 CheckBox가 있는 열 번호
            }
            // 현재 선택된 행의 CheckBox값을 True로 설정
            for (int i = 0; i < dataGridView1.SelectedRows.Count; i++) 
            {
                //Convert.ToInt32 => string을 int로 변환
                intchange = Convert.ToInt32(dataGridView1.SelectedRows[i].Cells[0].Value.ToString());
                dataGridView1[6, intchange].Value = true;
            }
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}


'c#' 카테고리의 다른 글

[c#] timer  (0) 2016.03.14
Posted by 초코렛과자
|