玩控件的继承( 一个很有意思的气球小程序 )DotNetBar

首先给大家介绍一个很不错的控件
DotNetBar,它包含很多漂亮的控件,功能也委实强大
适用于WinForm编程,我这有一个破解版的 (点击下载)
右边是安装完成后我的。NET工具箱中出现的相关控件

这里我要说的小程序玩继承
第一步:新建一个WinForm工程,相信这是很简单的啦
第二步:把自动生成的窗体删除
第三步:添加DevComponents.DotNetBar的dll引用
第四步:添加继承的窗体(自定义你窗体的名称),
                选择要继承的组件为Ballon如下图所示%7BDE09DDA7-C0ED-409D-AE82-5EB3D95512B6%7D0.jpg

第五步:初始化你的窗体

        要说明的是:你的窗体继承自Ballon所有具有了Ballon的属性,哈哈,是不是很好玩呢?
那就意味着,你的窗体可以像Ballon那样完成提醒的功能,而且提醒完之后,生命自动终止
还有很多更神奇的功能先不说,我们先来吧这个程序完成吧……
        它是支持可视化效果的,你的任何修改马上可以在Form里看到,你当然也可以像编其他任何
WinForm程序一样,往窗体里拖你的控件,就和操作其他窗体一样。
        你想让它干什么,就在给它编什么样的代码,提醒你的日程安排、纪念日等等

这里我做的是让它提醒我和女朋友在一起的日子多少天
代码和简单注释如下:
  1 None.gif using  System;
  2 None.gif using  System.Collections;
  3 None.gif using  System.ComponentModel;
  4 None.gif using  System.Drawing;
  5 None.gif using  System.Windows.Forms;
  6 None.gif using  DevComponents.DotNetBar;
  7 None.gif
  8 None.gif namespace  EveryDayNotice
  9 ExpandedBlockStart.gifContractedBlock.gif dot.gif {
 10InBlock.gif    public class EveryDayNotice : DevComponents.DotNetBar.Balloon
 11ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
 12InBlock.gif        private System.Windows.Forms.Label label1;
 13InBlock.gif        private System.Windows.Forms.Timer timer1;
 14InBlock.gif        private System.ComponentModel.IContainer components = null;
 15InBlock.gif
 16InBlock.gif        public EveryDayNotice()
 17ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 18InBlock.gif            // 该调用是 Windows 窗体设计器所必需的。
 19InBlock.gif            InitializeComponent();
 20ExpandedSubBlockEnd.gif        }

 21InBlock.gif
 22InBlock.gif        
 23InBlock.gif        protected override void Dispose( bool disposing )
 24ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 25InBlock.gif            if( disposing )
 26ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 27InBlock.gif                if (components != null
 28ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
 29InBlock.gif                    components.Dispose();
 30ExpandedSubBlockEnd.gif                }

 31ExpandedSubBlockEnd.gif            }

 32InBlock.gif            base.Dispose( disposing );
 33ExpandedSubBlockEnd.gif        }

 34InBlock.gif
 35InBlock.gif        [STAThread]
 36InBlock.gif        static void Main() 
 37ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 38InBlock.gif            Application.Run(new  EveryDayNotice());
 39ExpandedSubBlockEnd.gif        }

 40InBlock.gif
 41InBlock.gif        //我的获取提醒时间的简单函数
 42InBlock.gif        public int GetDayNotice()
 43ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 44InBlock.gif            DateTime date1 = Convert.ToDateTime(Convert.ToDateTime("2005-4-6"));
 45InBlock.gif            DateTime date2 = DateTime.Now.Date;
 46InBlock.gif
 47InBlock.gif            System.TimeSpan diff1 = date1.Subtract(Convert.ToDateTime("2005-6-25"));
 48InBlock.gif            System.TimeSpan diff2 = date2.Subtract(Convert.ToDateTime("2005-6-25"));
 49InBlock.gif            System.TimeSpan diff3 = diff2 - diff1;
 50InBlock.gif            return diff3.Days;
 51ExpandedSubBlockEnd.gif        }

 52InBlock.gif
 53ExpandedSubBlockStart.gifContractedSubBlock.gif        设计器生成的代码#region 设计器生成的代码
 54ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
 55InBlock.gif        /// 设计器支持所需的方法 - 说明:根据你拖的控件,修改的属性自动生成
 56ExpandedSubBlockEnd.gif        /// </summary>

 57InBlock.gif        private void InitializeComponent()
 58ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 59InBlock.gif            this.components = new System.ComponentModel.Container();
 60InBlock.gif            System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(EveryDayNotice));
 61InBlock.gif            this.label1 = new System.Windows.Forms.Label();
 62InBlock.gif            this.timer1 = new System.Windows.Forms.Timer(this.components);
 63InBlock.gif            this.SuspendLayout();
 64InBlock.gif            // 
 65InBlock.gif            // label1
 66InBlock.gif            // 
 67InBlock.gif            this.label1.Font = new System.Drawing.Font("宋体"10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
 68InBlock.gif            this.label1.ForeColor = System.Drawing.Color.Red;
 69InBlock.gif            this.label1.Location = new System.Drawing.Point(4872);
 70InBlock.gif            this.label1.Name = "label1";
 71InBlock.gif            this.label1.Size = new System.Drawing.Size(24048);
 72InBlock.gif            this.label1.TabIndex = 0;
 73InBlock.gif            this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
 74InBlock.gif            // 
 75InBlock.gif            // timer1
 76InBlock.gif            // 
 77InBlock.gif            this.timer1.Enabled = true;
 78InBlock.gif            this.timer1.Interval = 1000;
 79InBlock.gif            this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
 80InBlock.gif            // 
 81InBlock.gif            // EveryDayNotice
 82InBlock.gif            // 
 83InBlock.gif            this.AlertAnimationDuration = 100;
 84InBlock.gif            this.AutoScaleBaseSize = new System.Drawing.Size(714);
 85InBlock.gif            this.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(207)), ((System.Byte)(221)), ((System.Byte)(244)));
 86InBlock.gif            this.BackColor2 = System.Drawing.Color.White;
 87InBlock.gif            this.CaptionColor = System.Drawing.Color.Red;
 88InBlock.gif            this.CaptionFont = new System.Drawing.Font("Tahoma", 8F, System.Drawing.FontStyle.Bold);
 89InBlock.gif            this.CaptionImage = ((System.Drawing.Image)(resources.GetObject("$this.CaptionImage")));
 90InBlock.gif            this.CaptionText = "I love you for ever";
 91InBlock.gif            this.ClientSize = new System.Drawing.Size(355152);
 92InBlock.gif            this.CloseButtonHot = ((System.Drawing.Image)(resources.GetObject("$this.CloseButtonHot")));
 93InBlock.gif            this.CloseButtonNormal = ((System.Drawing.Image)(resources.GetObject("$this.CloseButtonNormal")));
 94InBlock.gif            this.CloseButtonPressed = ((System.Drawing.Image)(resources.GetObject("$this.CloseButtonPressed")));
 95InBlock.gif            this.Controls.Add(this.label1);
 96InBlock.gif            this.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
 97InBlock.gif            this.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(102)), ((System.Byte)(114)), ((System.Byte)(196)));
 98InBlock.gif            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
 99InBlock.gif            this.Location = new System.Drawing.Point(1024768);
100InBlock.gif            this.Name = "EveryDayNotice";
101InBlock.gif            this.Opacity = 0.8;
102InBlock.gif            this.Style = DevComponents.DotNetBar.eBallonStyle.Alert;
103InBlock.gif            this.ResumeLayout(false);
104InBlock.gif
105ExpandedSubBlockEnd.gif        }

106ExpandedSubBlockEnd.gif        #endregion

107InBlock.gif
108InBlock.gif
109InBlock.gif        //弹出提箱气球的函数
110InBlock.gif        public void Myshow()
111ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
112InBlock.gif            label1.Text = "今天是我们在一起第 "+GetDayNotice()+" 天";    
113InBlock.gif            Rectangle r=Screen.GetWorkingArea(this);
114InBlock.gif            //设置出现位置
115InBlock.gif            this.Location=new Point(r.Right-this.Width,r.Bottom-this.Height);
116InBlock.gif            //必须的,自动Dispose
117InBlock.gif            this.AutoClose=true;
118InBlock.gif            //自动消失的时间
119InBlock.gif            this.AutoCloseTimeOut=5;
120InBlock.gif            //弹出动画,这里是从底往上
121InBlock.gif            this.AlertAnimation=eAlertAnimation.BottomToTop;
122InBlock.gif            //动画时间
123InBlock.gif            this.AlertAnimationDuration=300;
124InBlock.gif            this.Show(false);
125ExpandedSubBlockEnd.gif        }

126InBlock.gif
127InBlock.gif        //注:Timeer控件让它在一定时间期之后发生一次Show()
128InBlock.gif        private void timer1_Tick(object sender, System.EventArgs e)
129ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
130InBlock.gif            timer1.Stop();
131InBlock.gif            timer1.Enabled=false;
132InBlock.gif            Myshow();
133ExpandedSubBlockEnd.gif        }

134ExpandedSubBlockEnd.gif    }

135ExpandedBlockEnd.gif}

136 None.gif
137 None.gif


哈哈,是不是很好玩呢?
.DotNetBar是个很爽的东西,推荐给大家……

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值