【问题标题】:How to set radius for textbox and button in PowerShell studio?如何在 PowerShell Studio 中设置文本框和按钮的半径?
【发布时间】:2021-09-20 06:26:40
【问题描述】:

我在 PowerShell 工作室做一个简单的项目。我想要圆形的文本框和按钮,如何以编程方式或使用属性窗口来做到这一点

【问题讨论】:

  • 圆形?您的意思是像自定义图像来替换默认图像?

标签: .net powershell powershell-studio


【解决方案1】:

如果是你想要的图片:

$button.Image=[System.Drawing.Image]::FromFile('c:\image.jpg')

如果你想完成它,PowerShell Studio 是不可能的。

【讨论】:

    【解决方案2】:

    不知道这是否是在 PowerShell 上处理此问题的正确方法,只是尝试从 Round shaped buttons 翻译 C# 代码。

    希望它能帮助您开始您的研究。

    演示

    代码

    Add-Type -AssemblyName System.Windows.Forms, System.Drawing
    [void][System.Windows.Forms.Application]::EnableVisualStyles()
    
    $bounds = [System.Windows.Forms.Screen]::PrimaryScreen.WorkingArea
    
    $mainForm = [System.Windows.Forms.Form]::new()
    $mainForm.StartPosition = 'CenterScreen'
    $mainForm.Size = [System.Drawing.Size]::new(($bounds.Width/3),($bounds.Height/3))
    $mainForm.FormBorderStyle = 'Sizable'
    $mainForm.Text = 'Circle Button'
    $mainForm.WindowState = 'Normal'
    $mainForm.KeyPreview = $True
    
    $mainForm.Add_Resize({
        $circleBtn.Width = $mainForm.Width-100
        $circleBtn.Height = $mainForm.Height-100
        $path = [System.Drawing.Drawing2D.GraphicsPath]::new()
        $path.AddEllipse(0, 0, $circleBtn.ClientSize.Width, $circleBtn.ClientSize.Height)
        $circleBtn.Region = [System.Drawing.Region]::new($path)
    })
    
    $circleBtn = [System.Windows.Forms.Button]::new()
    $circleBtn.Text = '&Hello'
    $circleBtn.Font = [System.Drawing.Font]::new('Calibri',30)
    $circleBtn.Width = $mainForm.Width-100
    $circleBtn.Height = $mainForm.Height-100
    $circleBtn.Location = [System.Drawing.Size]::new(40,20)
    $circleBtn.FlatAppearance.BorderSize = 0
    $circleBtn.FlatStyle = 'Flat'
    $circleBtn.BackColor = [System.Drawing.Color]::LightGray
    $circleBtn.Add_MouseHover({
        $this.BackColor = [System.Drawing.Color]::DarkGray
    })
    
    $circleBtn.Add_MouseLeave({
        $this.BackColor = [System.Drawing.Color]::LightGray
    })
    $path = [System.Drawing.Drawing2D.GraphicsPath]::new()
    $path.AddEllipse(0, 0, $circleBtn.ClientSize.Width, $circleBtn.ClientSize.Height)
    $circleBtn.Region = [System.Drawing.Region]::new($path)
    $mainForm.Controls.Add($circleBtn)
    
    $mainForm.Add_Shown({$this.Activate()})
    $mainForm.ShowDialog()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-22
      相关资源
      最近更新 更多