5,427,303 members and growing! (15,831 online)
Email Password   helpLost your password?
Languages » C# » General     Beginner License: The Code Project Open License (CPOL)

Desktop Sheep

By Muammar©

Animated sheep for your desktop
C#, Windows, .NET, Visual Studio, Dev

Posted: 26 Dec 2006
Updated: 23 Mar 2008
Views: 36,918
Bookmarked: 35 times
Announcements
Want a new Job?



Search    
Advanced Search
Sitemap
34 votes for this Article.
Popularity: 4.77 Rating: 3.12 out of 5
9 votes, 26.5%
1
5 votes, 14.7%
2
2 votes, 5.9%
3
6 votes, 17.6%
4
12 votes, 35.3%
5
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report This Article

Sample Image - Desktop_Sheep.jpg

Introduction

I really don’t know what to say about this article but I'd like to stress on "It only took me one hour to code this application so be nice and don’t beat me so hard with your comments".

Well, I just read a nice article this morning by Igor Tolmachev called Falling Snow on Your Desktop! here in the CP and said Merry X-Mas to everyone, but I thought there are good muslems here in the forum who would like to hear Happy Eid because it's about time too they have their sheeps slaughtered!

Explanation

Im sorry but I think there's nothing to explain about such an easy piece of application,
but here's what I would call the recipé:

Ingredients

Three Image objects are created for the three faces of the good sheep.

Sheep1 = Image.FromFile("Sheeps\weird_sheep1.gif");
Sheep2 = Image.FromFile("Sheeps\weird_sheep2.gif");
Sheep3 = Image.FromFile("Sheeps\weird_sheep3.gif");

Two timers to control the sheep 3 faces, the sheep movement on the desktop.

One Notify icon to control the application.

One Context menu poped from the notify icon.

Start Cooking

The form on which is the sheep is set to transparent using the transparency key property, form borders are removed, and a picture box control is added and docked to the parent container form.

The timers are started when the form is loaded with the interactivity of adjusting the sheep speed, this's done by using a variable sheepSpeed which's modified during run-time using the notify icon's context menu.

The Code

//By Muammar Yacoob

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Sheep
{
    public partial class Form1 : Form
    {
        int flipper, screenW, screenH;  //variable i'll be using later
        int sheepX, sheepSpeed; 
        Image Sheep1, Sheep2, Sheep3;   //to set the location and speed
        public Form1()                  //image files are attached here 
                                        //of the form (the sheep)
        {
            InitializeComponent();
            Sheep1 = Image.FromFile(@"Sheeps\weird_sheep1.gif");
            Sheep2 = Image.FromFile(@"Sheeps\weird_sheep2.gif");
            Sheep3 = Image.FromFile(@"Sheeps\weird_sheep3.gif");
            flipper = 1;
            screenW
               = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width;
            screenH
               = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height;
            sheepX = screenW;
            sheepSpeed = 2;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //setting the initial location for the form
            this.Location = new Point(screenW, screenH - this.Height);
            //initializing the form with sheep face1
            BoxSheep.Image = Sheep1;                     
            tmrSheeper.Start(); //starts changing the image
            tmrMoveit.Start();   //starts moving the form
        }

        private void tmrSheeper_Tick(object sender, EventArgs e)
        {
            switch (flipper)
            {
                case 1:
                    BoxSheep.Image = Sheep1;
                    flipper++;
                    break;
                case 2:
                    BoxSheep.Image = Sheep2;
                    flipper++;
                    break;
                case 3:
                    BoxSheep.Image = Sheep3;
                    flipper = 1; //back to face1
                    break;
            }
        }

        private void tmrMoveit_Tick(object sender, EventArgs e)
        {   //############ We add this line to get the sheep ###########//
            //############ on the taskbar after modifying it ###########//
            screenH = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height;
            //##########################################################//

            if (sheepX >= this.Width * -1) //end of sheep tail
            {
                this.Location = new Point(sheepX, (screenH - this.Height)-22);
                sheepX -= sheepSpeed;      //this's set by the context menu
            }             //by default, it's set to 2 in
            else                     //the constructor
                sheepX = screenW;
        }

        private void aboutToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            About about = new About();
            about.Show();
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            notifyIcon1.Dispose();//getting rid of the notify
            this.Close();         //icon from the system tray
        }

        private void fastToolStripMenuItem_Click(object sender, EventArgs e)
        {
            sheepSpeed = 3; //fast, "moves 3 pixles at a time"
        }

        private void mediumToolStripMenuItem_Click(object sender, EventArgs e)
        {
            sheepSpeed = 2; //medium, "moves 2 pixles at a time"
        }

        private void slowToolStripMenuItem_Click(object sender, EventArgs e)
        {
            sheepSpeed = 1; //slow, "moves 1 pixles at a time"
        }

        private void notifyIcon1_DoubleClick(object sender, EventArgs e)
        {
            About about = new About();
            about.Show();
        }
    }
}

Points of interest

Notice that I've used System.Windows.Forms.Screen.PrimaryScreen.Bounds to get the primary screen boundries nevertheless; I endup with adding 22 pixle to fix
the Form Y location. Now im using:

System.Windows.Forms.Screen.PrimaryScreen.WorkingArea

Only now I can remove the 22 tweaking pixles. Thanx to cokeman's feedback!

Notes

Because CP doesn’t allow EXEs in article submision, I've renamed the .exe demo file
to .zip, so it's actually not a zip file! Please rename it first to .exe before running it.

License

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

About the Author

Muammar©



Occupation: Software Developer
Company: UNDP
Location: Yemen Yemen

Other popular C# articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 25 of 43 (Total in Forum: 43) (Refresh)FirstPrevNext
Subject  Author Date 
QuestionHow would i be able to... [modified]memberC# Beginner Nick15:43 3 Oct '07  
AnswerRe: How would i be able to...memberMuammar©4:23 4 Oct '07  
Generalmodifying source files??memberMuammar©21:09 7 Jan '07  
JokeSheeps slaughtered!!memberMuammar©23:36 5 Jan '07  
GeneralRe: Sheeps slaughtered!!membernEo.X16:21 6 Jan '07  
GeneralRe: Sheeps slaughtered!!memberMuammar©20:10 6 Jan '07  
GeneralEXEmemberPolymorpher16:31 3 Jan '07  
GeneralRe: EXEmemberMuammar©23:21 5 Jan '07  
GeneralRe: EXEmemberThe_Mega_ZZTer6:41 6 Jan '07  
GeneralRe: EXEmemberPolymorpher11:09 6 Jan '07  
GeneralRe: EXEmemberMuammar©20:21 6 Jan '07  
GeneralRe: EXEmemberPolymorpher21:15 6 Jan '07  
GeneralRe: EXEmemberMuammar©21:43 6 Jan '07  
QuestionNot working in VBmemberPatel Pranav19:37 2 Jan '07  
AnswerRe: Not working in VBmemberMuammar©23:13 5 Jan '07  
GeneralNET?memberRadek Chalupa11:42 2 Jan '07  
GeneralRe: NET?memberMuammar©22:47 5 Jan '07  
NewsBehind the task barmemberSantosh M. P.23:18 27 Dec '06  
GeneralRe: Behind the task barmemberMuammar©6:19 30 Dec '06  
GeneralRe: Behind the task barmemberThe_Mega_ZZTer6:44 6 Jan '07  
GeneralRe: Behind the task barmemberMuammar©20:25 6 Jan '07  
GeneralRe: Behind the task barmemberThe_Mega_ZZTer13:28 7 Jan '07  
GeneralRe: Behind the task barmemberMuammar©20:03 7 Jan '07  
AnswerFixed:)memberMuammar©20:32 7 Jan '07  
Generalthx for funmembersubai19:08 26 Dec '06  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 23 Mar 2008
Editor:
Copyright 2006 by Muammar©
Everything else Copyright © CodeProject, 1999-2008
Web09 | Advertise on the Code Project