A tiny magnifier

Source: Internet
Author: User

ArticleSource: http://www.codeproject.com/useritems/SimpleMagnifier.asp

Article Title: simple magniier

Author:Otigli

======================================
=I have translated my articles for the first time. I hope you can give me more advice. Thank you ~!=
======================================

Introduction:
Interesting desktop gadgets: simple amplifiers.

Background:
I believe that most people have seen at least one Magnifier tool. I have used some tools, including one embedded in the operating system. But I don't like any of them. So I made one for myself.

CodeIntroduction:
As mentioned aboveProgramIs a simple application, but it can still show some interesting things. First, it shows how to capture screen images, double buffering, a rhythmic mobile windows form, and serializing and deserialization through xmlserializer). Secondly, this applet is used for entertainment, so it does not follow the traditional windows programming steps. In fact, I used a small borderless windows form as the main form. There are only three buttons on it to implement all the required functions, the first is to enable the magnifier, the second is the configuration button, and the third is to exit the application.

The following is a program:

The configuration form is as follows:

The main code is as follows:

//Make the window (the form) elliptical
Graphicspath GP= NewGraphicspath ();
GP. addellipse (clientrectangle );
Region= NewRegion (GP );


// --- Double buffering ---

Protected   Override   Void Onpaintbackground (painteventargs E)
{
If (Mconfiguration. doublebuffered)
{
// Do not paint background (required for double buffering )!
}
Else
{
Base . Onpaintbackground (E );
}
}

Protected   Override   Void Onpaint (painteventargs E)
{
If (Mbufferimage =   Null )
{
Mbufferimage =   New Bitmap (width, height );
}
Graphics buffergrf = Graphics. fromimage (mbufferimage );

Graphics g;

If(Mconfiguration. doublebuffered)
{
G=Buffergrf;
}
Else
{
G=E. graphics;
}

If (Mscreenimage ! =   Null )
{
Rectangle dest =   New Rectangle ( 0 , 0 , Width, height );
Int W = ( Int ) (Width / Mconfiguration. zoomfactor );
Int H = ( Int ) (Height / Mconfiguration. zoomfactor );
Int X = Left - W /   2   + Width /   2 ;
Int Y = Top - H /   2   + Height /   2 ;

G. drawimage (
mscreenimage,
DEST,
X, Y,
W, H,
graphicsunit. pixel);
}

If(Mimagemagnifier! = Null)
{
G. drawimage (mimagemagnifier,0,0, Width, height );
}

If (Mconfiguration. doublebuffered)
{
E. Graphics. drawimage (mbufferimage, 0 , 0 , Width, height );
}
}
// --- XML serialization ---
Public   Class Xmlutility
{
Public   Static   Void Serialize (object data, String Filename)
{
Type type = Data. GetType ();
Xmlserializer XS =   New Xmlserializer (type );
Xmltextwriter xmlwriter =   New Xmltextwriter (filename, system. Text. encoding. utf8 );
Xmlwriter. Formatting = Formatting. indented;
Xs. serialize (xmlwriter, data );
Xmlwriter. Close ();
}

Public static Object deserialize (type, string filename)
{< br> xmlserializer Xs = New xmlserializer (type);

Xmltextreader xmlreader= NewXmltextreader (filename );
Object Data=Xs. deserialize (xmlreader );

Xmlreader. Close ();

ReturnData;
}
}

 

Summary:
It is really interesting to write this program. I share it with my friends and they like it very much. I hope you like it as well.

Happy every day ~!

Ogun tigli

Source code: Magnifier20070401.zip-439.9 KB

======================================
After the translation is complete, I hope to give me more instructions. Thank you ~!
======================================

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.