ÎÒÃÇÏÈÀ´¿´¿´IssueVisionÖÐÒ»¸öÓû§¿Ø¼þPaneCaptionÔÚ¿ÉÊÓ»¯Éè¼ÆÆ÷ÖеÄÊôÐÔ´°¿Ú.

ÔÙ¿´Ò»ÏÂÔÚÁíÒ»¸öÓû§¿Ø¼þStaffPaneÖÐʹÓÃËüʱµÄÊôÐÔ´°¿Ú:

´ó¼Ò»á·¢ÏÖËü¶à³öÀ´ºÜ¶à¸öÊôÐÔ,ÕâЩÊôÐÔÊÇÔÀ´¼Ì³Ð¿Ø¼þÖÐûÓеÄÊôÐÔ,Èç:InactiveTextColor,InactiveTextColorµÈµÈ.ËüÃÇÊÇÈçºÎʵÏÖµÄÄØ?ÎÒÃǾÍÀ´¿´Ò»ÏÂÕâ¸öÓû§¿Ø¼þµÄ´úÂëPaneCaption.cs°É.
namespace IssueVision
{
// Custom control that draws the caption for each pane. Contains an active
// state and draws the caption different for each state. Caption is drawn
// with a gradient fill and antialias font.
public class PaneCaption : UserControl
{
private class Consts
{
......
¿ÉÒÔ¿´µ½ËüÊÇÓÉ System.Windows.Forms.UserControl ¼Ì³Ð¶øÀ´,ͼһÏÔʾÁËËüµÄĬÈÏÊôÐÔ.ÏÂÃæÎÒÃǽÓ×ÅPaneCaption.cs´úÂë,¿´¿´ÊÇÈçºÎ½«ÊôÐÔ»òʼþÏÔʾÔÚ¿ÉÊÓ»¯Éè¼ÆÆ÷ÖÐ.
[DefaultValueAttribute(typeof(Color), "3, 55, 145")]
[DescriptionAttribute("Low color of the inactive gradient.")]
[CategoryAttribute("Appearance")]
public Color InactiveGradientLowColor
{
get
{
return m_colorInactiveLow;
}
set
{
if (value == Color.Empty)
{
value = Color.FromArgb(3, 55, 145);
}
m_colorInactiveLow = value;
CreateGradientBrushes(); //×Ô¶¨Òå·½·¨,ÓÃÓÚ´´½¨ÏßÐν¥±ä±ÊË¢
Invalidate(); //Control.Invalidate ·½·¨,ʹ¿Ø¼þµÄÌØ¶¨ÇøÓòÎÞЧ²¢Ïò¿Ø¼þ·¢ËÍ»æÖÆÏûÏ¢
}
}
[CategoryAttribute("Appearance")]
[DescriptionAttribute("High color of the inactive gradient.")]
[DefaultValueAttribute(typeof(Color), "90, 135, 215")]
public Color InactiveGradientHighColor
{
get
{
return m_colorInactiveHigh;
}
set
{
if (value == Color.Empty)
{
value = Color.FromArgb(90, 135, 215);
}
m_colorInactiveHigh = value;
CreateGradientBrushes();
Invalidate();
}
}
[DescriptionAttribute("Text displayed in the caption.")]
[DefaultValueAttribute("")]
[CategoryAttribute("Appearance")]
public string Caption
{
get
{
return m_text;
}
set
{
m_text = value;
Invalidate();
}
}
Æä½á¹ûÈçÏÂͼËùʾ:

ÎÒÃÇ¿ÉÒÔ¿´µ½Views,Staff list±³¾°¶¼ÊÇʹÓÃÕâ¸ö×Ô¶¨ÒåµÄPaneCaption²úÉú½¥±äЧ¹û(ÓÉInactiveGradientHighColorºÍInactiveGradientLowColorÊôÐÔʵÏÖ),ÎÄ×ÖViewsºÍStaff listÊÇÓÉÊôÐÔCaptionʵÏÖ.
´úÂë·ÖÎö:
×îÖØÒªµÄÊÇ CategoryAttribute Àà,ËüÖ¸¶¨ÊôÐÔ»òʼþ½«ÏÔʾÔÚ¿ÉÊÓ»¯Éè¼ÆÆ÷ÖеÄÄĸöÀà±ð,¾ßÌåÀà±ðÈçϱí:
Àà±ð
˵Ã÷
Action
¹ØÓÚ¿ÉÓòÙ×÷µÄÊôÐÔ¡£
Appearance
Ó°ÏìʵÌåÍâ¹ÛµÄÊôÐÔ¡£
Behavior
Ó°ÏìʵÌåÐÐΪµÄÊôÐÔ¡£
Data
¹ØÓÚÊý¾ÝµÄÊôÐÔ¡£
Format
Ó°Ïì¸ñʽµÄÊôÐÔ¡£
Layout
¹ØÓÚ²¼¾ÖµÄÊôÐÔ¡£
Default
ûÓÐÀà±ðµÄÊôÐÔÊôÓÚĬÈÏÀà±ð¡£
Óйظü¶àÐÅÏ¢£¬Çë²ÎÔÄ.Net Framework 1.1 SDK
ÎÒÃÇ¿´µ½¾ÙÀýµÄÕâÈý¸öÊôÐÔCategoryAttributeÊôÐÔÖµ¶¼ÎªCategoryAttribute("Appearance"),´Óͼ¶þ¿ÉÒÔ¿´³ö,ÕâЩÊôÐÔ¶¼ÏÔʾÔÚ"Íâ¹Û"ÏÂ.
DefaultValueAttribute ÊôÐÔ¹ËÃû˼Òå,¾ÍÊÇ´Ë×Ô¶¨ÒåÊôÐÔµÄĬÈÏÖµ.
DescriptionAttribute ÊôÐÔÔòΪ´Ë×Ô¶¨ÒåÊôÐÔµÄÃèÊö.
¹Ø¼ü²¿·ÖÒѾÉèÖÃÍê³É,ʣϵľÍÊÇÈçºÎʵÏÖÊôÐÔµÄЧ¹ûÁË,ÎÒÒÔ´úÂë˵Ã÷:
protected override void OnPaint(PaintEventArgs e)
{
DrawCaption(e.Graphics);
base.OnPaint(e);
}
// draw the caption
private void DrawCaption(Graphics g)
{
// background
g.FillRectangle(this.BackBrush, this.DisplayRectangle);
if (m_antiAlias)
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
// need a rectangle when want to use ellipsis
RectangleF bounds = new RectangleF(Consts.PosOffset,
0,
this.DisplayRectangle.Width - Consts.PosOffset,
this.DisplayRectangle.Height);
g.DrawString(m_text, this.Font, this.TextBrush, bounds, m_format);
}
ʹÓÃGraphics.DrawString »æÖƳöCaption(¼´ÎÄ×ÖViewsºÍStaff list),Graphics.FillRectangle »æÖƽ¥±ä±³¾°.×¢Òâ´ËGraphics.FillRectangle ·½·¨µÄµÚÒ»¸ö²ÎÊýΪ±ÊË¢,´Ë±ÊË¢¾ÍΪÉÏÃæ×Ô¶¨ÒåÊôÐÔ´úÂëÖÐCreateGradientBrushes() ·½·¨Ëù´´½¨µÄ±ÊË¢.´úÂëÈçÏÂ:
private void CreateGradientBrushes()
{
// can only create brushes when have a width and height
if (Width > 0 && Height > 0)
{
if (m_brushActive != null)
{
m_brushActive.Dispose();
}
// ÆäÖÐ m_colorActiveHigh Öµ¾ÍΪ×Ô¶¨ÒåÊôÐÔInactiveGradientHighColorµÄÖµ,m_colorActiveLowÔòΪ×Ô¶¨ÒåÊôÐÔInactiveGradientLowColorµÄÖµ.
m_brushActive = new LinearGradientBrush(DisplayRectangle, m_colorActiveHigh, m_colorActiveLow, LinearGradientMode.Vertical);
if (m_brushInactive != null)
{
m_brushInactive.Dispose();
}
m_brushInactive = new LinearGradientBrush(DisplayRectangle, m_colorInactiveHigh, m_colorInactiveLow, LinearGradientMode.Vertical);
}
}
// gradient brush for the background
private LinearGradientBrush BackBrush
{
get
{
if (m_active && m_allowActive)
return m_brushActive;
else
return m_brushInactive;
}
}
²¹³äÒ»µã:¸ù¾ÝGDI+ÒªÇó,ËùÓÐͼÐεĻæÖƶ¼Í¨¹ýOnPaint()·½·¨»æÖÆ,Ö»ÓÃÖØÔØ´Ë·½·¨,¾Í¿ÉÒÔÖØÐ»æÖÆËùÐèµÄͼÐÎÁË.(´Ë·½·¨¾ÍÈçJavaÖеÄPaintComponet()·½·¨Ò»Ñù)
Õâ´Î¾ÍдÕâô¶àÁË,Ï£Íû´ó¼Ò¶à¶à½»Á÷,ÕâÒ²Ö»ÊÇÎÒÒ»¸öÈ˵ÄÈÏʶ,»¹Òª¶àºÍ´ó¼Ò½»Á÷²Å»áÓÐÌá¸ß.
CopyRight © YellowWee 2004. All Right Reserved.

