麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁(yè) > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

智能可變大小的控件:一個(gè)控件制作的全過(guò)程(C#)

2019-11-17 04:10:43
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

第一步:
確定這個(gè)控件需要用來(lái)做什么的,我們想對(duì)這個(gè)控件進(jìn)行什么樣的操作,這個(gè)控件需要什么屬性;
第二步:
明確我們要做的控件之后就要開始進(jìn)行實(shí)質(zhì)性的技術(shù)攻關(guān)了,就是你要定義好各種要做的方法,明確這些方法是否是技術(shù)可及的;
第三步:
方法實(shí)現(xiàn)階段,將原先已經(jīng)解決的技術(shù)關(guān)鍵點(diǎn)和應(yīng)處理的各個(gè)小范圍處理應(yīng)用到整個(gè)工程;
以下我做的一個(gè)控件的代碼:
///
///此控件達(dá)到的功能是可以隨意控制控件的大小,所在容器的位置,并且此控件實(shí)現(xiàn)了
///在鼠標(biāo)放上去的時(shí)候能夠自動(dòng)變大(需要改變大小可以自己再添加屬性,本控件默認(rèn)長(zhǎng)寬增長(zhǎng)30個(gè)像素),并且會(huì)產(chǎn)生標(biāo)簽顯示控件的信息(可控)
///在鼠標(biāo)離開后會(huì)自動(dòng)變回原來(lái)默認(rèn)的大小,并有畫字畫圖功能(這部分是根據(jù)傳入有限集合進(jìn)行智能繪畫功能,出入集合自行解決,本控件將其省略)
///
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace AnalysisSystem.Object
{
    public partial class DeviceControl : UserControl
    {
        #region 定義各種屬性  

        PRivate bool _showToolTip;//默認(rèn)false
        private bool _InControl;//鼠標(biāo)是否放在控件上的標(biāo)志位

        //設(shè)置窗口的大小
        private Size _SetSize;

        public Size SetSize
        {
            get { return _SetSize; }
            set { _SetSize = value; }
        }
        //將此控件放入容器的大小
        private Point _ContainerSize;

        public Point ContainerSize
        {
            get { return _ContainerSize; }
            set { _ContainerSize = value; }
        }
       
        //設(shè)置控件在容器中的位置
        private Point _showLocation;

        public Point ShowLocation
        {
            get { return _showLocation; }
            set { _showLocation = value; }
        }

        //傳入控制屬性類(有限集合,省略)
...........................................

        #endregion

        public DeviceControl()
        {
            InitializeComponent();
            //透明設(shè)置(在本控件中由于使用了g.clear()方法而失效,可用畫布疊加解決,暫未實(shí)現(xiàn))
            SetStyle(ControlStyles.SupportsTransparentBackColor
                | ControlStyles.UserPaint
                | ControlStyles.AllPaintingInWmPaint
                | ControlStyles.Opaque, true);
            BackColor = Color.Transparent;
          

        }

        #region 定義一些執(zhí)行函數(shù)中需要用到的方法

        //生成信息標(biāo)簽
        private ToolTip Get_Tooltip(string Title)
        {
            ToolTip Node_Box = new ToolTip();
            Node_Box.AutoPopDelay = 5000;
            Node_Box.InitialDelay = 100;
            Node_Box.ReshowDelay = 300;
            Node_Box.ShowAlways = true;
            Node_Box.IsBalloon = true;
            Node_Box.OwnerDraw = true;
            Node_Box.ToolTipIcon = ToolTipIcon.Info;
            Node_Box.ToolTipTitle = Title;
            Node_Box.UseFading = true;
            return Node_Box;
        }
        //產(chǎn)生三角形的各個(gè)點(diǎn)
        private PointF[] GetTrianglePointF()
        {
            PointF point1 = new PointF(ClientSize.Width / 2, 0.0F);
            PointF point2 = new PointF(0.0F, ClientSize.Height);
            PointF point3 = new PointF(ClientSize.Width, ClientSize.Height);
            PointF[] curvePoints =
             {
                 point1,
                 point2,
                 point3,
             };
            return curvePoints;
        }
        //產(chǎn)生多邊形的各個(gè)點(diǎn)
        private PointF[] GetPolygonPointF()
        {
            PointF point1 = new PointF(ClientSize.Width / 2, 0.0F);
            PointF point2 = new PointF(0.0F, ClientSize.Height / 3);
            PointF point3 = new PointF(ClientSize.Width / 4, ClientSize.Height);
            PointF point4 = new PointF(ClientSize.Width / 5 + ClientSize.Width / 5 + ClientSize.Width / 5 + ClientSize.Width / 5, ClientSize.Height);
            PointF point5 = new PointF(ClientSize.Width, ClientSize.Height / 3);
            PointF[] curvePoints =
             {
                 point1,
                 point2,
                 point3,
                 point4,
                 point5
             };
            return curvePoints;
        }
        /// <summary>
        /// 畫字
        /// </summary>
        /// <param name="g">圖對(duì)象</param>
        /// <param name="Word">要畫的字符串</param>
        /// <returns>畫好的圖對(duì)象</returns>

        private Graphics DrawWord(Graphics g, string Word)
        {
            // Create font and brush.
            Font drawFont = new Font("Arial", 8);
            SolidBrush drawBrush = new SolidBrush(Color.Black);

            // Create point for upper-left corner of drawing.
            float x = 0.0F;
            float y = ClientSize.Height / 2;

            // Draw string to screen.
            g.DrawString(Word, drawFont, drawBrush, x, y);//往控件里面寫字
            return g;
        }
        #endregion


        #region 控件使用到的一些消息響應(yīng)方法

        private void DeviceControl_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            Pen mypen = new Pen(Color.Black, 2);

            g.Clear(Color.White);//將背景清除并且填充白色
            //g.DrawImage(this.BackgroundImage, 0, 0, this.Width, this.Height);

            //依照不同的屬性類(集合)畫不同的圖案
...................................................................................


            // 圖像變大超出容器范圍則必須對(duì)其位置進(jìn)行調(diào)整
            if (this._ContainerSize != null)//如果有設(shè)置此控件放入的容器大小
            {
                if ((base.Left + this.ClientSize.Width) > this._ContainerSize.X)//超出右邊邊界
                {
                    base.Left = this._ContainerSize.X - this.ClientSize.Width - 10;
                }
                else
                {
                    if (base.Left != _showLocation.X && !this._InControl)
                        base.Left = _showLocation.X;
                }
                if ((base.Top + this.ClientSize.Height) > this._ContainerSize.Y)//超出下邊邊界
                {
                    base.Top = this._ContainerSize.Y - this.ClientSize.Height - 10;
                }
                else
                {
                    if (base.Top != _showLocation.Y && !this._InControl)
                        base.Top = _showLocation.Y;
                }
            }
        }
        //鼠標(biāo)放到控件上面時(shí)要做的動(dòng)作
        private void DeviceControl_MouseHover(object sender, EventArgs e)
        {
            if (!_showToolTip)
            {
                ToolTip t = this.Get_Tooltip(...);
                 string info="";//標(biāo)簽要顯示的內(nèi)容
                t.SetToolTip(this, info);//this即是綁定到本身
                this._showToolTip = true;
            }
            this.Invalidate();//清除已畫的畫布上的圖形
            this.Size = new System.Drawing.Size(_SetSize.Width + 30, _SetSize.Height + 30);//重繪控件的大小,默認(rèn)是擴(kuò)大30個(gè)像素
            this._InControl = true;


        }      
        //鼠標(biāo)移開時(shí)要做的動(dòng)作
        private void DeviceControl_MouseLeave(object sender, EventArgs e)
        {
            this.Invalidate();//清除已畫的畫布上的圖形
            this.Size = new System.Drawing.Size(_SetSize.Width , _SetSize.Height );//重繪控件的大小
            this._InControl = false;
        }
        #endregion
    }
}


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 最近免费观看高清韩国日本大全 | 亚洲网站一区 | 亚洲福利视频52 | 羞羞视频一区二区 | 暴力肉体进入hdxxxx0 | 国产免费高清在线视频 | 日日操操 | 亚洲影院在线播放 | 在线 日本 制服 中文 欧美 | 国产精品一区二区x88av | 日本综合久久 | 91久久国产综合久久91猫猫 | 一级免费 | 暖暖免费观看高清完整版电影 | 久久久久久久一区二区 | 天天碰天天操 | 日韩精品免费看 | 国产女同玩人妖 | 中文字幕四区 | 99re久久最新地址获取 | 黄色大片网 | 日本一区二区高清不卡 | av91肉丝一区二区电影 | 91网址在线观看 | 免费视频aaa | 一级做a爱片毛片免费 | 欧美日韩在线视频一区 | 27xxoo无遮挡动态视频 | 免费看欧美黑人毛片 | 精品国产乱码一区二区三区四区 | 国产一级在线看 | 中文在线观看视频 | 欧美一级高清片在线 | 日本高清视频网站www | 国产88久久久国产精品免费二区 | 久久最新免费视频 | 精品久久久久久中文字幕 | 色综合网在线观看 | 最新av网址在线观看 | 国产一级毛片视频在线! | 国产激情精品一区二区三区 |