Building a Clipboard Ring Utility Application Using C#
page 5 of 7
by Mohammed Habeeb
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 35817/ 53

Yahoo messenger style alert Customization

I always wanted to create a yahoo messenger like alert pop up. So I thought this was the right time to work on it and this is the right application for me to try it. The easiest solution I came, was to use timer component. I know that it needs optimization but this solution works fine. I am happy for the time being :-).

Below is a quick snap of its implementation.

In the form load event two variables xPos, yPos are set. xPos will have the desktop area width and yPos will have the desktop area's height.

GetWorkingArea method of the Screen (System.Windows.Forms.Screen) class retrieves the working area (desktop area in case of our form - working area is dependent on the container of the control) excluding the taskbar and any other docked toolbars.

Listing 8 - Retrieving Desktop Area

xPos = Screen.GetWorkingArea(this).Width; 
yPos = Screen.GetWorkingArea(this).Height;

Basically I have used 2 timer components for this functionality. tmr1 and tmr2. Each has an tick interval of 1 millisecond.

tmr1 is enabled when the notify icon in the system tray is clicked, and each time it ticks the Y location of the form is decreased so that the form raises from the bottom boundary of the screen.

Listing 9 - Timer Eventhandler to popup window

private void tmr1_Tick(object sender, EventArgs e)
{
    int curPos = this.Location.Y;
    if (curPos > yPos - this.Height)
    {
        this.Location = new Point(xPos - this.Width, curPos - 20);
    }
    else
    {
        tmr1.Stop();
        tmr1.Enabled = false;
    }
}

tmr2 is enabled when the close button is clicked, and each time it ticks the Y location of the form is increased to take the form below the visible screen space and ultimately take it out of the visibly of the user. At this point this timer is disabled.

Listing 10 - Timer Eventhandler to hide popup window

private void tmr2_Tick(object sender, EventArgs e)
{
    int curPos = this.Location.Y;
 
    if (curPos < (yPos + 30))
    {
        this.Location = new Point(xPos - this.Width, curPos + 20);
    }
    else
    {
        tmr2.Stop();
        tmr2.Enabled = false;
    }
}

The logic is quite simple and you can easily understand it taking a look at it. You can change the timer interval and timing to get variations of the animation effect.

Handling Images in Listview

In the attached application, the clipboard ring is implemented in two forms. First one (Form1.cs) is a Listbox implementation and the second one (ClipboardWithImage.cs) is a Listview implementation.

In the Listview implementation, an image thumbnail is shown towards the left of each image entry. The implementation of this is quiet simple. An ImageList control is set to the SmallImageList property of the ListView control. The dimension of images displayed in the ListView is set by having the ImageSize property of ImageList control set. ImageSize property is of type size, so its Height and Width properties can be set individually. Anyway thats not an issue because it can be set in the design view.

Each time a new picture entry is to be made into the Listview, the image is added to the ImageList control and the corresponding index of the image in the ImageList is set to the ListView items imageindex parameter.

To test images, you can use MSPaint. Both Copy and Paste options can be tested using the same.

Figure 1

<img width=290 height=144 src="/ArticleFiles/1245/image001.jpg">

Figure 2

Figure 3


View Entire Article

User Comments

No comments posted yet.






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-26 7:04:22 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search