| 
 
       
签到天数: 36 天 [LV.5]常住居民I - UID
 - 335 
 - 帖子
 - 104 
 - 精华
 - 1 
 - 积分
 - 1122 
 - 软件
 - 143 套 
 - 稻币
 - 170 元 
 - 贡献
 - 163  
 - 违规
 - 0 次 
 - 注册时间
 - 2009-10-20 
 
    
 | 
前些日子  老师要求做个PPT倒计时  即是时间到了就把PPT强行给关闭 在演示的时候防止有些人厚脸皮拖时间  我用VS2005做的  测试成功 
From1.cs: 
using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Text; 
using System.Windows.Forms; 
namespace ppttime 
{ 
    public partial class Form1 : Form 
    { 
        
        private string myval; 
        public string Form1Value 
        { 
            get { 
                return myval; 
            } 
            set { 
                myval = value; 
            } 
        } 
        public Form1() 
        { 
            InitializeComponent(); 
        } 
        private void Form1_Load(object sender, EventArgs e) 
        { 
            comboBox1.Items.Add("1分钟"); 
            comboBox1.Items.Add("3分钟"); 
            comboBox1.Items.Add("5分钟"); 
            comboBox1.Items.Add("10分钟"); 
            comboBox1.Items.Add("15分钟"); 
            comboBox1.Items.Add("20分钟"); 
        } 
        private void button1_Click(object sender, EventArgs e) 
        { 
            this.Form1Value = comboBox1.Text;  
            Form2 myform2 = new Form2(); 
            myform2.Owner = this;//将自己的引用放到myform2实例的Owner属性。    
            myform2.Show(); 
            this.Hide(); 
            myform2.FormClosing += Form2_FormClosing; //关闭窗体2前显示窗体1 
        } 
        private void Form2_FormClosing(object sender, FormClosingEventArgs e) 
        { 
            this.Show(); 
        } 
    } 
} 
 
From2.cs: 
using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Text; 
using System.Windows.Forms; 
namespace ppttime 
{ 
    public partial class Form2 : Form 
    { 
        Form1 myform1 ;//申明一个对象 
        int timecount; 
        public Form2() 
        { 
            InitializeComponent(); 
        } 
        private void Form2_Load(object sender, EventArgs e) 
        { 
           this.Top=0;this.Left=Screen.PrimaryScreen.WorkingArea.Width-104; 
           myform1 = (Form1)this.Owner;  //将引用(owner)转化为Form1赋给myfrom1,此时myfrom1实例就是你以前的那个实例。    
           string t1 = myform1.Form1Value; 
           string[]  t2 = t1.Split(new char[2]{'分','钟'});//将时间值分离出来 
           timecount = Convert.ToInt32(t2[0]) * 60;//将时间值转换成整形并以秒为单位 
           label1.Text = Convert.ToString(timecount+"秒");//显示设定的时间 
           timer1.Start(); 
        } 
 
        private void FullScreen() //全屏显示时的函数 
        {  
          this.WindowState = FormWindowState.Maximized; 
          Font label1_font = new Font("宋体",72); 
          this.label1.Font = label1_font; 
          label1.Top = (this.Height-label1.Height) / 2; 
          label1.Left = (this.Width-label1.Width) / 2; 
        } 
        private void timer1_Tick(object sender, EventArgs e) 
        { 
            timecount = timecount - 1; 
            if (timecount > 10 && timecount%10==0) 
            { 
                label1.Text = Convert.ToString(timecount + "秒"); 
            } 
            if(0< timecount && timecount<=10) 
            { 
                label1.Text = Convert.ToString(timecount + "秒"); 
            } 
             if(timecount == 0) 
            { 
                label1.Text = "时间到了"; 
                FullScreen(); 
                CloseProcess("POWERPNT");       
            } 
            if (timecount == -3) 
            {  
                timer1.Enabled = false; 
                this.Close(); 
            } 
             
        } 
         private void CloseProcess(string myprocess)//定义结束进程函数 
        { 
            foreach (System.Diagnostics.Process thisproc in System.Diagnostics.Process.GetProcesses()) 
            { 
                if (thisproc.ProcessName.ToString() == myprocess) 
                { 
                    thisproc.Kill(); 
                } 
            } 
        }     
    } 
} 
 
  |   
 
 
 
 |