精通
英语
和
开源
,
擅长
开发
与
培训
,
胸怀四海
第一信赖
锐英源精品开源心得,转载请注明:“锐英源www.wisestudy.cn,孙老师作品,电话13803810136。需要全文内容也请联系孙老师。
This is a fun little gadget for your desktop: a simple magnifier. 这是一个有趣的桌面小玩意:一个简单的放大镜。
I believe, many of you have already seen at least one magnifier application. I tried a few including the one which is built-in at the OS, however, I didn't like them one way or another. So, I decided to implement a simple one for my own usage.
我相信,你们中的许多人已经看过至少一个放大镜应用程序。我试过一些包括内置在操作系统的,然而,我不喜欢他们这样或那样的方式。所以,我决定实现一个简单属于我自己的用法。
Well, I've been using it quite sometime by now and it really works great. I thought you may find it interesting as well.
嗯,我到目前为止一直在使用它,它真的是一个伟大的工程。我想你会发现它有趣。
As I mentioned earlier, the program in fact is a simple application. However, it still demonstrates a few interesting points: First of all, it shows how to capture a screen image, double buffering, moving a Windows form programmatically, and serializing/deserializing configuration information through XmlSerializer. Second of all, the little application is designed to be a fun application in my mind, so it doesn't follow conventional Windows programming steps. Instead, I've used a very small borderless window as the main form. It has only 3 buttons (actually, hot spots) to do all functionality it provides. The first one instantiates a magnifier form, the second one to do the configuration, and finally, the third one is to exit from application.
正如我之前提到的,这个程序实际上是一个简单的应用程序。然而,它还演示了一些有趣的观点:首先,它展示了如何捕捉屏幕图像,双缓冲技术,编程移动一个Windows窗体,并通过XmlSerializer配置信息进行序列化/反序列化。其次,这个小应用程序在我的印象中被设计成一个有趣的应用程序,所以它不遵循传统的Windows编程步骤。相反,我使用了一个非常小的无边界的窗口为主要形式。它只有三个按钮(实际上,热点)提供了所有功能。第一个实例化一个放大镜形式,第二个配置,最后,第三个是退出应用程序。
Here is a screenshot of the application: 这是一个应用程序的屏幕截图:
The configuration section provides quite a few things to play with: 配置部分提供了很多好玩的东西:
Some of the code snippets are also shown below: 一些代码片段如下所示:
// Make the window (the form) elliptical GraphicsPath gp = new GraphicsPath(); gp.AddEllipse(ClientRectangle); Region = new Region(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 type, string fileName) { XmlSerializer xs = new XmlSerializer(type); XmlTextReader xmlReader = new XmlTextReader(fileName); Object data = xs.Deserialize(xmlReader); xmlReader.Close(); return data; } }
Please take a look at the provided code to see the details in the implementation. 请看看所提供的代码实现的细节。
It was really fun to code this application. I shared it with my friends and many really liked it. Hope you guys will like it as much as I did. Have a nice day!
这个应用程序代码真的很有趣。我和我的朋友分享它和许多朋友真的很喜欢它。希望你们能像我一样喜欢它。祝你有美好的一天!