小编Spa*_*pan的帖子

PowerShell脚本第一次失败但第二次失败

我找到了一个PowerShell脚本,可以更改我的Windows 7 PC桌面壁纸的图像文件,其路径作为参数提供.我想要的最终结果是在启动时通过批处理文件调用此脚本.

[CmdletBinding()]
Param(
   [Parameter(Position=0, Mandatory=$true, ValueFromPipelineByPropertyName=$true)]
   [Alias("FullName")]
   [string]
   $Path
,
   [Parameter(Position=1, Mandatory=$false)]
   $Style = "NoChange"
)

BEGIN {
try {
   $WP = [Wallpaper.Setter]
} catch {
   $WP = add-type @"
using System;
using System.Runtime.InteropServices;
using Microsoft.Win32;
namespace Wallpaper
{
public enum Style : int
{
     Tile, Center, Stretch, NoChange
}

public class Setter {
  public const int SetDesktopWallpaper = 20;
  public const int UpdateIniFile = 0x01;
  public const int SendWinIniChange = 0x02;

  [DllImport("user32.dll", SetLastError = true, …
Run Code Online (Sandbox Code Playgroud)

powershell scripting powershell-2.0

5
推荐指数
2
解决办法
2692
查看次数

触发事件后的类变量可用性

我是事件编程的新手,我显然误解了我正在尝试做的事情.

我有一个Windows窗体应用程序订阅来自另一个类的事件.Ť

//Class that provides event handler to Windows Forms application.
class Foo
{
  public string Value{get; set;}

  // Lots of other code

  public void OnEventFired(object sender, EventArgs e)
  {
     // Attempt to access variable Value here.
  }    
}
Run Code Online (Sandbox Code Playgroud)

从Windows窗体代码我首先Value在类中设置变量,Foo然后触发将执行OnEventFired上面代码的事件.

我所看到的是,当在事件处理程序中使用时,变量Value不包含在事件被触发之前设置的值(Value为空).

我知道我可以扩展EventArgs到包含变量数据,但我试图理解为什么我正在做的事情不起作用.

c# events scope event-handling winforms

0
推荐指数
1
解决办法
134
查看次数