所以我在那个类中有一个名为Common.cs的类,我有一个创建表单实例的函数frmMainGame.cs,然后调用一个应该调用这个新表单实例的方法,但由于某种原因,它没有。因此,当使用mainGame.Show() 显示表单时;表格只是挂在那里,我不能用它做任何事情。
这是代码:
frmMainGame.cs
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;
using System.Net.Sockets;
using System.Threading;
namespace Ghoul_Engine
{
public partial class frmMainGame : Form
{
public delegate void openGame();
public delegate void refreshGame();
public delegate void updateScreen(Bitmap image);
drawing draw;
public bool isTyping = false;
public Graphics g;
public List<String> Chat = new List<String>();
public List<String> chat
{
get { return Chat; }
}
public frmMainGame()
{
draw = new drawing(this);
InitializeComponent();
}
public Size size{
get { return this.Size; }
}
public void showGame()
{
if (InvokeRequired)
{
MessageBox.Show("Invoke");
BeginInvoke(new openGame(showGame), null);
}
else
{
this.Show();
this.Focus();
}
}
public void refresh()
{
if (this.InvokeRequired)
{
this.Invoke(new refreshGame(refresh), null);
}
else
{
this.Refresh();
}
}
private void frmMainGame_Load(object sender, EventArgs e)
{
this.DoubleBuffered = true;
draw.drawText(new string[] { "GHOUL Game Engine Alpha V0.0.1" }, 12, 0, 0, Brushes.Yellow);
clientNetHandler handlers = new clientNetHandler();
}
public void update(Bitmap image)
{
if (InvokeRequired)
{
this.Invoke(new updateScreen(update), new object[] { image });
}
else
{
pbScreen.Image = image;
}
}
private void frmMainGame_Close(object sender, FormClosingEventArgs e)
{
Program.Network.Send("logout", Program.netHandlers.getDataByte(clientNetHandler.cNetType.Logout));
//Program.Network.closeSocket();
Program.mainMenu.showMainMenu();
Program.mainGame = new frmMainGame();
}
private void tmrRefreshScreen_Tick(object sender, EventArgs e)
{
}
private void frmMainGame_KeyPress(object sender, KeyPressEventArgs e)
{
}
private void pbScreen_Click(object sender, EventArgs e)
{
draw.drawText(Chat.ToArray(), 12, 0, 30, Brushes.Green);
}
}
}
Common.Cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Sockets;
using System.Net;
using System.Threading;
using System.Drawing;
namespace Ghoul_Engine
{
class Common
{
public Common()
{
}
public void innnitiateGame(String login)
{
Program.mainMenu.hideMainMenu();
frmMainGame mainGame = new frmMainGame();
mainGame.showGame();
}
public void preExit()
{
Program.Network.closeSocket();
}
}
}