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);
|