VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > 编程开发 > Objective-C编程 >
  • 用c#制出消息提示窗体的日期管理器2

制作者:剑锋冷月 单位:无忧统计网,www.51stat.net
 


      //
      // Myconn
      //
      this.Myconn.ConnectionString = @"Jet OLEDB:Global Partial Bulk Ops=2;
      Jet OLEDB:Registry Path=;
      Jet OLEDB:Database Locking Mode=1;
      Jet OLEDB:Database Password=;
      Data Source=""F:Visual Studio ProjectsCalendarinDebugcalendar.mdb"";
      Password=;
      Jet OLEDB:Engine Type=5;
      Jet OLEDB:Global Bulk Transactions=1;
      Provider=""Microsoft.Jet.OLEDB.4.0"";
      Jet OLEDB:System database=;
      Jet OLEDB:SFP=False;
      Extended Properties=;
      Mode=Share Deny None;
      Jet OLEDB:New Database Password=;
      Jet OLEDB:Create System Database=False;
      Jet OLEDB:Don't Copy Locale on Compact=False;
      Jet OLEDB:Compact Without Replica Repair=False;
      User ID=Admin;
      Jet OLEDB:Encrypt Database=False";
      //
      // Mycmd
      //
      this.Mycmd.CommandText = "SELECT calendar.*, [datetime] AS Expr1, info AS Expr2 FROM calendar ORDER BY id";
      
      this.Mycmd.Connection =
      this.Myconn;
      //
      // checkedListBox1
      //
      this.checkedListBox1.Location = new System.Drawing.Po
      int( 6, 16 );
      
      this.checkedListBox1.Name = "checkedListBox1";
      
      this.checkedListBox1.Size = new System.Drawing.Size( 376, 225 );
      
      this.checkedListBox1.TabIndex = 3;
      //
      // label4
      //
      this.label4.Location = new System.Drawing.Po
      int( 16, 24 );
      
      this.label4.Name = "label4";
      
      this.label4.Size = new System.Drawing.Size( 48, 23 );
      
      this.label4.TabIndex = 1;
      
      this.label4.Text = "标题:";
      
      this.label4.TextAlign = System.Drawing.ContentAlignment.TopRight;
      //
      // textBox6
      //
      this.textBox6.Location = new System.Drawing.Po
      int( 72, 24 );
      
      this.textBox6.Name = "textBox6";
      
      this.textBox6.Size = new System.Drawing.Size( 184, 22 );
      
      this.textBox6.TabIndex = 2;
      
      this.textBox6.Text = "";
      //
      // insertcmd
      //
      this.insertcmd.Connection =
      this.Myconn;
      //
      // Form1
      //
      this.AutoScaleBaseSize = new System.Drawing.Size( 7, 15 );
      
      this.ClientSize = new System.Drawing.Size( 392, 363 );
      
      this.Controls.Add( this.textBox4 );
      
      this.Controls.Add( this.button2 );
      
      this.Controls.Add( this.button1 );
      
      this.Controls.Add( this.tabControl1 );
      
      this.Icon = ( ( System.Drawing.Icon )( resources.GetObject( "$
      this.Icon" ) ) );
      
      this.MaximizeBox = false;
      
      this.Name = "Form1";
      
      this.Text = "Calendar By Sinory Studio";
      
      this.Load += new System.EventHandler( this.Form1_Load );
      
      this.tabControl1.ResumeLayout( false );
      
      this.tabPage1.ResumeLayout( false );
      
      this.groupBox1.ResumeLayout( false );
      
      this.first.ResumeLayout( false );
      
      this.ResumeLayout( false );
    }
    #endregion
    /// <summary> 
    /// 应用程序的主入口点. 
    /// </summary> [STAThread] static void Main( )
    {
      Application.Run( new Form1( ) );
    }
    
    private void Form1_Load( object sender, System.EventArgs e ) 
    {
      this.timer1.Enabled=true;
      //设置timer控件的属性
      select( );
      //从数据库中读取最近的一次提示
    }
    
    private void button1_Click( object sender, System.EventArgs e ) 
    {
    }
    
    private void tabControl1_SelectedIndexChanged( object sender, System.EventArgs e ) 
    {
    }
    
    private void button2_Click( object sender, System.EventArgs e ) 
    {
      this.Close( );
      //退出 
    }
    
    private void first_Click( object sender, System.EventArgs e ) 
    {
    }
    
    private void textBox1_TextChanged( object sender, System.EventArgs e ) 
    {
    }
    
    private void select( ) 
    {
      DateTime dn=DateTime.Now;
      DateTime datetime;
      Myconn.Open( );
      dr=Mycmd.ExecuteReader( );
      
      string title,id;
      da=DateTime.Parse( "3000-1-1 01:01:01" );
      //设一个大点的值
      while( dr.Read( ) )//读取数据库
      {
        datetime=DateTime.Parse( dr["datetime"].ToString( ) );
        id=dr["id"].ToString( );
        title=dr["title"].ToString( );
        
        this.checkedListBox1.Items.Add( id+"
        "+datetime.ToString( )+"
        "+title );
        if( datetime>dn&&datetime<da )
        {
          da=datetime;
          //取值
          info=dr["info"].ToString( );
        }
      }
      dr.Close( );
      Myconn.Close( );
      //关闭数据库
      this.textBox5.Text="Next:"+da.ToString( );
      //显示最近的一次提示的时间
    }
    
    private void button1_Click_1( object sender, System.EventArgs e ) 
    {
      this.Hide( );
      //主窗体隐藏 
    }
    
    private void timer1_Tick( object sender, System.EventArgs e ) 
    {
      //接收当前日期和时间,用于即时显示
      string CurrTime=System.DateTime.Now.ToString( );
      
      this.textBox4.Text="当前时间:"+CurrTime;
      if( DateTime.Parse( CurrTime )==da )
      {
        clew clew1=new clew( );
        //设置提示窗体的属性
        clew1.HeightMax=150;
        clew1.WidthMax=180;
        clew1.Info=info;
        clew1.ScrollShow( );
        select( );
      }
    }
    
    private void button4_Click( object sender, System.EventArgs e ) 
    {
      this.textBox1.Text="";
      
      this.textBox2.Text="";
      
      this.textBox3.Text="";
      
      this.textBox6.Text="";
    }
    
    private void button3_Click( object sender, System.EventArgs e ) 
    {
      if( this.textBox1.Text!=""&&
      this.textBox2.Text!=""&&
      this.textBox3.Text!=""&&
      this.textBox6.Text!="" )
      {
        string indate=
        this.textBox1+" "+
        this.textBox2.Text;
        insertcmd.CommandText="insert
        into calendar( datetime,info,title ) values( '"+indate+"','"+
        this.textBox3.ToString( )+"','"+
        this.textBox6.ToString( )+"' )";
        Myconn.Open( );
        insertcmd.ExecuteNonQuery( );
        Myconn.Close( );
        select( );
        MessageBox.Show( "添加成功?? );
      }
      else
      {
        MessageBox.Show( "请按指定格式填写并且各项不能为空?? );
      }
    }
  }
}

以下为提示窗体代码:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace Calendar
{
  /// <summary>
  /// clew 的摘要说明.
  /// </summary>
  public class clew : System.Windows.Forms.Form
  {
    private System.Windows.Forms.Timer timer1;
    
    private System.Windows.Forms.Timer timer2;
    
    private System.Windows.Forms.Timer timer3;
    
    private System.Windows.Forms.Label label1;
    
    private System.Windows.Forms.Label label2;
    
    private System.ComponentModel.IContainer components;
    
    public clew( ) 
    {
      //
      // Windows 窗体设计器支持所必需的
      //
      InitializeComponent( );
      //
      // TODO: 在
      InitializeComponent 调用后添加任何构造函数代码
      // 
    }
    
    /// <summary> 
    /// 清理所有正在使用的资源. 
    /// </summary> 
    protected override void Dispose(bool disposing) 
    {
      if(disposing)
      {
        if( components != null )
        {
          components.Dispose( );
        }
      }
      base.Dispose(disposing);
    }
    #region Windows 窗体设计器生成的代码 
    /// <summary> 
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改 
    /// 此方法的内容. 
    /// </summary> 
    private void
    InitializeComponent( ) 
    {
      this.components = new System.ComponentModel.Container( );
      
      this.timer1 = new System.Windows.Forms.Timer( this.components );
      
      this.timer2 = new System.Windows.Forms.Timer( this.components );
      
      this.timer3 = new System.Windows.Forms.Timer( this.components );
      
      this.label1 = new System.Windows.Forms.Label( );
      
      this.label2 = new System.Windows.Forms.Label( );
      
      this.SuspendLayout( );
      //
      // timer1
      //
      this.timer1.Interval = 10;
      
      this.timer1.Tick += new System.EventHandler( this.timer1_Tick );
      //
      // timer2
      //
      this.timer2.Interval = 10;
      
      this.timer2.Tick += new System.EventHandler( this.timer2_Tick );
      //
      // timer3
      //
      this.timer3.Interval = 10;
      
      this.timer3.Tick += new System.EventHandler( this.timer3_Tick );
      //
      // label1
      //
      this.label1.Location = new System.Drawing.Po
      int( 24, 40 );
      
      this.label1.Name = "label1";
      
      this.label1.Size = new System.Drawing.Size( 152, 96 );
      
      this.label1.TabIndex = 0;
      //
      // label2
      //
      this.label2.Location = new System.Drawing.Po
      int( 0, 0 );
      
      this.label2.Name = "label2";
      
      this.label2.Size = new System.Drawing.Size( 192, 24 );
      
      this.label2.TabIndex = 1;
      //
      // clew
      //
      this.AutoScaleBaseSize = new System.Drawing.Size( 7, 15 );
      
      this.BackColor = System.Drawing.SystemColors.InactiveCaption;
      
      this.ClientSize = new System.Drawing.Size( 194, 150 );
      
      this.Controls.Add( this.label2 );
      
      this.Controls.Add( this.label1 );
      
      this.Cursor = System.Windows.Forms.Cursors.Hand;
      
      this.ForeColor = System.Drawing.SystemColors.ActiveCaptionText;
      
      this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
      
      this.MaximizeBox = false;
      
      this.MinimizeBox = false;
      
      this.Name = "clew";
      
      this.ShowInTaskbar = false;
      
      this.Text = "提示……";
      
      this.TopMost = true;
      
      this.Load += new System.EventHandler( this.clew_Load );
      
      this.ResumeLayout( false );
    }
    #endregion 
    private
    string info;
    //设置提示窗体的内容; 
    public
    string Info 
    {
      set
      {
        info=value;
      }
      get
      {
        return info;
      }
    }
    
    private
    int heightMax, widthMax;
    //设置窗体显示的大小的属性 
    public
    int HeightMax 
    {
      set
      {
        heightMax = value;
      }
      get
      {
        return heightMax;
      }
    }
    
    public
    int WidthMax 
    {
      set
      {
        widthMax = value;
      }
      get
      {
        return widthMax;
      }
    }
    
    public void ScrollShow( ) 
    {
      this.Width = widthMax;
      
      this.Height = 0;
      
      this.Show( );
      
      this.timer1.Enabled = true;
    }
    
    public
    int StayTime = 5000;
    //窗体的停留时间 //窗体的滚出与滚入方法 
    private void ScrollUp( ) 
    {
      if( Height < heightMax )
      {
        this.Height += 3;
        
        this.Location = new Po
        int( this.Location.X,
        this.Location.Y - 3 );
      }
      else
      {
        this.timer1.Enabled = false;
        
        this.timer2.Enabled = true;
      }
    }
    
    private void ScrollDown( ) 
    {
      if( Height > 3 )
      {
        this.Height -= 3;
        
        this.Location = new Po
        int( this.Location.X,
        this.Location.Y + 3 );
      }
      else
      {
        this.timer3.Enabled = false;
        
        this.Close( );
      }
    }
    
    private void clew_Load( object sender, System.EventArgs e ) 
    {
      string dNow;
      dNow=DateTime.Now.ToShortTimeString( ).ToString( );
      
      this.label2.Text="现在时刻是:"+dNow;
      
      this.label1.Text=info;
      Screen[] screens = Screen.AllScreens;
      Screen screen = screens[0];
      //获取屏幕变量
      this.Location = new Po
      int( screen.WorkingArea.Width - widthMax - 20, screen.WorkingArea.Height - 34 );
      //WorkingArea为Windows桌面的工作区
      this.timer2.Interval = StayTime;
    }
    
    private void timer1_Tick( object sender, System.EventArgs e ) 
    {
      ScrollUp( );
    }
    
    private void timer2_Tick( object sender, System.EventArgs e ) 
    {
      timer2.Enabled = false;
      timer3.Enabled = true;
    }
    
    private void timer3_Tick( object sender, System.EventArgs e ) 
    {
      ScrollDown( );
    }
  }
}

//由于是从VS2003下编的所以这些代码不能直接运行,但可以提供一个思路,另外还可以加个托盘图标或,其他小功能.



相关教程