[英]c# - Methods that are called from another class are not running
我在做一些本來很簡單的事情時遇到了麻煩,我要做的就是從另一個類中調用一個方法,這就是我如何調用該方法:
Gimjes_2D_Game_Framework1.Characters.Character_One.Create();
這是我嘗試調用的方法的內容:
public static void Create()
{
Form1 f = new Form1();
System.Windows.Forms.PictureBox s = new System.Windows.Forms.PictureBox();
//location of image (in thia case it is from resources):
s.BackgroundImage = Gimjes_2D_Game_Framework1.Properties.Resources.DefaultSprite;
//Set to height and width of image:
s.Height = 64;
s.Width = 64;
s.Size = new System.Drawing.Size(60, 60);
s.Location = new System.Drawing.Point(50, 50);
f.Controls.Add(s);
}
嘗試添加
f.Show();
要么
f.ShowDialog();
到您的Create
方法的末尾。
否則,您正在制作表單,並且永遠不會顯示它。
Show
給您一個無模式的表單, ShowDialog
給您一個模式對話框。
有關更多信息,請參見此處的文檔。
如果打算返回 Form1
對象(稍后顯示),則需要將方法更改為:
public static Form1 Create()
{
Form1 f = new Form1();
...
return f;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.