본문 바로가기

C#

System.Windows.Forms.ControlPaint 클래스의 FillReversibleRectangle 메서드를 이용해서 반전

반응형

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace AboutFillResersibleRectangle
{
   
public partial class Form1 : Form
   
{
       
private Timer timer = new Timer();

       
public Form1()
       
{
           
InitializeComponent();
       
}

       
void timer_Tick(object sender, EventArgs e)
       
{
           
Rectangle highLight = this.btn_test.Bounds;
            highLight
.Location = this.PointToScreen(this.btn_test.Bounds.Location);

           
ControlPaint.FillReversibleRectangle(highLight, Color.Black);
       
}

       
private void Form1_Load(object sender, EventArgs e)
       
{
           
            timer
.Tick += new EventHandler(timer_Tick);
            timer
.Interval = 500;
       
}

       
private void Form1_Activated(object sender, EventArgs e)
       
{
            timer
.Start();
       
}

       
private void Form1_Deactivate(object sender, EventArgs e)
       
{
            timer
.Stop();
       
}

   
}
}

 

private Timer timer = new Timer();

타이머를 통한 Rectangle 동작은 유지하되,

폼의 활성 / 비활성 상태에 따른 제어를 하도록 코드를 일부 수정하였습니다.

그리고 활성화, 비활성화에대한 이벤트를 추가하여, 타이머를 제어하도록 하였습니다.

 

private void Form1_Activated(object sender, EventArgs e)
{
timer.Start();
}

private void Form1_Deactivate(object sender, EventArgs e)
{
timer.Stop();
}

 

포럼답변 : http://social.msdn.microsoft.com/Forums/ko-KR/visualcsharpko/thread/668a7a2a-2568-4547-a04a-e8d90a8d6d63

반응형