我有一個問題,我做了一個新的形式,與背景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()'?你不使用計時器嗎?可能運行在一個單獨的線程? –