Malnutrition
Разработчик
- Сообщения
- 401
- Реакции
- 59
Код:
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
# Create the main form
$form = New-Object System.Windows.Forms.Form
$form.Text = 'Advanced Text Modifier'
$form.Size = New-Object System.Drawing.Size(500, 450)
$form.StartPosition = 'CenterScreen'
# Create input TextBox
$inputTextBox = New-Object System.Windows.Forms.TextBox
$inputTextBox.Location = New-Object System.Drawing.Point(10, 10)
$inputTextBox.Size = New-Object System.Drawing.Size(460, 100)
$inputTextBox.Multiline = $true
$inputTextBox.ScrollBars = 'Vertical'
# Create prefix TextBox
$prefixLabel = New-Object System.Windows.Forms.Label
$prefixLabel.Location = New-Object System.Drawing.Point(10, 120)
$prefixLabel.Size = New-Object System.Drawing.Size(100, 20)
$prefixLabel.Text = 'Prefix:'
$prefixTextBox = New-Object System.Windows.Forms.TextBox
$prefixTextBox.Location = New-Object System.Drawing.Point(10, 140)
$prefixTextBox.Size = New-Object System.Drawing.Size(200, 20)
# Create suffix TextBox
$suffixLabel = New-Object System.Windows.Forms.Label
$suffixLabel.Location = New-Object System.Drawing.Point(220, 120)
$suffixLabel.Size = New-Object System.Drawing.Size(100, 20)
$suffixLabel.Text = 'Suffix:'
$suffixTextBox = New-Object System.Windows.Forms.TextBox
$suffixTextBox.Location = New-Object System.Drawing.Point(220, 140)
$suffixTextBox.Size = New-Object System.Drawing.Size(200, 20)
# Create output TextBox
$outputTextBox = New-Object System.Windows.Forms.TextBox
$outputTextBox.Location = New-Object System.Drawing.Point(10, 170)
$outputTextBox.Size = New-Object System.Drawing.Size(460, 150)
$outputTextBox.Multiline = $true
$outputTextBox.ScrollBars = 'Vertical'
$outputTextBox.ReadOnly = $true
# Create radio buttons for modification type
$radioPanel = New-Object System.Windows.Forms.Panel
$radioPanel.Location = New-Object System.Drawing.Point(10, 330)
$radioPanel.Size = New-Object System.Drawing.Size(460, 50)
$radioOriginal = New-Object System.Windows.Forms.RadioButton
$radioOriginal.Location = New-Object System.Drawing.Point(10, 10)
$radioOriginal.Size = New-Object System.Drawing.Size(150, 20)
$radioOriginal.Text = 'Keep Original'
$radioOriginal.Checked = $true
$radioModified = New-Object System.Windows.Forms.RadioButton
$radioModified.Location = New-Object System.Drawing.Point(170, 10)
$radioModified.Size = New-Object System.Drawing.Size(150, 20)
$radioModified.Text = 'Modified Only'
$radioBoth = New-Object System.Windows.Forms.RadioButton
$radioBoth.Location = New-Object System.Drawing.Point(330, 10)
$radioBoth.Size = New-Object System.Drawing.Size(150, 20)
$radioBoth.Text = 'Both'
# Create Modify button
$modifyButton = New-Object System.Windows.Forms.Button
$modifyButton.Location = New-Object System.Drawing.Point(10, 390)
$modifyButton.Size = New-Object System.Drawing.Size(100, 30)
$modifyButton.Text = 'Modify Text'
# Create Save button
$saveButton = New-Object System.Windows.Forms.Button
$saveButton.Location = New-Object System.Drawing.Point(120, 390)
$saveButton.Size = New-Object System.Drawing.Size(100, 30)
$saveButton.Text = 'Save to File'
# Button click event for modification
$modifyButton.Add_Click({
# Get input lines
$inputLines = $inputTextBox.Text -split "`r`n"
# Get prefix and suffix
$prefix = $prefixTextBox.Text
$suffix = $suffixTextBox.Text
# Process lines based on radio button selection
$modifiedLines = @()
foreach ($line in $inputLines) {
if ($line.Trim() -ne '') {
# Original line with quotes and comma
$originalLine = '"' + $line + '",'
# Modified line with prefix and suffix
$modifiedLine = '"' + $prefix + $line + $suffix + '",'
# Add lines based on radio button selection
switch ($true) {
$radioOriginal.Checked { $modifiedLines += $originalLine }
$radioModified.Checked { $modifiedLines += $modifiedLine }
$radioBoth.Checked {
$modifiedLines += $originalLine
$modifiedLines += $modifiedLine
}
}
}
}
# Join modified lines and display in output
$outputTextBox.Text = $modifiedLines -join "`r`n"
})
# Button click event for saving
$saveButton.Add_Click({
$desktopPath = [Environment]::GetFolderPath('Desktop')
$outputTextBox.Text | Out-File -FilePath "$desktopPath\modified.txt"
[System.Windows.Forms.MessageBox]::Show('File saved to Desktop as modified.txt', 'Save Successful')
})
# Add controls to form
$form.Controls.Add($inputTextBox)
$form.Controls.Add($prefixLabel)
$form.Controls.Add($prefixTextBox)
$form.Controls.Add($suffixLabel)
$form.Controls.Add($suffixTextBox)
$form.Controls.Add($outputTextBox)
$form.Controls.Add($radioPanel)
$radioPanel.Controls.Add($radioOriginal)
$radioPanel.Controls.Add($radioModified)
$radioPanel.Controls.Add($radioBoth)
$form.Controls.Add($modifyButton)
$form.Controls.Add($saveButton)
# Show the form
$form.Add_Shown({$form.Activate()})
$form.ShowDialog()
Сохраните как угодно.ps1
Работа продолжается.
Последнее редактирование модератором: