1

我想制作程序名称 Cyan Pembuat Soal(Cyan Question Maker) 我将启动事件添加到此代码:

using System;
using System.Windows;

namespace Cyan_Pembuat_Soal {
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application {
        private void Application_Startup(object sender, StartupEventArgs e){
            if (FindPlace(e.Args) != null) {
                Cyan_Pembuat_Soal.MainWindow a = new Cyan_Pembuat_Soal.MainWindow();
                a.Activate();
            } else {
                Cyan_Pembuat_Soal.MainWindow a = new Cyan_Pembuat_Soal.MainWindow();
                a.Activate();
                a.Closed += delegate(object senders, EventArgs es) {this.Shutdown();};
            }
        }
        private static string FindPlace(string[] a) {
            if (a.Length == 0) {
                return null;
            }
            int b = 0;
            System.Uri c;
            for (b = 0; b < a.Length; b++) {
                if(Uri.TryCreate(a[b], UriKind.RelativeOrAbsolute, out c)){
                    break;
                }
            }
            c = null;
            return a[b];
        }
    }
}

但是该代码无法正常工作。这个程序有什么问题?

4

2 回答 2

1

我会尝试添加a.ShowDialog();a.Show();添加到a.Activate();.

不确定您为什么使用Activate(),但请确保它按照您的意愿执行。 http://msdn.microsoft.com/en-us/library/system.windows.window.activate.aspx

于 2012-08-03T08:13:54.433 回答
0

使用 a.Show() 而不是 a.Activate(); 并确保您的处理程序已在 App.Xaml 中注册:

<Application 
    ...
    Startup="Application_Startup">
于 2012-08-03T08:18:34.750 回答