using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
namespace GDIexam_02
{
class GDI02 : Form
{
ListBox lb = null;
public GDI02()
{
this.Text = "리스트박스 예제";
lb = new ListBox();
lb.SetBounds(100, 100, 80, 100);
this.Controls.Add(lb);
lb.Items.Add("사과"); //0
lb.Items.Add("포도"); //1
lb.Items.Add("수박"); //2
lb.DrawItem += new DrawItemEventHandler(lb_DrawItem);
lb.MeasureItem += new MeasureItemEventHandler(lb_MeasureItem);
this.Controls.Add(lb);
this.Load += new EventHandler(GDI02_Load);
}
static void Main(string[] args)
{
Form f = new Form();
Application.Run(new GDI02());
}
private void GDI02_Load(object sender, EventArgs e)
{
lb.DrawMode = DrawMode.OwnerDrawVariable;
}
private void lb_DrawItem(object sender, DrawItemEventArgs e)
{
Graphics g = e.Graphics;
Brush brush = Brushes.Aqua;
switch(e.Index)
{
case 0:
brush = Brushes.Red;
break;
case 1:
brush = Brushes.Violet;
break;
case 2:
brush = Brushes.Gray;
break;
default:
break;
}
g.DrawString(lb.Items[e.Index].ToString(), e.Font,brush,e.Bounds, StringFormat.GenericDefault);
g.Dispose();
}
private void lb_MeasureItem(object sender, MeasureItemEventArgs e)
{
}
}
}