Click here to Skip to main content
11,922,641 members (56,834 online)
Click here to Skip to main content
Add your own
alternative version


54 bookmarked


, 11 Sep 2008 CPOL
Rate this:
Please Sign up or sign in to vote.
Creating an eye control.

Sample Image


This article demonstrates how to create a perfect, useless control using C# WinForms and .NET 2.0. The control uses pure managed code, and all visual elements can be adjusted through its properties.


Is it not all developer's deepest desire to create something living? Well, not me! This was solely to have fun playing with the graphics. So, don't expect to see a mouth, nose, or brains in the future.

The Graphics

The process of building the eye.

Above are the basic elements of the eye: background, iris, shadow, pupil, reflex, and the eye-lid. The eye is drawn in this order.


The Eye is a single class that inherits from the System.Windows.Forms.Control. Below are the properties and methods of the Eye class.

The Eye class

Using the Code

Using the Eye class is straightforward, but some properties may need some explanation.

  • BlinkStep is the rate in which the eye will close when blinking.
  • FocusPoint is the point the eye will look, in screen coordinates.
  • FocusAngle and FocusDistance are derived (read only) from FocusPoint.
  • LidOffset is used when TypeOfEye is Left or Right.

    The offset in pixels is the width of the iris divided by the value. Minimum is 3.

  • SlitSize is a percentage of the eye height.
  • TypeOfEye is an enum, and can take the values Left, Right, and Cyclops (default).
  • Blink() starts a new thread that will blink the eye.

The detailed iris is done using a color blend:

using (var path = new GraphicsPath())
  using (var gradientBrush = new PathGradientBrush(path))
    gradientBrush.CenterPoint = centerPoint;
    var cb = new ColorBlend(4)
                 Colors = irisColors,
                 Positions = new[] { 0.0F, 0.05F, 0.1F, 1.0F }
    if (cb.Colors == null) return;
    gradientBrush.InterpolationColors = cb;
    g.FillPath(gradientBrush, path);

Points of Interest

I attempted to squeeze the iris rectangle to make it more eye-like when going to the edge, but it never quite looked right.

History and Credits

This is the first version - 1.0.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Niel M.Thomas
Denmark Denmark
Name: Niel Morgan Thomas
Born: 1970 in Denmark
Dataengineer from Odense Technical University.
More than 20 years in IT-business.
Current employment:
Working with application development in a major Danish company that produce medical equipment.

You may also be interested in...

Comments and Discussions

QuestionReport Required (urgent) Pin
Member 99149963-Dec-13 3:56
memberMember 99149963-Dec-13 3:56 
GeneralNice idea and well done! Pin
Martin#7-Apr-09 2:45
memberMartin#7-Apr-09 2:45 
GeneralToo Cool! Pin
ArchKaine17-Sep-08 14:25
memberArchKaine17-Sep-08 14:25 
GeneralAbth Project Pin
Yildirim Kocdag15-Sep-08 21:16
memberYildirim Kocdag15-Sep-08 21:16 
Good job.
GeneralEyes Pin
Greg.Farquhar15-Sep-08 21:10
memberGreg.Farquhar15-Sep-08 21:10 
GeneralToo late (grin) Pin
fredsparkle15-Sep-08 7:56
memberfredsparkle15-Sep-08 7:56 
QuestionProblems with source Pin
rht34110-Sep-08 8:13
memberrht34110-Sep-08 8:13 
AnswerRe: Problems with source [modified] Pin
Niel M.Thomas10-Sep-08 9:16
memberNiel M.Thomas10-Sep-08 9:16 
GeneralReally cool demo! Pin
Johnny J.10-Sep-08 0:00
memberJohnny J.10-Sep-08 0:00 
JokeRe: Really cool demo! Pin
markkuk10-Sep-08 0:16
membermarkkuk10-Sep-08 0:16 
GeneralGreat Project !!! Pin
Rin Reaksmey9-Sep-08 17:07
memberRin Reaksmey9-Sep-08 17:07 
Generalpersonally... PinPopular
Scott Bruno9-Sep-08 12:19
memberScott Bruno9-Sep-08 12:19 
GeneralRe: personally... Pin
Ilíon10-Sep-08 0:48
memberIlíon10-Sep-08 0:48 
GeneralRe: personally... Pin
Scott Bruno10-Sep-08 3:24
memberScott Bruno10-Sep-08 3:24 
GeneralRe: personally... Pin
Ilíon10-Sep-08 7:23
memberIlíon10-Sep-08 7:23 
GeneralRe: personally... Pin
Scott Bruno10-Sep-08 9:54
memberScott Bruno10-Sep-08 9:54 
GeneralRe: personally... Pin
Ilíon10-Sep-08 13:22
memberIlíon10-Sep-08 13:22 
GeneralRe: personally... Pin
sinklink13-Sep-08 20:15
membersinklink13-Sep-08 20:15 
GeneralRe: personally... Pin
Ilíon14-Sep-08 9:15
memberIlíon14-Sep-08 9:15 
GeneralRe: personally... Pin
MarkRedman15-Sep-08 8:21
memberMarkRedman15-Sep-08 8:21 
GeneralRe: personally... Pin
hackman3vilGuy15-Sep-08 10:21
memberhackman3vilGuy15-Sep-08 10:21 
GeneralRe: personally... Pin
Leblanc Meneses8-Nov-08 21:53
memberLeblanc Meneses8-Nov-08 21:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.151125.1 | Last Updated 11 Sep 2008
Article Copyright 2008 by Niel M.Thomas
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid