YOU CAN CODE!

 

With The Case Of UCanCode.net  Release The Power OF  Visual C++ !   HomeProducts | PurchaseSupport | Downloads  
Download Evaluation
Pricing & Purchase?
E-XD++Visual C++/ MFC Products
Overview
Features Tour 
Electronic Form Solution
Visualization & HMI Solution
Power system HMI Solution
CAD Drawing and Printing Solution

Bar code labeling Solution
Workflow Solution

Coal industry HMI Solution
Instrumentation Gauge Solution

Report Printing Solution
Graphical modeling Solution
GIS mapping solution

Visio graphics solution
Industrial control SCADA &HMI Solution
BPM business process Solution

Industrial monitoring Solution
Flowchart and diagramming Solution
Organization Diagram Solution

Graphic editor Source Code
UML drawing editor Source Code
Map Diagramming Solution

Architectural Graphic Drawing Solution
Request Evaluation
Purchase
ActiveX COM Products
Overview
Download
Purchase
Technical Support
  General Q & A
Discussion Board
Contact Us

Links

Get Ready to Unleash the Power of UCanCode .NET

 


UCanCode Software focuses on general application software development. We provide complete solution for developers. No matter you want to develop a simple database workflow application, or an large flow/diagram based system, our product will provide a complete solution for you. Our product had been used by hundreds of top companies around the world!

"100% source code provided! Free you from not daring to use components because of unable to master the key technology of components!"


Introduction to GDI+ in .NET

By c#corner

In this article, we’ll see basics of GDI+ and how GDI+ is much better interface than its predecessor GDI.

 

Introduction

Microsoft .NET is Microsoft's recent released development framework. Microsoft .NET not only introduces powerful languages such as C# and VB.NET, it also brings relief to other programmers including graphics, multimedia, web development and speech.

In this article, we'll see basics of GDI+ and how GDI+ is much better interface than its predecessor GDI.

GDI - Graphic User Interface

GDI stands for Graphic Device Interface. In Microsoft Windows, GDI is a way to work with paining graphic objects such as painting on windows, forms or other media.

Why do you need GDI ? To write GUI application, you need to write some kind of visual interface in the form of windows and controls. There is only one way to see the visual interface - through hardware, such as printer and monitor.

GDI is a set of C++ classes, which provides functionality to render data to a program to hardware devices with the help of device drivers. GDI sits between the program and the hardware and transfer data from one to other

Working with GDI objects in earlier versions of Microsoft products was a pain. I've been programming with Microsoft products (C++ and VB) for over 5 years in C++ and I know the pain of using GDI. If you've ever programmed in C++ or MFC, I bet you must be frustrated using GDI objects too. Have you ever try changing color or font of windows and controls in C++/MFC?

For example, if you want to change the font of a control in C++ (MFC), you need to create a font with its type and then call SetFont. See fig. 1.1.

CStatic *lpLabel=(CStatic *)GetDlgItem(IDC_STATIC1);
CFont LabelFont;
LabelFont.CreateFont(20,20,0,0,FW_BOLD,FALSE,FALSE,0,DEFAULT_CHARSET,             
   OUT_CHARACTER_PRECIS,CLIP_CHARACTER_PRECIS,DEFAULT_QUALITY, 
   DEFAULT_PITCH,NULL);
lpLabel->;SetFont(&LabelFont,TRUE);

Fig 1.1.

This is just a simple example. What if you want to change the background color of a toolbar? That's more pain. You need to override OnEraseBackground and get pDC object and so on.

GDI+: A Higher Level API

In Visual Studio .NET, Microsoft has taken care of most of the GDI problems and have made it easy to use. The GDI version of .NET is called GDI+.

GDI+ is next evolution of GDI. It's much better improved and easy to use version of GDI. The best thing about GDI is you don't need to know any details of drivers to render data on printers and monitors. GDI+ takes care of it for you. In other words, GDI was a low-middle level of programming API, where you need to know about devices too, while GDI+ is a higher level of programming model, which provides functions to do work for you.

For example, if you want to set background or foreground color of a control, just set ForeGroundColor property of the control. We'll see this all in more depth later in this tutorial.

What's new in GDI+?

Beside the fact that GDI+ API is easier and flexible than GDI, there are many more new features added to the API. Some of the new features GDI+ offers are -

  • Improved Colors. Now GDI+ comes with more colors and these are compatible with other colors such as Windows etc.  
  •    Antialiasing support  
  •    Gradient brushes  
  •    Splines  
  •    Transformation and Matrices  
  •    Scalable reasons  
  •    Alpha Blending

It's hard to cover every thing in this article, but may be in next article of this series, I would cover some of these details.

What this article covers?

In this article, first we'll talk about GDI+ classes (also called types in .NET) and interfaces followed by GDI+ objects and then we'll see some sample examples.

GDI+ Class and Interfaces in .NET

In Microsoft .NET library, all classes (types) are grouped in namespaces. A namespace is nothing but a category of similar kind of classes. For example, Forms related classes are stored in Windows.Forms namespace, database related classed are grouped in Data and its sub namespaces such as System.Data.SqlClient, System.Data.OleDb, and System.Data.Common. Similarly, GDI+ classes are grouped under six namespaces, which reside in System.Drawing.dll assembly.

GDI+ Namespaces

GDI+ is defined in the Drawing namespace and its five sub namespaces. All drawing code resides in System.Drawing.DLL assembly. These namespaces System.Drawing, System.Drawing.Design, System.Drawing.Printing, System.Drawing.Imaging, System.Drawing.Drawing2D and System.Drawing.Text namespaces. 

Now let's take a quick overview of these namespaces.

Introduction to GDI+ in .NET

GDI+ Font, Brush and Bitmap

GDI+ GraphicsPath and LinearGradientBrush

GDI+ Printing.

GDI+ and DrawArc and DrawPath

GDI+ Color and ARGB with Example

 

 

 

Copyright ?1998-2009 UCanCode.Net Software , all rights reserved.
Other product and company names herein may be the trademarks of their respective owners.

Please direct your questions or comments to webmaster@ucancode.net