我有一个问题,我做了一个新的形式,与背景img,和我需要和它的工作就像我想要的,但我也需要在5或10秒后自动关闭它。C#FORM与图像和自动关闭
我在谷歌整天搜索......但没有教程是好的。 我使用的是Visual Studio 2013.
你可以男孩帮我吗请... 我现在绝望了......自从我尝试了将近10个小时。 你是我最后的希望。 谢谢
this.close()dosen't做到了,或者我做错了,但我怀疑这一点。 Application.Exit失败 计时器给出错误......
//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();
}
}
}
发生了什么?你在哪里叫它?你得到了什么错误? – SLaks
我确实从这两个文件调用了函数。有时候,它会导致错误,但应用程序关闭。我现在将发布代码。 –
你在哪里调用'this.Close()'?你不使用计时器吗?可能运行在一个单独的线程? –