【发布时间】:2018-08-15 20:46:53
【问题描述】:
我让用户使用 OpenFileDialog 选择一个文件。选择文件并关闭对话框后,主窗口是 alt-tabbing 时的最后一个应用程序。我想让主窗口重新获得焦点并处于前台,而不必在关闭对话框窗口后按 alt+tab 键。这可能吗?如果可以,怎么办?
public class Game1 : Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
Class1 c1;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void Initialize()
{
c1 = c1.Instance;
base.Initialize();
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
c1.Load(Content);
c1.GetFile();
}
}
public sealed class Class1
{
private static Class1 _instance = null;
private static readonly object _padlock = new object();
private Class1()
{
}
public static Class1 Instance
{
get
{
lock (_padlock)
{
if (_instance == null)
{
_instance = new Class1();
}
return _instance;
}
}
}
public void GetFile()
{
string path;
OpenFileDialog ofdSelectLayout = new OpenFileDialog();
if(ofdSelectLayout.ShowDialog() == DialogResult.OK)
{
path = ofdSelectLayout.FileName;
}
//some code
}
public void Load(ContentManager content)
{
//Loading some textures
}
}
【问题讨论】:
标签: c# monogame openfiledialog