PowerShell -Part 7 (615レス)
上下前次1-新
抽出解除 レス栞
419(1): デフォルトの名無しさん [sage] 03/07(金)23:19 ID:6K+ignj1(1)
Add_Clickに渡したスクリプトブロックが実行されるのはボタンクリック時。
その時にはもうsetSelectButtonを抜けてるから、setSelectButton実行時に渡した$folderTypeはもう見えない。
最後の手段的なglobalスコープの使用を避けて手っ取り早く解決するなら、
{〜〜〜}.GetNewClosure()でsetSelectButton実行中の変数スコープを記憶(?)したうえで
自前のクラスとかハッシュテーブル等で入出力しちゃう。とか。適当実装だとこんな。
function setSelectButton($def){
$conf = New-Object System.Windows.Forms.Button
$conf.Location = New-Object System.Drawing.Point($def.xAxis,$def.yAxis)
$conf.Size = New-Object System.Drawing.Size($def.xSize, $def.ySize)
$conf.Text = "Select"
$conf.Add_Click({
$dialog_FolderSelection = New-Object Windows.Forms.FolderBrowserDialog
if($dialog_FolderSelection.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK){
$def.textBox.Text = $dialog_FolderSelection.SelectedPath
}
}.GetNewClosure())
return $conf
}
(略)
$inputDef = [Ordered] @{xAxis = 370; yAxis = 50; xSize = 70; ySize = 20; textBox = $textBox_inputFolder;}
$outputDef = [Ordered] @{xAxis = 370; yAxis = 70; xSize = 70; ySize = 20; textBox = $textBox_outputFolder;}
# create Select button
$button_Select_inputFolder = setSelectButton $inputDef
$button_Select_outputFolder = setSelectButton $outputDef
(略)
if([String]::IsNullOrEmpty($inputDef.textBox.Text)){ # show a message dialog if no file is selected
※これで入力欄にフォルダパスをコピペする人(=私)も安心
421: デフォルトの名無しさん [] 03/09(日)07:42 ID:RXTu5Tqn(1)
>>419
ありがとうございます!
setSelectButton実行時に渡した$folderTypeはもう見えないんですね。
上下前次1-新書関写板覧索設栞歴
スレ情報 赤レス抽出 画像レス抽出 歴の未読スレ AAサムネイル
ぬこの手 ぬこTOP 0.037s