Lable Control for customizing Windows Mobile backgrounds

Source: Internet
Author: User

Development Environment of this Article

Operating System: xp

Program Development Environment vss2008 + windowMobile6.1Professional

 

Overview:

During WindowMobile development, especially for UI design with high requirements, we need to implement tags with custom background images.

For such a requirement, we usually think of inheriting the lable control and the OnPaint method of the Override control. However, the odd phenomenon is that the inherited control does not use the OnPaint method in any way. Many people on the network also encounter this problem. The following describes how to implement a custom control.

 

Customize the lable of the background imageWidget.

The solution is as follows:

Define a Control inheritance and Control,

Override OnPaint method.

Do the following in the OnPaint method:

L first clear the current background

L draw background

L display the current label text. Note that Color. Transparent is used for the text background when drawing the text,

 

Example:

The following is an application in the actual project.

Displays a control of the current game player's blood, the background is the current blood volume picture, the displayed text is the current blood value

The specific effect is as follows:

 

The Code is as follows:

 

 

Code

/// <Summary>
/// Inherit and reset the background
/// Set according to the ratio of the current blood
/// </Summary>
/// <Param name = "e"> </param>
Protected override void OnPaintBackground (PaintEventArgs e)
{
Base. OnPaintBackground (e );

// Step One clears the background
E. Graphics. Clear (Color. White );

// Step Two re-paint the current background
Int length = (BloodNum/MaxBloodNum) * this. Width;

Using (SolidBrush brush = new SolidBrush (this. BackColor ))
{

E. Graphics. FillRectangle (brush, new Rectangle (0, 0, length, this. Height ));

}

// Step Three: Fill the unfilled part.
Using (SolidBrush brush = new SolidBrush (Color. DarkOliveGreen ))
{

E. Graphics. FillRectangle (brush, new Rectangle (length, 0, (this. Width-length), this. Height ));
}

// Step Four shows the current blood value
Using (Pen pen = new Pen (this. ForeColor ))
{

Using (SolidBrush brush = new SolidBrush (Color. Transparent ))
{
// Set the text area

E. Graphics. DrawString (this. BloodNum. ToString (), this. Font, brush, (this. Width/2)-5), 0 );
}
}

}

 

 

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.