Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
具有图像和自动关闭功能的C#FORM_C#_C# 4.0 - Fatal编程技术网

具有图像和自动关闭功能的C#FORM

具有图像和自动关闭功能的C#FORM,c#,c#-4.0,C#,C# 4.0,我有一个问题,我制作了一个新表单,有背景img,我所需要的一切,它的工作方式和我想要的一样,但我还需要在5秒或10秒后自动关闭它 我在谷歌上搜索了一整天。。。但是没有一个教程是好的。 我使用Visual Studio 2013 你们能帮帮我吗。。。 我现在很绝望。。。我已经试了将近10个小时了。 你是我最后的希望。 谢谢 这不是我做的,或者是我弄错了,但我对此表示怀疑。 应用程序。退出失败 计时器给出错误 //form using System; using System.Collections

我有一个问题,我制作了一个新表单,有背景img,我所需要的一切,它的工作方式和我想要的一样,但我还需要在5秒或10秒后自动关闭它

我在谷歌上搜索了一整天。。。但是没有一个教程是好的。 我使用Visual Studio 2013

你们能帮帮我吗。。。 我现在很绝望。。。我已经试了将近10个小时了。 你是我最后的希望。 谢谢

这不是我做的,或者是我弄错了,但我对此表示怀疑。 应用程序。退出失败 计时器给出错误

//form
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Cerum_HS
{
    public partial class CERUM_HS : Form
    {
        public CERUM_HS()
        {
            InitializeComponent();
            Rectangle r = Screen.PrimaryScreen.WorkingArea;
            this.StartPosition = FormStartPosition.Manual;
            this.Location = new Point(Screen.PrimaryScreen.WorkingArea.Width - this.Width, Screen.PrimaryScreen.WorkingArea.Height - this.Height);
        }
    }
}


//main.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Timers;
//using System.Windows.Forms;

namespace Cerum_HS
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>


        private static System.Timers.Timer aTimer;

        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new CERUM_HS());

            aTimer = new System.Timers.Timer();
            aTimer.Interval = 10;

            aTimer = new System.Timers.Timer(10);

            aTimer.Elapsed += OnTimedEvent;

            aTimer.AutoReset = false;

            aTimer.Enabled = true;
        }

        private static void OnTimedEvent(Object source, System.Timers.ElapsedEventArgs e)
        {
            //Console.WriteLine("The Elapsed event was raised at {0}", e.SignalTime);
            Application.Exit();
            //this.close();
        }
    }
}
//表单
使用制度;
使用System.Collections.Generic;
使用系统组件模型;
使用系统数据;
使用系统图;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
使用System.Windows.Forms;
名称空间Cerum_HS
{
公共部分类CERUM_HS:表格
{
公共教育基金(CERUM_HS)
{
初始化组件();
矩形r=Screen.PrimaryScreen.WorkingArea;
this.StartPosition=FormStartPosition.Manual;
this.Location=新点(Screen.PrimaryScreen.WorkingArea.Width-this.Width,Screen.PrimaryScreen.WorkingArea.Height-this.Height);
}
}
}
//梅因。
使用制度;
使用System.Collections.Generic;
使用System.Linq;
使用System.Threading.Tasks;
使用System.Windows.Forms;
使用系统计时器;
//使用System.Windows.Forms;
名称空间Cerum_HS
{
静态类程序
{
/// 
///应用程序的主要入口点。
/// 
专用静态系统定时器定时器定时器;
[状态线程]
静态void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(新的CERUM_HS());
aTimer=新的System.Timers.Timer();
a时间间隔=10;
aTimer=新系统计时器计时器(10);
aTimer.appeased+=OnTimedEvent;
aTimer.AutoReset=false;
aTimer.Enabled=true;
}
私有静态void OnTimedEvent(对象源,System.Timers.ElapsedEventArgs e)
{
//WriteLine(“在{0}时引发了经过的事件”,例如SignalTime);
Application.Exit();
//这个。关闭();
}
}
}

既然我的评论似乎有帮助,我想我把它写下来作为一个答案

public partial class CERUM_HS : 
{
    // here is the timer for the automatic closing
    private static System.Timers.Timer aTimer;

    public CERUM_HS()
    {
        InitializeComponent();
        Rectangle r = Screen.PrimaryScreen.WorkingArea;
        this.StartPosition = FormStartPosition.Manual;
        this.Location = new Point(Screen.PrimaryScreen.WorkingArea.Width - this.Width, Screen.PrimaryScreen.WorkingArea.Height - this.Height);
    }

    private void Form_Load(object sender, System.EventArgs e)
    {
        // start here the timer when the form is loaded
        aTimer = new System.Timers.Timer();
        aTimer.Interval = 10;

        aTimer = new System.Timers.Timer(10);

        aTimer.Elapsed += OnTimedEvent;

        aTimer.AutoReset = false;

        aTimer.Enabled = true;
    }

    private static void OnTimedEvent(Object source, System.Timers.ElapsedEventArgs e)
    {
        // Close the Application when this event is fired
        Application.Exit();
    }

}

Bogdan请评论此实现是否最终适用于您。

我会在您的表单上放置一个PictureBox和计时器(设置为5000毫秒),单击勾选事件,并使用以下代码:

namespace Image
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            // set picture box to image of interest
            // size and position form appropriately
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            timer1.Enabled = false;
            this.Close();
        }
    }
}

怎么搞的?你把它叫哪里?您遇到了什么错误?我确实从两个文件中调用了函数。有时它不会给出错误,但应用程序会关闭。我现在就发布代码。您对
this.Close()的调用在哪里?你不用定时器吗?可能是在另一个线程中运行?看,现在我添加了我的最后一次尝试。。。仍然没有关闭..您可以尝试将计时器放入CERUM_HS类,在
load
事件中启动它,然后尝试
this.close()
以及this.close();将给出错误替换为Application.Exit();