好吧,所以我需要在c#中做一個簡單的動畫作爲加載圖標使用。這個工作都很好,好,所以讓我們這個廣場爲例圖形從一個類到表格
PictureBox square = new PictureBox();
Bitmap bm = new Bitmap(square.Width, square.Height);
Graphics baseImage = Graphics.FromImage(bm);
baseImage.DrawRectangle(Pens.Black, 0, 0, 100, 100);
square.Image = bm;
與我做我的動畫,一切都在這裏工作
所以,後來我意識到,我需要我的動畫是在一個類,所以我可以從我的合作者計劃中調用它來使用動畫。這是問題出現的地方,我做了我的課程,我做了所有事情,但是在一個班級而不是表格中,然後我從表格中調用我的班級,但屏幕是空白的,沒有動畫。有什麼需要通過才能做到這一點?
namespace SpinningLogo
{//Here is the sample of my class
class test
{
public void square()
{
PictureBox square = new PictureBox();
Bitmap bm = new Bitmap(square.Width, square.Height);
Graphics baseImage = Graphics.FromImage(bm);
baseImage.DrawRectangle(Pens.Black, 0, 0, 100, 100);
square.Image = bm;
}
}
}
private void button1_Click(object sender, EventArgs e)
{//Here is how I call my class
Debug.WriteLine("11");
test square = new test();
square.square();
}
我沒有看到你在哪裏顯示'PictureBox'。作爲一個孩子控制之前,它是「在形式上」嗎?但現在你沒有這樣做? – DonBoitnott
您是試圖在窗體上新建一個「PictureBox」還是在現有的「PictureBox」上寫? – CodeCamper