Getting Cursor Position and Showing it in Taskbar without Occupying any Space in Screen

 Introduction

At a time I am working in an application in that I need to show current cursor position that do not occupying the screen. So I found this concept that contains a simple logic to show the position in taskbar. this concept will help those who are working to get the current cursor position for some purpose. Normally we have some space to show position of the cursor. it may be not optimal in some case. So we can show it in taskbar.

Concept behind the approach:

In this concept we can show the cursor position through Icon of the task. Here we convert the text of cursor position to an Icon. And the Icon further assign to icon of the task.

C# Code behind the approach:

Timer timer = new Timer(); // Create a Timer

timer.Interval = 100; // Have some interval to tick

timer.Start(); // Start the process

timer.Tick += timer_Tick; // Hook the event

void timer_Tick(object sender, EventArgs e)

{

var xValue = "x :"+ Cursor.Position.X .ToString(); // Get the Value of cursor's x value

var yValue = "y :" + Cursor.Position.Y.ToString(); // Get the Value of cursor's y value

var taskIcon = new Bitmap(100, 100); // Get a bitmap

 

var font = new Font("TimesNewRoman", 27, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Pixel); // Get a font

var graphics = Graphics.FromImage(taskIcon); // Get a graphics with the bitmap image

graphics.DrawString(xValue, font, Brushes.Red, new PointF(0, 0)); // Add the x value in the graphics

graphics.DrawString(yValue, font, Brushes.Red, new PointF(0, 50)); // Add the y value in the graphics

graphics.SmoothingMode = SmoothingMode.AntiAlias; // Smoothing the pixel

graphics.TextRenderingHint = TextRenderingHint.AntiAlias; // Smoothing the text rendering because stem width may differ

this.Icon = Icon.FromHandle(taskIcon.GetHicon()); // Convert the bitmap to icon and assign to Icon.

}

Image1.jpg
The above image show the cursor position in task bar.

Conclusion

Hence through this concept we show the cursor's position in taskbar

Next Recommended Reading Adobe finally getting Touchy