看系统结构的设计的引用关系,现在来说说一下开机时程序自动启动读取数据,如果有进入警戒范围的图书时就从屏幕右下角慢慢出现一个窗口往上移,等他全部出现时就停留一段时间再慢慢往下移,之后退出系统。
     实现效果如下:
 
    
     先说说一下怎么实现它的动作,用三个Timer控件来确定它的位置,一开始时它的位置是在最右下角我们看不到的地方,timUp控件实现它的位置向上,当它完全显示时timMiddle让它停5秒,之后timBottom让它往下。
     图书信息的显示,用一个FlowLayoutPanel容器控件,来动态的显示放在它里面的Label,在该窗口类的构造函数中我们传入一个图书类Book的集合,再根据该集合中的内容来确定Label的内容和个数。
     要注意的是设置Label控制的背景颜色为透明
     //设置Label背景颜色为透明
     labTitle.BackColor = System.Drawing.Color.FromArgb(0, 240, 240, 240);
     还有,当我们双击该窗口时显示出用户编辑的主界面,双击事件是放在FlowLayoutPanel容器中实现的,但Label控件并没有实现,所以把label控制的双击事件关联到容器的双击事件中
     labTitle.DoubleClick += new System.EventHandler(this.PanelShowBookInfo_DoubleClick);
     具体的实现代码如下,创建工程WarningUI,添加一个窗体类frmWarning.cs

 Code
Code
 using System;
using System;
 using System.Collections.Generic;
using System.Collections.Generic;
 using System.ComponentModel;
using System.ComponentModel;
 using System.Data;
using System.Data;
 using System.Drawing;
using System.Drawing;
 using System.Text;
using System.Text;
 using System.Windows.Forms;
using System.Windows.Forms;
 using System.Collections;
using System.Collections;

 using LibraryHelper.Model;
using LibraryHelper.Model;
 using LibraryHelper.EditUI;
using LibraryHelper.EditUI;


 namespace LibraryHelper.WarningUI
namespace LibraryHelper.WarningUI


 {
{
 public partial class frmWarning : Form
    public partial class frmWarning : Form

 
     {
{
 //设置一个静态变量来保存窗体变化的高度
        //设置一个静态变量来保存窗体变化的高度
 static int hight;
        static int hight;

 public frmWarning(List<Book> listBook)
        public frmWarning(List<Book> listBook)

 
         {
{
 InitializeComponent();
            InitializeComponent();



 //-----------------向窗体添加图书信息---------------------
            //-----------------向窗体添加图书信息---------------------
 int num = listBook.Count;
            int num = listBook.Count;
 for (int i = 0; i < num; i++)
            for (int i = 0; i < num; i++)

 
             {
{
 Book book = listBook[i];
                Book book = listBook[i];

 Label labTitle = new Label();
                Label labTitle = new Label();
 labTitle.Text = book.Title;
                labTitle.Text = book.Title;
 labTitle.Width = 150;
                labTitle.Width = 150;
 labTitle.ForeColor = System.Drawing.Color.White;
                labTitle.ForeColor = System.Drawing.Color.White;
 //设置Label背景颜色为透明
                //设置Label背景颜色为透明
 labTitle.BackColor = System.Drawing.Color.FromArgb(0, 240, 240, 240);
                labTitle.BackColor = System.Drawing.Color.FromArgb(0, 240, 240, 240);
 labTitle.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
                labTitle.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
 labTitle.AutoEllipsis = true;
                labTitle.AutoEllipsis = true;
 //把label控制的双击事件关联到容器的双击事件中
                //把label控制的双击事件关联到容器的双击事件中
 labTitle.DoubleClick += new System.EventHandler(this.PanelShowBookInfo_DoubleClick);
                labTitle.DoubleClick += new System.EventHandler(this.PanelShowBookInfo_DoubleClick);
 this.PanelShowBookInfo.Controls.Add(labTitle);
                this.PanelShowBookInfo.Controls.Add(labTitle);

 Label labDayNum = new Label();
                Label labDayNum = new Label();
 labDayNum.Text = book.WarningDay + "天";
                labDayNum.Text = book.WarningDay + "天";
 labDayNum.ForeColor = System.Drawing.Color.Red;
                labDayNum.ForeColor = System.Drawing.Color.Red;
 labDayNum.BackColor = System.Drawing.Color.FromArgb(0, 240, 240, 240);
                labDayNum.BackColor = System.Drawing.Color.FromArgb(0, 240, 240, 240);
 labDayNum.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
                labDayNum.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
 labDayNum.Width = 40;
                labDayNum.Width = 40;
 //把label控制的双击事件关联到容器的双击事件中
                //把label控制的双击事件关联到容器的双击事件中
 labDayNum.DoubleClick += new System.EventHandler(this.PanelShowBookInfo_DoubleClick);
                labDayNum.DoubleClick += new System.EventHandler(this.PanelShowBookInfo_DoubleClick);
 this.PanelShowBookInfo.Controls.Add(labDayNum);
                this.PanelShowBookInfo.Controls.Add(labDayNum);
 }
            }


 //-------------------控制窗体开始始位置在右下角-----------------------
            //-------------------控制窗体开始始位置在右下角-----------------------
 
            
 hight = Screen.PrimaryScreen.Bounds.Height;
            hight = Screen.PrimaryScreen.Bounds.Height;
 this.Location = new Point(Screen.PrimaryScreen.WorkingArea.Width - 248, hight);
            this.Location = new Point(Screen.PrimaryScreen.WorkingArea.Width - 248, hight);

 }
        }

 private void frmSendBookMessage_FormClosed(object sender, FormClosedEventArgs e)
        private void frmSendBookMessage_FormClosed(object sender, FormClosedEventArgs e)

 
         {
{
 Application.Exit();
            Application.Exit();
 }
        }

 //使窗体的位置从下面往上起
        //使窗体的位置从下面往上起
 private void timUp_Tick(object sender, EventArgs e)
        private void timUp_Tick(object sender, EventArgs e)

 
         {
{
 if (this.Location.Y > Screen.PrimaryScreen.WorkingArea.Height - 145)
            if (this.Location.Y > Screen.PrimaryScreen.WorkingArea.Height - 145)

 
             {
{
 hight -= 1;
                hight -= 1;
 this.Location = new Point(Screen.PrimaryScreen.WorkingArea.Width - 248, hight);
                this.Location = new Point(Screen.PrimaryScreen.WorkingArea.Width - 248, hight);
 }
            }
 else
            else

 
             {
{
 timUp.Enabled = false;
                timUp.Enabled = false;
 timMiddle.Enabled = true;
                timMiddle.Enabled = true;
 }
            }
 }
        }

 //上升到顶部就停3秒
        //上升到顶部就停3秒
 private void timMiddle_Tick(object sender, EventArgs e)
        private void timMiddle_Tick(object sender, EventArgs e)

 
         {
{
 timMiddle.Enabled = false;
            timMiddle.Enabled = false;
 timBottom.Enabled = true;
            timBottom.Enabled = true;
 }
        }

 //当在顶部时就往下走
        //当在顶部时就往下走
 private void timBottom_Tick(object sender, EventArgs e)
        private void timBottom_Tick(object sender, EventArgs e)

 
         {
{
 if (this.Location.Y < Screen.PrimaryScreen.Bounds.Height)
            if (this.Location.Y < Screen.PrimaryScreen.Bounds.Height)

 
             {
{
 hight += 1;
                hight += 1;
 this.Location = new Point(Screen.PrimaryScreen.WorkingArea.Width - 248, hight);
                this.Location = new Point(Screen.PrimaryScreen.WorkingArea.Width - 248, hight);
 }
            }
 else
            else

 
             {
{
 timBottom.Enabled = false;
                timBottom.Enabled = false;
 this.Close();
                this.Close();
 }
            }
 }
        }

 //当用户双击时就调出用户编辑主界面
        //当用户双击时就调出用户编辑主界面
 private void PanelShowBookInfo_DoubleClick(object sender, EventArgs e)
        private void PanelShowBookInfo_DoubleClick(object sender, EventArgs e)

 
         {
{
 timUp.Enabled = false;
            timUp.Enabled = false;
 timMiddle.Enabled = false;
            timMiddle.Enabled = false;
 timBottom.Enabled = false;
            timBottom.Enabled = false;

 this.Hide();
            this.Hide();

 frmLiraryEdit frmEdit = frmLiraryEdit.GetSinglefrmEdit();
            frmLiraryEdit frmEdit = frmLiraryEdit.GetSinglefrmEdit();
 frmEdit.Show();
            frmEdit.Show();

 }
        }
 }
    }
 }
}