|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionSome years ago I started to write my first color picker application in VB 6.0. For me it was useful, because it helped me to pick colors for my website projects very fast. Since then I released two other releases as the freeware "ColorManager" (did you hear about it?). The only thing I didn't like: I used API functions directly via DllImport in the last .NET 1.x release version. I used them because I started the first ColorManager in VB 6.0 and I had to. Now I'm developing in C# and I want to use the power of .NET, not Win32 directly. So I decided to write a new ColorManager kernel version with pure C# code - here it is. I've written a user control that works like a magnifying glass: Move the mouse 'round your screen and you'll see the part of the screen that the cursor is pointing to, bigger. You can deactivate the pixel and position view in the display, if you don't need it. Click on the display to create a magnifying glass with alpha effect that will follow the cursor. Move the mouse wheel while the moving glass is active to increase or decrease it's magnifying values. The sample application is a test project for the new ColorManager. The current pixel under the cursor will be selected if the window
looses the focus (just click on the pixel to select the color) or you click while the moving glass is active. The window will try to get the focus
again after selecting a pixel. Finally the RGB values and the preview of the color will stay at the window bottom and the application is ready to
select the next color. Using the codeYou find the main class
You should not resize the control: The size will be calculated using the I used a special interpolation mode to disable the smoothing effect when painting the image scaled: ...
e.Graphics.InterpolationMode = System.Drawing.Drawing2D
.InterpolationMode.NearestNeighbor;
...
Without this setting it's hard to find a single pixel in the magnified screenshot view. Example code to display the control with default settings on your form (place this within the form class and call the method): private void AddMagnifyingGlassControl() { MagnifyingGlass mg = new MagnifyingGlass(); // Set the position and maybe other settings to the // "mg" object here Controls.Add(mg); mg.UpdateTimer.Start(); } Note: To use the control within a designer, add the class to your project and compile once. You will then find the control in the Visual Studio Toolbox. Add it to your form like you do with any other control. By the way, you can decide if you want to use the moving glass feature. Simply use the constructor with the boolean value: // Disable the moving glass { MagnifyingGlass mg = new MagnifyingGlass(false); } // Enable the moving glass { MagnifyingGlass mg = new MagnifyingGlass(true); } // or: { MagnifyingGlass mg = new MagnifyingGlass(); } If you disable the moving glass trough the constructor, you won't be able to enable it later (you need to create a new You may also use only the moving glass without placing the fixed Control to your form. Example: private void ShowMovingGlass() { MovingMagnifyingGlass mg = new MovingMagnifyingGlass(); mg.Show(); ... } Any suggestions? You're welcome! Known bugs
Points of InterestWriting the calculation of the screenshot sizes and display positions was... yeah... (I wrote the complete code (the first version) in - lets
say - round about 30 minutes) I hope everything is working right :) Someone told me that his graphic card CPU cooler is running faster (and louder) after he started an application with the magnifying glass
control on it's form, even if the If you'd like to get the current freeware release of the ColorManager (sorry, no source), you can download it from here: http://wan24.de/download/ColorManager.zip (527 KB) History2007-01-24:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||