문제
C#에서 X 시간 동안 양식을 보이지 않게 만들려고합니다. 어떤 아이디어?
고마워요, 존
해결책
Bfree는 이것을 테스트하는 데 걸리는 시간에 비슷한 코드를 게시했지만 여기에 내 시도가 있습니다.
this.Hide();
var t = new System.Windows.Forms.Timer
{
Interval = 3000 // however long you want to hide for
};
t.Tick += (x, y) => { t.Enabled = false; this.Show(); };
t.Enabled = true;
다른 팁
클로저를 활용하는 빠르고 더러운 솔루션. 타이머가 필요하지 않습니다!
private void Invisibilize(TimeSpan Duration)
{
(new System.Threading.Thread(() => {
this.Invoke(new MethodInvoker(this.Hide));
System.Threading.Thread.Sleep(Duration);
this.Invoke(new MethodInvoker(this.Show));
})).Start();
}
예시:
// 양식을 5 초 동안 보이지 않습니다
Invisibilize (New Times -span (0, 0, 5));
수업 수준에서는 다음과 같은 일을합니다.
Timer timer = new Timer();
private int counter = 0;
생성자에서 다음을 수행합니다.
public Form1()
{
InitializeComponent();
timer.Interval = 1000;
timer.Tick += new EventHandler(timer_Tick);
}
그런 다음 이벤트 처리기 :
void timer_Tick(object sender, EventArgs e)
{
counter++;
if (counter == 5) //or whatever amount of time you want it to be invisible
{
this.Visible = true;
timer.Stop();
counter = 0;
}
}
그런 다음 어디에나 보이지 않게하려면 (버튼 클릭으로 여기에서 보여 드리겠습니다) :
private void button2_Click(object sender, EventArgs e)
{
this.Visible = false;
timer.Start();
}
사용 가능한 여러 유형의 타이머가 있습니다.http://msdn.microsoft.com/en-us/magazine/cc164015.aspx
또한 자신을 방해하지 않도록 핸들러 기간 동안 타이머를 비활성화하는 것을 잊지 마십시오. 오히려 창피합니다.
제휴하지 않습니다 StackOverflow