satocchiaブログ

satocchiaブログ

PR

×

キーワードサーチ

▼キーワード検索

プロフィール

satocchia

satocchia

カレンダー

お気に入りブログ

まだ登録されていません

コメント新着

tomoZo@ Re:Pale Moon日本語化トラブル(06/06) はじめまして。 28.16.0でまたもや提供さ…
satocchia @ Re[1]:Pale Moon日本語化トラブル(06/06) zui_9さんへ 本日、確認しました。ようや…
zui_9 @ Re:Pale Moon日本語化トラブル(06/06) 上記リンク「Githubのプロジェクト」の左…
わたなべ@ Re:powershellコンソール、見づらくありませんか?(08/26) 初めまして、この情報最高です! 背景を白…
y__@ Re:uwscでGUIフォーム(05/12) UWSC 仮掲示板から飛んできました。 HTAで…

フリーページ

2020.10.09
XML
カテゴリ: powershell
UWSCのFukidasi(Balloon)って結構便利だったりするんで、powershellでもつかえないかな。
使い方
表示する $fuki=show-balloon "文字列"
文言を変更 $fuki.setText("別の文字列")
フォントを変更 $fuki.setFont((new-object system.drawing.font("MS明朝",9))
フォントサイズだけ変更 $fuki.resizeFont(12)

UWSCだと同一スレッドに1つしかfukidasiを持てないけれど、これはいくつでもOK
その代わり、終了するときは明示的に $fuki.Close() が必要

中身

なので、移動するなら $fuki.location=@{x=200;y=500} みたいにすればいい。


balloon.ps1

function show-balloon( $text ){
    function new-winform( $name, $attribute=$null ){
        $res = iex "new-object System.Windows.Forms.$name"
        if ( $attribute ){
             $attribute.Keys|%{
                $res.$_=$attribute.$_
             }
        }
        return $res

    function asyncshow( $winform ){
        $rs =[Management.Automation.Runspaces.RunspaceFactory]::CreateRunspace()
        $rs.Open()
        $rs.SessionStateProxy.SetVariable("form",$winform)
        $p =$rs.CreatePipeline({[void]$form.ShowDialog()})

        $p.InvokeAsync()
    }
    $form=new-winform form -attrib @{
        backcolor="yellow";
        formborderstyle="none";
        opacity=0.7;
        topmost=$true
    }
    $label=new-winform label -attrib @{
        text=$text;
        textalign="MiddleCenter";
        parent=$form;
        dock="fill"
    }
    $form|add-member -MemberType ScriptMethod -Name setText -Value {
        param($text)
        $label = $this.Controls[0]
        $label.text=$text
    }
    $form|add-member -MemberType ScriptMethod -Name setComplimentaryColor -Value {
        $bcol=$this.backcolor
        $max=$bcol.r
        if ( $bcol.g -gt $max ){ $max=$bcol.g }
        if ( $bcol.b -gt $max ){ $max=$bcol.b }
        $min=$bcol.r
        if ( $bcol.g -lt $min ){ $min=$bcol.g }
        if ( $bcol.b -lt $min ){ $min=$bcol.b }
        $fcol=[drawing.color]::FromArgb( $max + $min - $bcol.r, $max + $min - $bcol.g, $max + $min - $bcol.b )
        $this.ForeColor=$fcol
    }
    $form|add-member -MemberType ScriptMethod -Name setFont -Value {
        param($font)
        $label = $this.Controls[0]
        if ( $font ){
            $label.font=$font
        } else {
            $label.font
        }
    }
    $form|add-member -MemberType ScriptMethod -Name resizeFont -Value {
        param($size)
        $label = $this.Controls[0]
        $font=$label.font
        $label.font=new-object drawing.font( $font.name, $size )
    }
    $label|add-member -MemberType NoteProperty -Name FormMinHeight -Value 40
    $redraw={
        $this.parent.width=$this.preferredSize.width + 10
        $height=$this.preferredSize.height + 10
        if ( $height -le $this.FormMinHeight ){
            $height = $this.FormMinHeight
        }
        $this.parent.height=$height
    }
    $label.add_textchanged($redraw)
    $label.add_fontchanged($redraw)
    $form.width=$label.preferredSize.width + 10
    $form.height=40
    asyncshow $form
    $form
}





お気に入りの記事を「いいね!」で応援しよう

最終更新日  2020.10.09 11:28:15
コメント(0) | コメントを書く
[powershell] カテゴリの最新記事


【毎日開催】
15記事にいいね!で1ポイント
10秒滞在
いいね! -- / --
おめでとうございます!
ミッションを達成しました。
※「ポイントを獲得する」ボタンを押すと広告が表示されます。
x
X

© Rakuten Group, Inc.
X
Design a Mobile Website
スマートフォン版を閲覧 | PC版を閲覧
Share by: