我想創建一個新組件,當我調用.show()方法時,它將顯示一個啓動畫面。該組件必須像Windows窗體一樣具有圖像和以毫秒爲單位的持續時間,如同參數一樣傳遞。我應該在Visual Studio中選擇哪種類型的項目?如果我選擇一個ClassLibrary,它創建一個dll類,但如果我選擇一個新的ControlLibrary它創建一個新的控件,但我不能使用Windows窗體。爲SplashScreen創建一個C#組件
protected int nSec;
public SplashScreen(string img, int nSec)
{
// duration
this.nSec = nSec;
// background splash screen
this.BackgroundImage = Image.FromFile("img.jpg");
InitializeComponent();
}
private void SplashScreen_Load(object sender, EventArgs e)
{
timer1.Interval = nSec * 1000;
timer1.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
this.Close()
}
我希望在未來的其他工作中重複使用此「組件」,而不是每次都創建一個新組件。
您需要像Windows窗體一樣的東西,但不能使用Windows窗體。你的意思是你不能使用Windows窗體項目模板?或者你不能使用Form對象? –
聽起來像他們希望你創建一個類庫並讓它創建表單,那麼顯然可以調用引用該庫並在需要啓動屏幕時調用所需的函數。 –
但我應該創建一個包含Windows窗體的ClassLibrary和我的Splash Screen? – user2921326