Powershell DataGridView Buttons anpassen überschreiben
Hi PS Guru's,
ich bin wieder beim DataGridView hängen geblieben.
In einigen Spalten habe ich Buttons eingefügt.
Nun wollte ich auf den Buttons Bilder einfügen(Pfeil hoch, Pfeil runter, Pfeil nach rechts).
Bisher aber ohne Erfolg. Mit Querlesen bin ich bisher nur auf C# Sourcen gestoßen.
Wie man allerdings die Buttons mit der Powershell überschreibt hab ich noch nichts gefunden.
Hat einer von euch einen Tipp? Denn nur graue Buttons sehen doof aus.
Gruß
ich bin wieder beim DataGridView hängen geblieben.
In einigen Spalten habe ich Buttons eingefügt.
Nun wollte ich auf den Buttons Bilder einfügen(Pfeil hoch, Pfeil runter, Pfeil nach rechts).
Bisher aber ohne Erfolg. Mit Querlesen bin ich bisher nur auf C# Sourcen gestoßen.
Wie man allerdings die Buttons mit der Powershell überschreibt hab ich noch nichts gefunden.
Hat einer von euch einen Tipp? Denn nur graue Buttons sehen doof aus.
Gruß
Please also mark the comments that contributed to the solution of the article
Content-Key: 284275
Url: https://administrator.de/contentid/284275
Printed on: May 5, 2024 at 04:05 o'clock
4 Comments
Latest comment
Hallo Heim###er,
dazu musst du das OnPaint-Ereignis benutzen, da eine Button-Column nativ keine Bilder unterstützt. Du musst damit also das Bild über den Button zeichnen.
Hier ein Beispiel, das das Icon eines Programms als Quelle nutzt (Um ein anderes normales Bild aus dem Dateisystem zu benutzen, nimmst du stattdessen die auskommentierte Zeile 18):
Grüße Uwe
dazu musst du das OnPaint-Ereignis benutzen, da eine Button-Column nativ keine Bilder unterstützt. Du musst damit also das Bild über den Button zeichnen.
Hier ein Beispiel, das das Icon eines Programms als Quelle nutzt (Um ein anderes normales Bild aus dem Dateisystem zu benutzen, nimmst du stattdessen die auskommentierte Zeile 18):
function GenerateForm {
#region Import the Assemblies
[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
[reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
#endregion
#region Form Objects
$form1 = New-Object System.Windows.Forms.Form
$dgv = New-Object System.Windows.Forms.DataGridView
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
#endregion Form Objects
$handler_dgv_CellPainting =
{
if ($_.ColumnIndex -eq 0 -and $_.RowIndex -eq 0){
$_.Paint($_.CellBounds,[System.Windows.Forms.DataGridViewPaintParts]::All)
# [System.Drawing.Image]$img = [System.Drawing.Image]::FromFile("C:\Ordner\bild.png")
$img = [System.Drawing.Icon]::ExtractAssociatedIcon('C:\windows\system32\taskmgr.exe')
$_.Graphics.DrawImage($img,$_.CellBounds.Left + 5,$_.CellBounds.Top + 2,16,16)
$_.Handled = $true
}
}
$handler_form1_Load=
{
$dgv.Rows.Cells.Value = "Klick mich"
}
$handler_dataGridView1_CellContentClick=
{
}
$OnLoadForm_StateCorrection=
{#Correct the initial state of the form to prevent the .Net maximized form issue
$form1.WindowState = $InitialFormWindowState
}
#----------------------------------------------
#region Form Code
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 192
$System_Drawing_Size.Width = 316
$form1.ClientSize = $System_Drawing_Size
$form1.DataBindings.DefaultDataSourceUpdateMode = 0
$form1.Name = "form1"
$form1.Text = "Image on DataGridView Button"
$form1.add_Load($handler_form1_Load)
$System_Windows_Forms_DataGridViewButtonColumn_4 = New-Object System.Windows.Forms.DataGridViewButtonColumn
$System_Windows_Forms_DataGridViewButtonColumn_4.HeaderText = "Button Spalte"
$System_Windows_Forms_DataGridViewButtonColumn_4.Name = ""
$System_Windows_Forms_DataGridViewButtonColumn_4.Width = 100
$dgv.Columns.Add($System_Windows_Forms_DataGridViewButtonColumn_4)|Out-Null
$dgv.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 12
$System_Drawing_Point.Y = 12
$dgv.Location = $System_Drawing_Point
$dgv.Name = "dgv"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 163
$System_Drawing_Size.Width = 288
$dgv.Size = $System_Drawing_Size
$dgv.TabIndex = 0
$dgv.add_CellPainting($handler_dgv_CellPainting)
$dgv.add_CellContentClick($handler_dataGridView1_CellContentClick)
$form1.Controls.Add($dgv)
#endregion Form Code
#Save the initial state of the form
$InitialFormWindowState = $form1.WindowState
#Init the OnLoad event to correct the initial state of the form
$form1.add_Load($OnLoadForm_StateCorrection)
#Show the Form
$form1.ShowDialog()| Out-Null
} #End Function
GenerateForm