六月婷婷综合激情-六月婷婷综合-六月婷婷在线观看-六月婷婷在线-亚洲黄色在线网站-亚洲黄色在线观看网站

明輝手游網(wǎng)中心:是一個(gè)免費(fèi)提供流行視頻軟件教程、在線學(xué)習(xí)分享的學(xué)習(xí)平臺(tái)!

[原創(chuàng)]IssueVision 學(xué)習(xí)筆記(二)-----為控件添加自定義屬性與事件

[摘要]我們先來(lái)看看IssueVision中一個(gè)用戶(hù)控件PaneCaption在可視化設(shè)計(jì)器中的屬性窗口. 再看一下在另一個(gè)用戶(hù)控件StaffPane中使用它時(shí)的屬性窗口: 大家會(huì)發(fā)現(xiàn)它多出來(lái)很多個(gè)屬性,這些屬性是原來(lái)繼承控件中沒(méi)有的屬性,如:InactiveTextColor,Inactiv...
我們先來(lái)看看IssueVision中一個(gè)用戶(hù)控件PaneCaption在可視化設(shè)計(jì)器中的屬性窗口.






再看一下在另一個(gè)用戶(hù)控件StaffPane中使用它時(shí)的屬性窗口:






大家會(huì)發(fā)現(xiàn)它多出來(lái)很多個(gè)屬性,這些屬性是原來(lái)繼承控件中沒(méi)有的屬性,如:InactiveTextColor,InactiveTextColor等等.它們是如何實(shí)現(xiàn)的呢?我們就來(lái)看一下這個(gè)用戶(hù)控件的代碼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 繼承而來(lái),圖一顯示了它的默認(rèn)屬性.下面我們接著PaneCaption.cs代碼,看看是如何將屬性或事件顯示在可視化設(shè)計(jì)器中.

[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(); //自定義方法,用于創(chuàng)建線形漸變筆刷
Invalidate(); //Control.Invalidate 方法,使控件的特定區(qū)域無(wú)效并向控件發(fā)送繪制消息
}
}

[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();
}
}

其結(jié)果如下圖所示:








我們可以看到Views,Staff list背景都是使用這個(gè)自定義的PaneCaption產(chǎn)生漸變效果(由InactiveGradientHighColor和InactiveGradientLowColor屬性實(shí)現(xiàn)),文字Views和Staff list是由屬性Caption實(shí)現(xiàn).




--------------------------------------------------------------------------------

代碼分析:

最重要的是 CategoryAttribute 類(lèi),它指定屬性或事件將顯示在可視化設(shè)計(jì)器中的哪個(gè)類(lèi)別,具體類(lèi)別如下表:

類(lèi)別
說(shuō)明

Action 關(guān)于可用操作的屬性。
Appearance 影響實(shí)體外觀的屬性。
Behavior 影響實(shí)體行為的屬性。
Data 關(guān)于數(shù)據(jù)的屬性。
Format 影響格式的屬性。
Layout 關(guān)于布局的屬性。
Default 沒(méi)有類(lèi)別的屬性屬于默認(rèn)類(lèi)別。













有關(guān)更多信息,請(qǐng)參閱.Net Framework 1.1 SDK
我們看到舉例的這三個(gè)屬性CategoryAttribute屬性值都為CategoryAttribute("Appearance"),從圖二可以看出,這些屬性都顯示在"外觀"下.

DefaultValueAttribute 屬性顧名思義,就是此自定義屬性的默認(rèn)值.
DescriptionAttribute 屬性則為此自定義屬性的描述.


關(guān)鍵部分已經(jīng)設(shè)置完成,剩下的就是如何實(shí)現(xiàn)屬性的效果了,我以代碼說(shuō)明:

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 方法的第一個(gè)參數(shù)為筆刷,此筆刷就為上面自定義屬性代碼中CreateGradientBrushes() 方法所創(chuàng)建的筆刷.代碼如下:

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

補(bǔ)充一點(diǎn):根據(jù)GDI+要求,所有圖形的繪制都通過(guò)OnPaint()方法繪制,只用重載此方法,就可以重新繪制所需的圖形了.(此方法就如Java中的PaintComponet()方法一樣)

這次就寫(xiě)這么多了,希望大家多多交流,這也只是我一個(gè)人的認(rèn)識(shí),還要多和大家交流才會(huì)有提高.





主站蜘蛛池模板: 色婷婷啪啪| 日本精品国产 | 性欧美大战久久久久久久久 | 日本高清不卡免费 | 亚洲 欧美 国产 中文 | 日本高清在线不卡 | 欧美亚洲性色影视在线 | 日本福利片国产午夜久久 | 日韩在线综合 | 色台湾色综合网站 | 天天干天天天天 | 夜夜视频 | 青青热久久综合网伊人 | 最新在线精品国自产拍网站 | 四虎影视免费观看免费观看 | 亚洲人成www在线播放 | 亚洲 欧美 日韩 另类 | 青娱乐啪啪 | 亚洲精品乱码久久久久久 | 三级黄色片免费观看 | 亚洲资源在线播放 | 日韩一级黄色大片 | 午夜成人免费影院 | 星辰影院免费 | 日日噜噜噜夜夜爽爽狠狠69 | 热久久这里是精品6免费观看 | 五月婷婷之婷婷 | 三级精品视频在线播放 | 亚洲成年www | 欧美一区二区三区播放 | 伊人久久综合影院首页 | 一区二区三区在线 | 网站 | 色天天躁夜夜躁天干天干 | 亚洲va中文字幕 | 色一情一乱一伦 | 日韩a在线 | 欧美最新在线 | 色噜噜综合 | 中文字幕一区二区三区免费视频 | 日日视频 | 亚洲免费黄色网址 |