【问题标题】:How can I open a window first, instead of a MainWindow in WPF (C#)如何首先打开一个窗口,而不是 WPF 中的 MainWindow(C#)
【发布时间】:2020-09-01 02:43:26
【问题描述】:

所以,当我点击开始调试时,它显示的是我的主窗口而不是另一个窗口,这是我想要测试的。

这是主窗口代码。

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Xml;
using EasyExploits;
using System.Windows.Forms;
using System.Diagnostics;
using System.Net;
using System.Threading;
using System.Linq.Expressions;
using MeguSploit;

namespace Exploit_Template
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {

        Module m = new Module();

        public MainWindow()
        {
            InitializeComponent();
        }

        private void Window_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (e.ChangedButton == MouseButton.Left)
                this.DragMove();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            using (StreamReader s = new StreamReader("./Bin/Languages/Lua.xshd"))
            {
                using (XmlTextReader reader = new XmlTextReader(s))
                {
                    TextEditor.SyntaxHighlighting = ICSharpCode.AvalonEdit.Highlighting.Xshd.HighlightingLoader.Load(reader, HighlightingManager.Instance);
                }
            }

            DirectoryInfo di = new DirectoryInfo("./Scripts");
            FileInfo[] f = di.GetFiles("*.txt");
            foreach (FileInfo fi in f)
            {
                ListBox.Items.Add(fi.Name);
            }

            DirectoryInfo din = new DirectoryInfo("./Scripts");
            FileInfo[] file = din.GetFiles("*.lua");
            foreach (FileInfo fil in file)
            {
                ListBox.Items.Add(fil.Name);
            }
        }

        private void Exit_Click(object sender, RoutedEventArgs e)
        {
            System.Windows.Application.Current.Shutdown();
        }

        private void Minimize_Click(object sender, RoutedEventArgs e)
        {
            WindowState = WindowState.Minimized;
        }

        private void Load_Click(object sender, RoutedEventArgs e)
        {
            if (ListBox.SelectedIndex != -1)
            {
                TextEditor.Text = File.ReadAllText($"./Scripts/{ListBox.SelectedItem}");
            }
        }

        private void Refresh_Click(object sender, RoutedEventArgs e)
        {
            ListBox.Items.Clear();

            DirectoryInfo di = new DirectoryInfo("./Scripts");
            FileInfo[] f = di.GetFiles("*.txt");
            foreach (FileInfo fi in f)
            {
                ListBox.Items.Add(fi.Name);
            }

            DirectoryInfo din = new DirectoryInfo("./Scripts");
            FileInfo[] file = din.GetFiles("*.lua");
            foreach (FileInfo fil in file)
            {
                ListBox.Items.Add(fil.Name);
            }
        }

        private void ExecuteL_Click(object sender, RoutedEventArgs e)
        {
            if (ListBox.SelectedIndex != -1)
            {
                m.ExecuteScript(File.ReadAllText($"./Scripts/{ListBox.SelectedItem}"));
            }
        }

        private void Execute_Click(object sender, RoutedEventArgs e)
        {
            m.ExecuteScript(TextEditor.Text);
            Status.Content = "Executed!";
        }

        private void Clear_Click(object sender, RoutedEventArgs e)
        {
            TextEditor.Text = "";
            Status.Content = "Ready!";
        }

        private void OpenFile_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "Txt Files (*.txt)|*.txt|Lua Files (*.lua)|*.lua";
            if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                TextEditor.Text = File.ReadAllText(ofd.FileName);
            }
        }

        private void ExecuteFile_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog ef = new OpenFileDialog();
            ef.Filter = "Txt Files (*.txt)|*.txt|Lua Files (*.lua)|*.lua";
            if (ef.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                m.ExecuteScript(ef.FileName);
            }
        }

        private void SaveFile_Click(object sender, RoutedEventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog();
            sfd.Filter = "Txt Files (*.txt)|*.txt|Lua Files (*.lua)|*.lua";
            if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                File.WriteAllText(sfd.FileName, TextEditor.Text);
            }
        }

        private void Attach_Click(object sender, RoutedEventArgs e)
        {
            m.LaunchExploit();
            Status.Content = "Injected!";
        } 

        private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {

        }

    }
}

这是我想首先启动的窗口。

using Exploit_Template;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace MeguSploit
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
        }


        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            Process.Start("https://shrinkme.io/BWe0");
        }

        private void Button_Click_3(object sender, RoutedEventArgs e)
        {
            if (Pass.Text == new WebClient().DownloadString("https://pastebin.com/raw/VTGJqX6k") || Pass.Text == "stefanradu2005eadminsiesmekrau")
            {
                MessageBox.Show("Thank you for using MeguSploit");
                this.Hide();
                MainWindow main = new MainWindow();
                main.Show();

            }
            else
            {
                MessageBox.Show("Sorry the key is invalid", "Key Invalid");
            }
        }

        private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (e.ChangedButton == MouseButton.Left)
                this.DragMove();
        }
    }
}

我真的需要帮助,我是编程界的新手。提前致谢。我也不想从头开始,因为我会浪费很多时间。这将是最后的选择。

【问题讨论】:

  • 更改 Application.Run(new MainWindow ());在 program.cs 中的表单
  • @mehdifarhadi 这应该是一个答案,而不是评论;)
  • @mehdifarhadi 实际上他在 WPF 应用程序中而不是在 winform 中,因此对于入口点,他应该使用 App.g.cs 但更容易在 App.xaml 中更改 StartupUri

标签: c# .net wpf windows visual-studio


【解决方案1】:

将 App.xaml 中的 StartupUri 从 MainWindow.xaml 更改为 Window1.xaml

<Application x:Class="MyApp.App"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:local="clr-namespace:MyApp"
         StartupUri="MainWindow.xaml">

</Application>

另见相对documentation

【讨论】:

    【解决方案2】:

    假设您使用的是 Visual Studio 2015-2019:默认情况下,用于创建 WPF 应用程序的模板在 App.xaml 中指定 StartupUri。将其更改为您的 Window 文件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多