using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
private Timer oTimer;
private bool isBlueColor = true;
public Form1()
{
InitializeComponent();
oTimer = new Timer();
oTimer.Tick += new EventHandler(oTimer_Tick);
oTimer.Interval = 1000;
oTimer.Start();
}
void oTimer_Tick(object sender, EventArgs e)
{
if (isBlueColor)
{
isBlueColor = false;
}
else
{
isBlueColor = true;
}
this.Invalidate();
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
if (isBlueColor)
{
e.Graphics.FillRectangle(Brushes.Blue, new Rectangle(10, 10, 100, 100));
}
else
{
e.Graphics.FillRectangle(Brushes.Green, new Rectangle(50, 50, 100, 100));
}
}
}
}
Code (VB.NET)
Public Class Form1
Dim oTimer As Timer
Dim isBlueColor As Boolean = True
Sub New()
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
oTimer = New Timer
AddHandler oTimer.Tick, AddressOf oTimer_Tick
oTimer.Interval = 1000
oTimer.Start()
End Sub
Private Sub oTimer_Tick(ByVal sender As System.Object, ByVal e As EventArgs)
If isBlueColor Then
isBlueColor = False
Else
isBlueColor = True
End If
Me.Invalidate()
End Sub
Private Sub Form1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias
If (isBlueColor) Then
e.Graphics.FillRectangle(Brushes.Blue, New Rectangle(10, 10, 100, 100))
Else
e.Graphics.FillRectangle(Brushes.Green, New Rectangle(50, 50, 100, 100))
End If
End Sub
End Class