C# 如何在应用程序启动时将其最小化?

C# 如何在应用程序启动时将其最小化?,c#,windows-mobile,C#,Windows Mobile,如何在Windows Mobile 6中启动应用程序并在后台运行时最小化它?我想尽量减少应用程序自动启动(即自动启动),当以后,如果用户想看到应用程序,它可以从程序菜单等运行 我尝试了一些代码,但不起作用 传统的最小化方案,虽然它不能解决我的问题,因为使用此代码将永远不会向用户再次显示应用程序(即使此代码不起作用) 第二个选项是调用本机API(源代码:) 第二个代码确实可以从程序的任何其他部分工作,但不能从加载事件工作。我认为唯一的解决方案是使用System.Windows.Forms.Time

如何在Windows Mobile 6中启动应用程序并在后台运行时最小化它?我想尽量减少应用程序自动启动(即自动启动),当以后,如果用户想看到应用程序,它可以从程序菜单等运行

我尝试了一些代码,但不起作用

传统的最小化方案,虽然它不能解决我的问题,因为使用此代码将永远不会向用户再次显示应用程序(即使此代码不起作用)

第二个选项是调用本机API(源代码:)


第二个代码确实可以从程序的任何其他部分工作,但不能从加载事件工作。

我认为唯一的解决方案是使用
System.Windows.Forms.Timer
,它可以工作

private void GUI_Load(object sender, EventArgs e)
{                        
// Initialize timer to hide application when automatically launched
_hideTimer = new System.Windows.Forms.Timer();
_hideTimer.Interval = 0; // 0 Seconds
_hideTimer.Tick += new EventHandler(_hideTimer_Tick);
_hideTimer.Enabled = true;
}

// Declare timer object
System.Windows.Forms.Timer _hideTimer;
void _hideTimer_Tick(object sender, EventArgs e)
{
    // Disable timer to not use it again
    _hideTimer.Enabled = false;
    // Hide application
    this.HideApplication();
    // Dispose timer as we need it only once when application auto-starts
    _hideTimer.Dispose();
}

[DllImport("coredll.dll")]
static extern int ShowWindow(IntPtr hWnd, int nCmdShow);

const int SW_MINIMIZED = 6;

public void HideApplication()
{
      ShowWindow(this.Handle, SW_MINIMIZED);
}

第二种方法在Load事件中不起作用,因为表单尚未完全初始化,因此无法最小化它。你试过在OnActivated或OnShow中调用HideApplication吗?它是有效的,我想我应该使用一个变量来隐藏它一次!不,它在激活的事件上不起作用,所以唯一的解决方案是定时器!
private void GUI_Load(object sender, EventArgs e)
{                    
     this.HideApplication();
}

[DllImport("coredll.dll")]
static extern int ShowWindow(IntPtr hWnd, int nCmdShow);

const int SW_MINIMIZED = 6;

public void HideApplication()
{
      ShowWindow(this.Handle, SW_MINIMIZED);
}
private void GUI_Load(object sender, EventArgs e)
{                        
// Initialize timer to hide application when automatically launched
_hideTimer = new System.Windows.Forms.Timer();
_hideTimer.Interval = 0; // 0 Seconds
_hideTimer.Tick += new EventHandler(_hideTimer_Tick);
_hideTimer.Enabled = true;
}

// Declare timer object
System.Windows.Forms.Timer _hideTimer;
void _hideTimer_Tick(object sender, EventArgs e)
{
    // Disable timer to not use it again
    _hideTimer.Enabled = false;
    // Hide application
    this.HideApplication();
    // Dispose timer as we need it only once when application auto-starts
    _hideTimer.Dispose();
}

[DllImport("coredll.dll")]
static extern int ShowWindow(IntPtr hWnd, int nCmdShow);

const int SW_MINIMIZED = 6;

public void HideApplication()
{
      ShowWindow(this.Handle, SW_MINIMIZED);
}