How to create Action Lable in .NET compact framework.

No.of Views1064
Bookmarked0 times
Downloads 
Votes0
By  RRaveen   On  15 Feb 2010 22:02:46
Tag : .NET CF , How to
How to create Action Lable in .NET compact framework.
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

Hi Guys,

Most of the time, we need to create custom controls in .net compact framework. Because many time standard controls are not fulfill our requirements. I'm going to create an action label in .net compact framework. It's pretty simple. Because of we do not need play with P/Invoke, but we want to play with GDI+, since I want to create a graphical objects,

Here the complete code for you.


{codecitation class="brush: c#; gutter: true;" width="500px"}using System;


using System.Windows.Forms;
using System.Drawing;

namespace RaveSoftBlog
{
///
/// Arrow label button control.
///
public class ActionLabel : Control
{
class Const
{
public static Color DisableColor = Color.FromArgb(150,150,80);
public static Color PushedColor = Color.FromArgb(160,100,0);
public static Color ForeColor = Color.FromArgb(90,90,45);
public static Color BulletColor = Color.FromArgb(180,180,110);
public const string FontName = "Arial";
public const int FontSize = 10;
public const int BulletSize = 8;
}

// internal fields
bool m_pushed;
Rectangle m_rcHitArea;
Point[] m_bulletPts;

// gdi objects
Bitmap m_bmp;
Font m_font;
Pen m_penPushed, m_penFore, m_penDisabled;
Brush m_brushPushed, m_brushFore, m_brushDisabled;

// ctor
public ActionLabelControl()
{
// colors
this.ForeColor = Const.ForeColor;

// gdi objects
CreateGdiObjects();
}

protected override void OnPaint(PaintEventArgs e)
{
// draw to memory bitmap
CreateMemoryBitmap(e.Graphics);
Graphics g = Graphics.FromImage(m_bmp);
DrawLabel(g);

// blit memory bitmap to screen
e.Graphics.DrawImage(m_bmp, 0, 0);
}

protected override void OnPaintBackground(PaintEventArgs e)
{
// don't pass to base since we paint everything, avoid flashing
}

protected override void OnEnabledChanged(EventArgs e)
{
// redraw when enabled state changes
Invalidate();
}

// draw label and arrow
private void DrawLabel(Graphics g)
{
// background
g.Clear(Parent.BackColor);

// determine what pen and brush to use
Pen pen = m_pushed ? m_penPushed :
(this.Enabled ? m_penFore : m_penDisabled);

Brush brush = m_pushed ? m_brushPushed :
(this.Enabled ? m_brushFore : m_brushDisabled);

// draw solid arrow if enabled
if (this.Enabled)
g.FillPolygon(brush, m_bulletPts);

 
Sign Up to vote for this article
 
About Author
 
RRaveen
Occupation-Software Engineer
Company-TGS
Member Type-Gold
Location-Singapore
Joined date-03 Jun 2009
Home Page-codegain.com
Blog Page-www.codegain.com
- B.Sc. degree in Computer Science. - 4+ years experience in Visual C#.net and VB.net - Obsessed in OOP style design and programming. - Designing and developing Network security tools. - Designing and developing a client/server application for sharing files among users in a way other than FTP protocol. - Designing and implementing GSM gateway applications and bulk messaging. - Windows Mobile and Symbian Programming - Having knowledge with ERP solutions
 
 
Other popularSectionarticles
Comments
There is no comments for this articles.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top