Create Image button with. NET Compact framework

Source: Internet
Author: User

 I. Overview

Due to device restrictions, the. NET Compact framework does not support all the GDI + features. You may also know that GDI + is divided into the following three categories:

1. 2-D vector graphics (2-D vector plot)

2. imageing (imaging)

3. typography)

2-D vectore graphics in. in the NET Compact framework, the core of the graphics object is only used to draw an ellipse, line, image, polygon, square, String, fill an ellipse, fill a polygon, fill a square, and fill a area.

In the imaging category, the bitmap class supports Image Processing (in small blocks) or saving image files. The types of typography are font changes, sizes, and styles .. NET Compact framework provides support for this program. But don't be afraid! We can still use a subset of the GDI function to create a powerful drawing application. Just pay attention to it. system. windows. forms. dataGrid Control. this control is on which we fully utilize the self-drawn control. the real high-performance graphics created on the netcompact Framework Platform are used to represent multiple rows and multiple columns.

 3. Best practices for creating images

1. When we create a self-drawn control, it is derived from the system. Windows. Forms. Control and the onpaint and onpaintbackground events are reloaded.


2. Create pen, bitmap, and brush objects and use their onpaint events. The operating system takes some time to handle the onpaint event. The image performance is also affected when these objects are instantiated and cleared.

3. Use dual cache to reduce the flashes of images when the screen is refreshed. Generally, the Double Cache logic is as follows:


In the above Code, an empty bitmap is created using the graphics object, and the size of the image in the control can be obtained through the static method formimage of the graphics class, we will draw these graphic objects in the memory. After all the graphical objects are finished, we can accurately draw these image objects on the control. NET Compact framework imageattributes parameters to achieve bitmap transparency.


Remember the low and high color key values. Set them to the same value in the setcolorkey method. The main reason is that. NET Compact framework does not support setting transparent colors in any way.

Iv. Application Rules

In actual operations, we will create a self-drawn image button control. You need to display an image on the button. When you press the button, you can see the effect.

We started to create a Windows application for the smartdevice project in Visual Studio. NET. In this project, we added a new imagebutton class.


In the above Code, we use the imagebutton class in the control, and reload the onpaint and onpaintbackground events. As mentioned above, imagebutton will use an image for display, so we add image attributes:


Of course, there is also a button to reload the onpaint event to draw


Based on the summary in the previous chapter, we successfully wrote the code by drawing the. NET Compact framework method. We first set up the cache of the drawing object, and try to use double cache to Reduce image blinking. We use the following function to help identify the background color and make the image transparent:


The above function adds the color in the upper left corner of the bitmap. When drawing a button, we use the bpushed flag to determine whether the button is pressed. We can easily reload onmousedown and onmouseup events:



V. Usage

You can easily create an imagebutton control. Add the following code to the form structure:



Vi. Conclusion

. NET Compact framework does not provide many available graphics and drawing functions like. NET Framework. This is because of platform resource restrictions. However, we can use some self-painting techniques to create rich and responsive images in user programs.

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: 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.