【问题标题】:Button don't open program按钮不打开程序
【发布时间】:2023-03-05 09:05:01
【问题描述】:
        private void discord_click(object sender, RoutedEventArgs e)
        {
            WindowState = WindowState.Minimized;
            Process objProcess = new Process();
            objProcess.StartInfo.FileName = "Update.exe.lnk";
            objProcess.StartInfo.Arguments = @"C:\Users\Darksli\Desktop\folders\MainApp\MainApp\MainApp\bin\Debug\links\";
            objProcess.Start();
        }

如果我按下按钮,我会看到错误“找不到此文件”

【问题讨论】:

  • 也许您需要设置 WorkingDirectory 属性而不是 Arguments one
  • 无论如何都不起作用
  • 尝试提供完整路径作为文件名。另外:尝试添加objProcess.UseShellExecute = true; - 请参阅stackoverflow.com/questions/6141821/…
  • 无结果...

标签: c# wpf xcode


【解决方案1】:

您可以尝试参考以下步骤,看看它是否适合您。 项目A:

MainWindow.xaml:

<Grid>
    <Button Click="Button_Click" Width="100" Height="40" Content="click"/>
</Grid>

MainWindow.xaml.cs:

using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows;

namespace ClickButtonToOpenProgram
{
  public partial class MainWindow : Window
  {
    public MainWindow()
    {
      InitializeComponent();
    }

    private void Button_Click(object sender, RoutedEventArgs e)
    {
      Process p = Process.Start("BackgroundOfCanvas");
      p.WaitForInputIdle();
      SetParent(p.MainWindowHandle, Process.GetCurrentProcess().MainWindowHandle);
    }

    [DllImport("user32.dll")]
    static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
  }
}

项目 B:

<Canvas Opacity="0.9">
     <Path Fill="Black" Data="M0,0 L1000,0 1000,1000 0,1000Z M100,100 L200,100 200,200 100,200Z"/>
     <Rectangle Fill="LightGreen" Height="100" Width="100" Margin="200"/>
     <TextBlock Text="hello" Background="AliceBlue" Height="40" Width="100" />
</Canvas>

右击Project A的Reference,选择Add Reference...,然后勾选Project B。最后点击Ok。

The result

【讨论】:

  • 嗨,@ Darksli。这个问题有更新吗?你有时间检查我的答案是否适合你吗?
猜你喜欢
  • 2016-03-21
  • 1970-01-01
  • 2019-09-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-12-03
  • 1970-01-01
相关资源
最近更新 更多