Перейти из форума на сайт.

НовостиФайловые архивы
ПоискАктивные темыТоп лист
ПравилаКто в on-line?
Вход Забыли пароль? Первый раз на этом сайте? Регистрация
Компьютерный форум Ru.Board » Операционные системы » Microsoft Windows » PowerShell

Модерирует : KLASS, IFkO

KLASS (06-03-2018 00:43): Объединение тем по сценариям: Сценарии Windows
 Версия для печати • ПодписатьсяДобавить в закладки
На первую страницук этому сообщениюк последнему сообщению

   

sysprg2e

Newbie
Редактировать | Профиль | Сообщение | Цитировать | Сообщить модератору
Простая XAML-форма для отображения пар (Имя, Значение). Основное назначение - создание popup-окна для отображения детальных свойств объекта, кликнутого в основной форме, отображающей лишь часть свойств для каждого из объектов в коллекции.  
[more]
Код:
 
<#
---------------------------------------------------------------------  
 Project: Properties Presentation                                                
 Version: 1.0                                                          
 FileId:  e:\Delme\BuildsHistory\NameValueForm.ps1                        
 When:    13-Mar-2017 20:23                            
 ©        Oleg Kulikov, sysprg@live.ru                                
---------------------------------------------------------------------
#>
$style =  
[System.Collections.Hashtable]@{
   ColorScheme       = "Black";
   LabelWidth        = "105";
   MarginLeft        = "5";
   TextWidth         = "320";
   RowHeight         = "30";
   ButtonFontSize    = "20";
   FormFontSize      = "14";
   LongLinesFontSize = "10";
};
 
Set-Variable -Name DefaultStyle -Scope Script -Value $style;
 
############################ GUI Presentaion code starts ################################
 
Add-Type -AssemblyName "PresentationFramework"                                                                                                                                              
 
<#
---------------------------------------------------------------------------------
Function receives:
[string[]]$Names  - an array of the properties names  to be placed into the Form
[string[]]$Values - an array of the properties values to be placed into the Form
[string[]]$Titles - an array of the labels of the header and trailer rows  
[PSObject]$Style  - Style object which defines Geometry and colors of the form
Function returns [xml] $xaml - Form presentation XML
---------------------------------------------------------------------------------
#>
function ShowForm
{
   param(
      [string[]]$Names,
      [string[]]$Values,
      [string[]]$Titles,
      [PSObject]$Style = $DefaultStyle
   );
 
   $Colors = @{
      Black = @{ Dark='#FF2F4F4F'; Light='#FFD3D3D3'; Half='#FF778899'; Body='#FFDCDCDC' };
      Brown = @{ Dark="#FF8B4516"; Light="#FFFFE4C4"; Half="#FFCD853F"; Body="#FFF5DEB3" };  
      Green = @{ Dark="#FF006400"; Light="#FF90EF90"; Half="#FF00B300"; Body="#FF98FB98" };
      Blue  = @{ Dark="#FF0000CD"; Light="#FFADD8D6"; Half="#FF6495ED"; Body="#FF8FCEFA" };  
   };
 
   $Scheme = $Style.ColorScheme;
   $TopTitle = $Titles[0];
   $BotTitle = $Titles[1];
 
   $dark  = $Colors.$Scheme.Dark;  
   $half  = $Colors.$Scheme.Half;  
   $light = $Colors.$Scheme.Light;  
   $body  = $Colors.$Scheme.Body;  
 
   $LabelWidth   = $Style.LabelWidth;     # "105"
   $MarginLeft   = $Style.MarginLeft;     # "5"
   $TextWidth    = $Style.TextWidth;      # "320"
   $TextLeft     = ([int]$MarginLeft + [int]$LabelWidth + [int]$MarginLeft).ToString();
   $RowHeight    = $Style.RowHeight;      # "30"
   $ButtonHeight = $ButtonWidth = $RowHeight; # 30
   $FullHight    = [int]$MarginLeft + [int]$RowHeight;# 5 + 30
   $btnFSZ       = $Style.ButtonFontSize; # "20";
   $winFSZ       = $Style.FormFontSize;   # "14";
   
   $LabelPattern = @"
<Label Margin="$MarginLeft,%w,0,0" Content="%nv" Name="lbl%n"  
Background="$half" Foreground="#FFFFFFFF"
VerticalAlignment="Top" HorizontalAlignment="Left"  
Width="$LabelWidth" Height="$RowHeight"
/>
"@;
   $TextPattern  = @"
<TextBox Margin="$TextLeft,%w,0,0" Name="txt%n" Padding="2,4,0,0"  
Background="$light" Text="%text"
VerticalAlignment="Top" HorizontalAlignment="Left"  
Width="$TextWidth" Height="$RowHeight"
/>
"@;
 
   $OffsetTop = $FullHight;#35;
   $labels    = "";
   $text      = "";
 
   for ( $i = 0; $i -lt $Names.Length; $i++ )
   {
      $n = $Names[$i]; $nv = $n.Replace( "_comma_", ", " );
      $w = $OffsetTop.ToString().PadLeft( 3, "0" );
      $labels += $LabelPattern.Replace("%nv", "$nv").Replace( "%n", "$n" ).Replace( "%w", "$w" );
      $tp = $TextPattern.Replace( "%n", "$n" ).Replace( "%w", "$w" ).Replace( "%text",$Values[$i] );
      $text   += $tp;
      $OffsetTop += $FullHight;
   }
 
   $FormWidth  = (3*([int]$MarginLeft)+[int]$LabelWidth+[int]$TextWidth).ToString();
   $FormHeight = ($OffsetTop + $FullHight - $MarginLeft).ToString();
   $ButtonOffsetLeft = ([int]$FormWidth - [int]$ButtonWidth).ToString();
   $stretch    = "UltraCondensed";
 
   $xaml = ([xml]@"                                                                            
<?xml version="1.0" encoding="UTF-8"?>                                                                                                      
<!-- XAML Code - Imported from Visual Studio Express WPF Application -->                                                                    
<Window                                                                                                                                      
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"                                                                        
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"                                                                                  
    ResizeMode="NoResize" WindowStyle="None" BorderThickness="1"                                                                            
    Background="$body" WindowStartupLocation="CenterScreen"                                                                              
    SizeToContent="Width" Height="$FormHeight" Title="$TopTitle"                                                                                    
    Topmost="False" FontSize="$winFSZ" FontStretch="$stretch">                                                                                                          
                                                                                                                                             
    <Grid Margin="0,0,0,0">                                                                                                                  
        <Label                                                                                                                              
            Width="$FormWidth" Height="$RowHeight" Margin="0,0,0,0"                                                                                      
            VerticalAlignment="Top" HorizontalAlignment="Center"                                                                            
            HorizontalContentAlignment="Center" Content="$TopTitle"
            Background="$dark" Foreground="#FFFFFFFF"                                                          
            FontWeight="Bold" Name="Header"                                                                                            
        />                                                                                                                                  
        <Button                                                                                                                              
            Width="$RowHeight" Height="$RowHeight" Margin="$ButtonOffsetLeft,0,0,0" BorderThickness="0"                                                                    
            VerticalAlignment="Top" HorizontalAlignment="Left"                                                                              
            Foreground="White" Background="#FFC35A50"                                                                                        
            FontWeight="Bold" FontSize="$btnFSZ" Content="X"                                                                                      
            Cursor="Hand" ToolTip="Close Window" Name="btnExit"                                                                              
        />  
$labels
$text  
        <Label                                                                                                                              
            Width="$FormWidth" Height="$RowHeight" Margin="0,$OffsetTop,0,0"                                                                                      
            VerticalAlignment="Top" HorizontalAlignment="Center"                                                                            
            HorizontalContentAlignment="Center" Content="$BotTitle"
            Background="$dark" Foreground="#FFFFFFFF"                                                          
            Name="Footer"                                                                                          
        />                  
    </Grid>                                                                                                                                  
</Window>                                                                                                                                    
"@); # FontWeight="Bold"  
 
#####################  Preparing Form to Show ####################################
 
    $syncHash = [Hashtable]::Synchronized(@{});                                                                                              
    $rsHash   = [Hashtable]::Synchronized(@{});                                                                                              
    $rsHash.Runspace = [RunspaceFactory]::CreateRunspace();                                                                                
    $rsHash.Runspace.ApartmentState, $rsHash.Runspace.ThreadOptions = 'STA','ReuseThread'                                                  
    $rsHash.Runspace.Open();                                                                                                                
    $rsHash.Runspace.SessionStateProxy.SetVariable( "syncHash",$syncHash );                                                                  
    $rsHash.Runspace.SessionStateProxy.SetVariable( "rsHash", $rsHash );                                                                      
    $syncHash.xaml = $xaml;
    $rform = $null;                                                                                                        
 
    $psCmd = [PowerShell]::Create().AddScript(
    {                                                                                                                      
        $reader = New-Object -TypeName Xml.XmlNodeReader -ArgumentList $syncHash.xaml;                                                      
        $Form   = [Windows.Markup.XamlReader]::Load($reader);
        $rform  = $Form;                                                                                                                
        $Form.Add_Closed(
           {                                                                                                                
              $rshash.PowerShell.Dispose();                                                                                                                                          
              [GC]::Collect();                                                                                                                
              [GC]::WaitForPendingFinalizers();                                                                                              
           }
        );  
 
        $lblMain = $Form.FindName('Header');                                                
        $eventHandler_LeftButtonDown = [Windows.Input.MouseButtonEventHandler]{ $Form.DragMove() };                                        
        $lblMain.add_MouseLeftButtonDown($eventHandler_LeftButtonDown);
                                                                                                                               
        $btnExit = $Form.FindName('btnExit');                                                                                                        
        $btnExit.add_Click({ $Form.Close() });                                                                                              
                                                                                                                                                                                                       
        $Form.ShowDialog();
                                                                                                             
    });# End-of-$psCmd = [PowerShell]::Create().AddScript(                                                                                                                                    
                                                                                                                                           
    $psCmd.Runspace = $rsHash.Runspace;                                                                                                    
    [void]$psCmd.BeginInvoke();                                                                                                            
    return $rform;
}
https://1drv.ms/i/s!Alc6r9K6meXyhfkDdJW3Zsii7umZzw
 


Всего записей: 4 | Зарегистр. 16-12-2017 | Отправлено: 20:12 24-12-2017 | Исправлено: sysprg2e, 20:17 24-12-2017
   

На первую страницук этому сообщениюк последнему сообщению

Компьютерный форум Ru.Board » Операционные системы » Microsoft Windows » PowerShell
KLASS (06-03-2018 00:43): Объединение тем по сценариям: Сценарии Windows


Реклама на форуме Ru.Board.

Powered by Ikonboard "v2.1.7b" © 2000 Ikonboard.com
Modified by Ru.B0ard
© Ru.B0ard 2000-2024

BitCoin: 1NGG1chHtUvrtEqjeerQCKDMUi6S6CG4iC

Рейтинг.ru