Making a Custom Snipping Tool Appear on the Taskbar in Windows 11 Home
Have you ever wanted to take a quick screenshot on your Windows 11 Home computer, but found the built-in tools lacking in features or customization options? Look no further, as this article will guide you through the process of creating your own custom snipping tool and pinning it to your taskbar for easy access.
Prerequisites
Before we begin, there are a few things you will need:
- A basic understanding of programming concepts, such as variables, functions, and loops.
- A text editor, such as Visual Studio Code or Notepad++, to write and edit your code.
- The .NET 5.0 SDK or later, which can be downloaded from the Microsoft website.
Creating the Snipping Tool
To create our custom snipping tool, we will be using C# and the System.Drawing namespace to capture the screenshot, and the System.Windows.Forms namespace to create the user interface.
using System;
using System.Drawing;
using System.Windows.Forms;
namespace SnippingTool
{
class Program
{
static void Main(string[] args)
{
// Create the main form
Form mainForm = new Form();
mainForm.Text = "Snipping Tool";
mainForm.FormBorderStyle = FormBorderStyle.None;
mainForm.Bounds = Screen.PrimaryScreen.Bounds;
mainForm.StartPosition = FormStartPosition.Manual;
// Create the snipping rectangle
Rectangle snippingRectangle = new Rectangle(0, 0, 0, 0);
// Create the snipping button
Button snippingButton = new Button();
snippingButton.Text = "Snip";
snippingButton.Location = new Point(10, 10);
snippingButton.Click += (sender, e) =>
{
// Set the snipping rectangle to the size of the form
snippingRectangle = new Rectangle(mainForm.Location, mainForm.Size);
// Create a new bitmap to hold the screenshot
Bitmap bitmap = new Bitmap(snippingRectangle.Width, snippingRectangle.Height);
// Create a graphics object to draw the screenshot
Graphics graphics = Graphics.FromImage(bitmap);
// Draw the screenshot to the bitmap
graphics.CopyFromScreen(snippingRectangle.Location, Point.Empty, snippingRectangle.Size);
// Save the screenshot to a file
bitmap.Save("screenshot.png", System.Drawing.Imaging.ImageFormat.Png);
// Close the form
mainForm.Close();
};
// Add the snipping button to the form
mainForm.Controls.Add(snippingButton);
// Show the form
Application.Run(mainForm);
}
}
}Pinning the Snipping Tool to the Taskbar
Now that we have our custom snipping tool, we need to pin it to the taskbar for easy access. To do this, we will create a shortcut to the snipping tool executable and place it in the %APPDATA%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar directory.
using System;
using System.Diagnostics;
using System.IO;
namespace SnippingTool
{
class Program
{
static void Main(string[] args)
{
// Get the path to the snipping tool executable
string exePath = AppDomain.CurrentDomain.BaseDirectory + "SnippingTool.exe";
// Create a shortcut to the snipping tool executable
string shortcutPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Microsoft", "Internet Explorer", "Quick Launch", "User Pinned", "TaskBar", "Snipping Tool.lnk");
using (Stream stream = new FileStream(shortcutPath, FileMode.Create))
{
IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell();
IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(stream);
shortcut.TargetPath = exePath;
shortcut.Save();
}
// Open the taskbar folder
Process.Start(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Microsoft", "Internet Explorer", "Quick Launch", "User Pinned", "TaskBar"));
}
}
}Customizing the Snipping Tool Icon
By default, the snipping tool will use the default application icon. To change this, we can use a resource file (.resx) to store the icon and reference it in our code.
using System;
using System.Drawing;
using System.Windows.Forms;
namespace SnippingTool
{
class Program
{
static void Main(string[] args)
{
// Load the icon from the resource file
Icon icon = new Icon("SnippingTool.ico");
// Create the main form
Form mainForm = new Form();
mainForm.Text = "Snipping Tool";
mainForm.FormBorderStyle = FormBorderStyle.None;
mainForm.Bounds = Screen.PrimaryScreen.Bounds;
mainForm.StartPosition = FormStartPosition.Manual;
mainForm.Icon = icon;
// ...
}
}
}In this article, we have covered the process of creating a custom snipping tool and pinning it to the taskbar in Windows 11 Home. This includes:
- Creating the snipping tool using C# and the
System.DrawingandSystem.Windows.Formsnamespaces. - Pinning the snipping tool to the taskbar by creating a shortcut to the executable in the
%APPDATA%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBardirectory. - Customizing the snipping tool icon using a resource file (.resx).
References
- System.Drawing Namespace
- System.Windows.Forms Namespace
- Environment.SpecialFolder Enumeration
- Process.Start Method
- Bitmap Class
- Graphics Class
- FormBorderStyle Enumeration
- FormStartPosition Enumeration
- Rectangle Structure
- Point Structure
- ImageFormat Enumeration
- Button Class
- Controls Property
- Click Event
- Application.Run Method
- Stream Class
- FileMode Enumeration
- FileAttributes Enumeration
- File.Create Method
- File.Exists Method
- File.Delete Method
- Path Class
- Icon Property
- Icon Class
- ResourceManager Class
- ResourceManager.GetObject Method
- Show Method
- Hide Method
- Close Method
- Dispose Method
- Validating Event
- Validated Event
- ValidateChildren Method
- CancelButton Property
- AcceptButton Property
- ContextMenu Property
- ContextMenuStrip Property
- CreateDoubleBuffer Property
- Cursor Property
- DoubleBuffered Property
- Enabled Property
- Font Property
- ForeColor Property
- Height Property
- Left Property
- Location Property
- MaximumSize Property
- Maximum Property
- MinimumSize Property
- Minimum Property
- Name Property
- Parent Property
- Right Property
- Size Property
- StartPosition Property
- TabIndex Property
- TabStop Property
- Tag Property
- Text Property
- Top Property
- UseWaitCursor Property
- Visible Property
- Width Property