Click here to Skip to main content
Licence CPOL
First Posted 26 Dec 2006
Views 65,858
Downloads 1,168
Bookmarked 43 times

Desktop Sheep

By | 22 Mar 2008 | Article
Animated sheep for your desktop
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 on 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 sheep slaughtered!

Explanation

I'm 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 three sheepfaces, the sheep movement on the desktop.
  • One Notify icon to control the application.
  • One Context menu popped from the notify icon.

Start Cooking

The form which has 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 is done by using a variable sheepSpeed which is 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 is 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 pixels at a time"
        }

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

        private void slowToolStripMenuItem_Click(object sender, EventArgs e)
        {
            sheepSpeed = 1; //slow, "moves 1 pixels 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 boundaries nevertheless; I endup with adding 22 pixels to fix
the Form Y location. Now I'm using:

System.Windows.Forms.Screen.PrimaryScreen.WorkingArea

Only now can I remove the 22 tweaking pixels. Thanks to cokeman's feedback!

Notes

Because CodeProject doesn't allow EXEs in article submission, 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©

Retired
QSoft
Yemen Yemen

Member

Biography?! I'm not dead yet!
www.QSoftOnline.com

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionHow would i be able to... [modified] PinmemberC# Beginner Nick14:43 3 Oct '07  
Hey, I was checking out you're codes then started up on a little program of my own.
 
How would I, instead of the sheep moving acrost the screen, make a picture show up in the buttom right corner and allow me to click/hold and move it anywhere and it will drop back down to the status bar and walk back to the bottom right corner?
 
I know it's possible, i just don't know if it's possible in C#.
 
I'm not very good at coding. I've only been looking and learning for the last few days off of here.
 
If anyone can help it be appreciated.
 

-- modified at 21:01 Wednesday 3rd October, 2007
 
Also, how would i add in a initialize program code?
 
What i mean by that is; A code that when i click the button it will open the correct program i list to it.
 
For Example: The button says 'Enternet' I'd like when i click it, it will open Enternet Explorer for me.
AnswerRe: How would i be able to... PinmemberMuammar©3:23 4 Oct '07  
Questionmodifying source files?? PinmemberMuammar©20:09 7 Jan '07  
JokeSheeps slaughtered!! PinmemberMuammar©22:36 5 Jan '07  
GeneralRe: Sheeps slaughtered!! PinmembernEo.X15:21 6 Jan '07  
GeneralRe: Sheeps slaughtered!! PinmemberMuammar©19:10 6 Jan '07  
GeneralEXE PinmemberPolymorpher15:31 3 Jan '07  
GeneralRe: EXE PinmemberMuammar©22:21 5 Jan '07  
GeneralRe: EXE PinmemberThe_Mega_ZZTer5:41 6 Jan '07  
GeneralRe: EXE PinmemberPolymorpher10:09 6 Jan '07  
GeneralRe: EXE PinmemberMuammar©19:21 6 Jan '07  
GeneralRe: EXE PinmemberPolymorpher20:15 6 Jan '07  
GeneralRe: EXE PinmemberMuammar©20:43 6 Jan '07  
QuestionNot working in VB PinmemberPatel Pranav18:37 2 Jan '07  
AnswerRe: Not working in VB PinmemberMuammar©22:13 5 Jan '07  
QuestionNET? PinmemberRadek Chalupa10:42 2 Jan '07  
AnswerRe: NET? PinmemberMuammar©21:47 5 Jan '07  
NewsBehind the task bar PinmemberSantosh M. P.22:18 27 Dec '06  
GeneralRe: Behind the task bar PinmemberMuammar©5:19 30 Dec '06  
GeneralRe: Behind the task bar PinmemberThe_Mega_ZZTer5:44 6 Jan '07  
GeneralRe: Behind the task bar PinmemberMuammar©19:25 6 Jan '07  
GeneralRe: Behind the task bar PinmemberThe_Mega_ZZTer12:28 7 Jan '07  
GeneralRe: Behind the task bar PinmemberMuammar©19:03 7 Jan '07  
AnswerFixed:) PinmemberMuammar©19:32 7 Jan '07  
Generalthx for fun Pinmembersubai18:08 26 Dec '06  

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

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

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120529.1 | Last Updated 23 Mar 2008
Article Copyright 2006 by Muammar©
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid