C#自定义控件有关问题
C#自定义控件问题
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication3
{
public partial class UserControl1 : UserControl
{
private int count = 4;
public int Count
{
get { return count; }
set
{
count = value;
this.Invalidate();
}
}
public int index = 0;
public string name = "";
public Color color;
public UserControl1()
{
InitializeComponent();
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Graphics g = e.Graphics;
#region 定义颜色
if (index <= count)
{
if (index == 1)
{
color = Color.Red ;
}
if (index == 2)
{
color = Color.Black;
}
if (index == 3)
{
color = Color.Blue;
}
if (index == 4)
{
color = Color.SkyBlue;
}
}
else
{
count = index;
if (index == 5)
{
color = Color.Coral;
}
if (index == 6)
{
color = Color.CornflowerBlue;
}