人人做人人澡人人爽欧美,国产主播一区二区,久久久精品五月天,羞羞视频在线观看免费

當前位置:蘿卜系統下載站 > 技術開發教程 > 詳細頁面

自定義按鈕(轉)

自定義按鈕(轉)

更新時間:2022-10-08 文章作者:未知 信息來源:網絡 閱讀次數:

//這個用戶自定義控件繼承自Button類
//實現了在按紐左側顯示圖片的任務
//和點擊后顯示不同樣式的功能
//下面就是人家的了
//本人加如了一些注釋

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

namespace NETToggle
{
/// <summary>
/// Summary description for customFlatButton.
/// </summary>
public class customFlatButton : System.Windows.Forms.Button
{
//used to set the type of image that is displayed with the button
public enum TOGGLE_TYPE{ none, XML_TOGGLE, HTML_TOGGLE };//顯示類型

private bool bSelected = false;//是否被選擇
private System.Windows.Forms.ImageList flatBtnImageList;//從工具欄拖進來的了
//他的一些東西有vs.net工具自動生成
private System.ComponentModel.IContainer components;
private int toggleType = 0;

public int ToggleType
{
get{ return toggleType; }
set{ toggleType = value; }
}

public bool bChangeSelection
{
get{ return bSelected; }
set{ bSelected = value; Invalidate(); }
}

public customFlatButton()
{
InitializeComponent();
}

private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(customFlatButton));
this.flatBtnImageList = new System.Windows.Forms.ImageList(this.components);
//
// flatBtnImageList
//
this.flatBtnImageList.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
this.flatBtnImageList.ImageSize = new System.Drawing.Size(9, 9);
this.flatBtnImageList.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("flatBtnImageList.ImageStream")));
this.flatBtnImageList.TransparentColor = System.Drawing.Color.Transparent;
//
// customFlatButton
//
this.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.Size = new System.Drawing.Size(57, 19);

}

protected override void OnMouseEnter( System.EventArgs e )
{
return;
}

protected override void OnClick( System.EventArgs e)
{
bSelected = true;//觸發bChangeSelection的寫屬性--調用this.Invalidate();--引起對OnPaint()的調用
base.OnClick(e);
}

protected override void OnMouseDown( System.Windows.Forms.MouseEventArgs e)
{
OnClick(e);
}

protected override void OnPaint( System.Windows.Forms.PaintEventArgs e )
{
Rectangle rect = e.ClipRectangle;
Graphics g = e.Graphics;

if( bSelected )
{
g.FillRectangle( new SolidBrush(Color.White), rect );
g.DrawString( this.Text, this.Font, new SolidBrush(this.ForeColor), 20, (float)2.5 );

g.DrawRectangle( new Pen(System.Drawing.SystemColors.Highlight, 2), rect );
}
else
{
g.FillRectangle( new SolidBrush(System.Drawing.SystemColors.Control), rect );
g.DrawString( this.Text, this.Font, new SolidBrush(this.ForeColor),20, (float)2.5 );
}

//now draw the correct image if one is specified
if( toggleType == (int)TOGGLE_TYPE.XML_TOGGLE )
g.DrawImage( this.flatBtnImageList.Images[0], 8, 5 );
else if( toggleType == (int)TOGGLE_TYPE.HTML_TOGGLE )
g.DrawImage( this.flatBtnImageList.Images[1], 7, 5 );
}
}
}

溫馨提示:喜歡本站的話,請收藏一下本站!

本類教程下載

系統下載排行

網站地圖xml | 網站地圖html
主站蜘蛛池模板: 工布江达县| 双流县| 肇州县| 麻阳| 苗栗市| 永福县| 德阳市| 保靖县| 耒阳市| 定安县| 内黄县| 杭州市| 清河县| 宣威市| 沙洋县| 九龙城区| 西和县| 江陵县| 安徽省| 陇川县| 华宁县| 禹州市| 巫溪县| 大名县| 商水县| 曲水县| 平乡县| 搜索| 皋兰县| 凉城县| 张家港市| 青州市| 丹寨县| 石棉县| 轮台县| 罗平县| 洛阳市| 宜兴市| 大田县| 封开县| 湘乡市|