check colors to show circles
Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.Application]::EnableVisualStyles()
$sampleForm = New-Object System.Windows.Forms.Form
$sampleForm.Width = 500
$sampleForm.Height = 350
# Create three ListViewItems
$item1 = New-Object System.Windows.Forms.ListViewItem('Red')
$item1.SubItems.Add('#ff0000')
$item1.SubItems.Add('rgb(255, 0, 0)')
$item2 = New-Object System.Windows.Forms.ListViewItem('Green')
$item2.SubItems.Add('#00ff00')
$item2.SubItems.Add('rgb(0, 255, 0)')
$item3 = New-Object System.Windows.Forms.ListViewItem('Blue')
$item3.SubItems.Add('#0000ff')
$item3.SubItems.Add('rgb(0, 0, 255)')
# Create a ListView, set the view to 'Details' and add columns
$listView = New-Object System.Windows.Forms.ListView
$listView.View = 'Details'
$listView.Width = 450
$listView.Height = 120
$listView.Location = New-Object System.Drawing.Point(20, 20)
$listView.Columns.Add('Color', 120)
$listView.Columns.Add('Hex', 120)
$listView.Columns.Add('Rgb', 120)
# Display check boxes.
$listView.CheckBoxes = $true;
# Display grid lines.
$listView.GridLines = $true;
# Add items to the ListView
$listView.Items.AddRange(($item1, $item2, $item3))
$imageList = new-Object System.Windows.Forms.ImageList
$imageList.ImageSize = New-Object System.Drawing.Size(15, 15) # Size of the pictures
$bitm1 = [System.Drawing.Image]::FromFile("C:\Users\bob\Desktop\1.png")
$bitm2 = [System.Drawing.Image]::FromFile("C:\Users\bob\Desktop\2.png")
$bitm3 = [System.Drawing.Image]::FromFile("C:\Users\bob\Desktop\3.png")
$imageList.Images.Add("image1", $bitm1)
$imageList.Images.Add("image2", $bitm2)
$imageList.Images.Add("image3", $bitm3)
$listView.SmallImageList = $imageList
$item1.ImageIndex = 0
$item2.ImageIndex = 1
$item3.ImageIndex = 2
$formGraphics = $sampleForm.createGraphics()
# code or call to a function to perform graphics drawing
$RBrush = [System.Drawing.SolidBrush]::New([System.Drawing.Color]::FromArgb(100, 255, 0, 0))
$GBrush = [System.Drawing.SolidBrush]::New([System.Drawing.Color]::FromArgb(100, 0, 255, 0))
$BBrush = [System.Drawing.SolidBrush]::New([System.Drawing.Color]::FromArgb(100, 0, 0, 255))
$RRec = [System.Drawing.Rectangle]::New(178, 150, 100, 100)
$GRec = [System.Drawing.Rectangle]::New(150, 195, 100, 100)
$BRec = [System.Drawing.Rectangle]::New(206, 195, 100, 100)
$sampleForm.Controls.AddRange(@($listView))
$ListView.Add_ItemChecked( { listView_ItemChecked })
function listView_ItemChecked {
$sampleForm.add_paint(
{
if ($item1.Checked) { $formGraphics.FillEllipse($RBrush, $RRec) }
if ($item2.Checked) { $formGraphics.FillEllipse($GBrush, $GRec) }
if ($item3.Checked) { $formGraphics.FillEllipse($BBrush, $BRec) }
}
)
$sampleForm.refresh()
}
[void] $sampleForm.ShowDialog()
reference:
fill circle
No comments:
Post a Comment