Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# { 进程外壳=新进程(); shell.StartInfo=newprocessstartinfo(“cmd.exe”, String.Format(@“/K psexec.exe\\{0}-u{1}-p{2}cmd.exe”,system.IpAddre_C#_Generics_Events - Fatal编程技术网

C# { 进程外壳=新进程(); shell.StartInfo=newprocessstartinfo(“cmd.exe”, String.Format(@“/K psexec.exe\\{0}-u{1}-p{2}cmd.exe”,system.IpAddre

C# { 进程外壳=新进程(); shell.StartInfo=newprocessstartinfo(“cmd.exe”, String.Format(@“/K psexec.exe\\{0}-u{1}-p{2}cmd.exe”,system.IpAddre,c#,generics,events,C#,Generics,Events,{ 进程外壳=新进程(); shell.StartInfo=newprocessstartinfo(“cmd.exe”, String.Format(@“/K psexec.exe\\{0}-u{1}-p{2}cmd.exe”,system.IpAddress,CurrentSelectedSite.RemoteAccess.UserName,CurrentSelectedSite.RemoteAccess.DecryptedPassword)); shell.StartInfo.WindowS

{ 进程外壳=新进程(); shell.StartInfo=newprocessstartinfo(“cmd.exe”, String.Format(@“/K psexec.exe\\{0}-u{1}-p{2}cmd.exe”,system.IpAddress,CurrentSelectedSite.RemoteAccess.UserName,CurrentSelectedSite.RemoteAccess.DecryptedPassword)); shell.StartInfo.WindowStyle=ProcessWindowStyle.Normal; shell.StartInfo.UseShellExecute=true; shell.Start(); } 此。控制。删除(p.Parent); p、 Parent.Dispose(); this.SearchPanel.BringToFront(); }; }
完全不确定您试图在这里处理事件的内容。您的每个面板上都有SystemsListbox或同等产品吗?@Noldrin,没有,但我在SystemViewPanel上有,我在ShellButton\u单击中使用了SystemViewPanel。我知道SystemViewPanel有一个SystemsListBox。其他面板显示一些不同类型的图表或配置数据(SystemStatPanel、SystemConfigPanel)Hmmm,仍然不太清楚您的目标。你能解释一下你认为事情可以概括/抽象到什么地方(至少口头上/用伪代码)吗?根本不知道你想用这里的事件做什么。你的每个面板上都有SystemsListbox或类似的吗?@Noldrin,没有,但我在SystemViewPanel上有,我在ShellButton\u点击中使用了它。我知道SystemViewPanel有一个SystemsListBox。其他面板显示一些不同类型的图表或配置数据(SystemStatPanel、SystemConfigPanel)Hmmm,仍然不太清楚您的目标。你能解释一下你认为事物可以在哪里被概括/抽象(至少口头上/用伪代码)?好的,我明白你的意思了。我会传递什么样的论点(我对Func类型的论点还不是很在行)。@Frank,我发布了我自己的答案,但你的意见给了我这个想法。自由地让所谓的民主来决定这是否是一个可接受的方法。好的,我知道你要去哪里。我会传递什么样的论点(我对Func类型的论点还不是很在行)。@Frank,我发布了我自己的答案,但你的意见给了我这个想法。自由地让所谓的民主决定这是否是一种可接受的方法。
private static T ShowPanel<T>(Control parent, params object[] parameters) where T: Panel
{
    T panelToShow = (T)Activator.CreateInstance(typeof(T), parameters);

    parent.Controls.Add(panelToShow);

    panelToShow.Dock = DockStyle.Fill;
    panelToShow.BringToFront();
    panelToShow.Show();

    return panelToShow;
}
private void ShellButton_Click(object sender, EventArgs e)
{
    if (CurrentSelectedSite == null)
    {
        AlertSelectSite();
        return;
    }

    SystemViewPanel panel = ShowPanel<SystemViewPanel>(this, CurrentSelectedSite.Systems);

    panel.SystemsListbox.DoubleClick += new EventHandler(ShellAccessSystemSelected);
}
SystemViewPanel panel = ShowPanel<SystemViewPanel>(
  this, 
  panel => {
    //Do the stuff you would do on click event, panel impl ensures this 
    // gets called at the right moment
  },
  CurrentSelectedSite.Systems);
(sender, args) => //Do stuff
private void ShellButton_Click(object sender, EventArgs e)
{
    if (CurrentSelectedSite == null)
    {
        AlertSelectSite();
        return;
    }

    SystemViewPanel systemSelectPanel = ShowPanel<SystemViewPanel>(this, CurrentSelectedSite.Systems);

    /*
    I decided that this since this panel is used quickly, I'd rather 
    keep the flow of what's happening in the same place. The line
    above shows the panel, a double click later, and I'm back to doing
    what the ShellButton does. 

    I've exposed a SystemSelected event, which just wraps the panel's 
    SystemsListBox.DoubleClick event.*/


    systemSelectPanel.SystemSelected += delegate(object s, EventArgs eArgs)
    {
        ListBox p = (ListBox)s;
        System system = (System)p.SelectedItem;

        if (system != null)
        {
            Process shell = new Process();
            shell.StartInfo = new ProcessStartInfo("cmd.exe",
            String.Format(@"/K psexec.exe \\{0} -u {1} -p {2} cmd.exe", system.IpAddress, CurrentSelectedSite.RemoteAccess.UserName, CurrentSelectedSite.RemoteAccess.DecryptedPassword));
            shell.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
            shell.StartInfo.UseShellExecute = true;


            shell.Start();
        }

        this.Controls.Remove(p.Parent);
        p.Parent.Dispose();
        this.SearchPanel.BringToFront();
    };
}