我找到了一个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) 我是事件编程的新手,我显然误解了我正在尝试做的事情.
我有一个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
到包含变量数据,但我试图理解为什么我正在做的事情不起作用.