ComboBox
은 SelectedIndexChanged
일 때 Timer.Interval
으로 변경됩니다. 내 코드는 기본적으로 다음과 같습니다타이머를 EventHandler에 전달하는 방법은 무엇입니까?
public Form1()
{
InitializeComponent();
Timer AutoRefresh = new Timer();
AutoRefresh.Tick += new EventHandler(AutoRefresh_Tick);
var RefreshIntervals = new[] { "4 hours", "2 hours", "1 hour", "15 minutes", "10 seconds" };
comboBox1.DataSource = RefreshIntervals;
comboBox1.SelectedIndexChanged += new EventHandler(comboBox1_SelectedIndexChanged);
}
void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (AutoRefresh.Enabled == true)
AutoRefresh.Enabled = false;
if (comboBox1.SelectedText == "4 hours")
AutoRefresh.Interval = 14400000;
else if (comboBox1.SelectedText == "2 hours")
AutoRefresh.Interval = 7200000;
else if (comboBox1.SelectedText == "1 hour")
AutoRefresh.Interval = 3600000;
else if (comboBox1.SelectedText == "15 minutes")
AutoRefresh.Interval = 900000;
else if (comboBox1.SelectedText == "10 seconds")
AutoRefresh.Interval = 10000;
AutoRefresh.Enabled = true;
}
을 이제 comboBox1_SelectedIndexChanged()
는 Timer
변수에 대한 참조가 없기 때문에 분명이 작동하지 않습니다.
AutoRefresh
을 comboBox1_SelectedIndexChanged()
으로 전달하려면 코드를 어떻게 수정할 수 있습니까?
아마도 나는 C#으로 초보자라는 것을 지적하기에 좋은시기입니다. 친절 하구만.
왜 이러는거야? 무엇을 성취하려고합니까? 설명하면, 더 좋은 방법으로 그것을 얻을 수 있습니다. – Oded
@Oded - 전화하세요. 이 프로그램은 매우 간단합니다 : 새로 고침시 DataTable을 채우는 SQL DB를 쿼리하여 표시합니다. 이 comboBox와 Timer를 사용하여 자동으로 Reoccurring 타이머에서 DataTable을 새로 고치고 사용자가 새 일정 (4 시간, 2 시간, 1 시간, 15 분)을 선택하자마자 Timer 's Interval을 업데이트하려고합니다. – newuser
['SqlDependency'] (http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldependency.aspx) 클래스를 보았습니까? – Oded