none
How to mane the Button's Edge Soft in Windows forms RRS feed

  • Question

  • Dear team,

    I made a small GUI based Tool with windows forms + powershell, and it works fine, I have few modifications to do

    1. how to make the edges of the button soft , below is the part of the script I am using to create button , also pic is attached

    #Clear Cache Butoon $ClearButton2 = New-Object “System.Windows.Forms.Button”; $ClearButton2.Location = New-Object System.Drawing.Size(15,560) $ClearButton2.Size = new-object System.Drawing.Size(130,30) $ClearButton2.Text = "Clear Cache" $ClearButton2.backcolor = [System.Drawing.Color]::LightBlue $ClearButton2.Add_Click{OnlyCachecleanup}


    2.  How to make the tick mark only green like in attached pic below  , currently my test is been written to Textbox

    Kind regards

    Tanoj


    OSLM ENGINEER - SCCM 2007 & 2012

    Monday, June 25, 2018 10:07 AM

Answers

All replies

  • What is "soft"?

    What is a "tick" in Windows Forms. Do you mean a check? You can't make a checkbox green. You can use a picture control to display a custom image or icon.

    When posting code in this forum please use the code posting tool provided.  The code you posted in unreadable and unusable.


    \_(ツ)_/

    Monday, June 25, 2018 5:05 PM
  • Buttons in Windows forms only have a few styles.  Always read the documentation for a control before using it.

    https://msdn.microsoft.com/en-us/library/system.windows.forms.button%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396

    A button can also display an image.   There is no "soft" style.


    \_(ツ)_/

    Monday, June 25, 2018 5:08 PM
  • What is a "tick" in Windows Forms. Do you mean a check? You can't make a checkbox green. You can use a picture control to display a custom image or icon.

    I am not trying to make a checkbox green,   inside text box the too; writes the messages like below, and just the checkmark should be displayed in different colour, like you see in below picture

    $outputBox = New-Object System.Windows.Forms.RichTextBox
    $outputBox.Location = New-Object System.Drawing.Size(3,125) 
    $outputBox.Size = New-Object System.Drawing.Size(436,405)
    $outputBox.Font = New-Object System.Drawing.Font("Lucida Console",10)
    $outputBox.ForeColor = [Drawing.Color]::Black
    $outputBox.BackColor = "LightGray"
    $outputBox.MultiLine = $True
    $outputBox.ReadOnly = $True
    $outputBox.ScrollBars = "Vertical"
    $outputBox.Text = "    
                Skype Optimer is Ready"
    $outputBox.SelectionStart = $richtextbox1.TextLength;
    $outputBox.ScrollToCaret()
    
    # below command adds the 
    
    $outputbox.Text += "`n" + "✓ VPN Client Program is installed"

    or altlease the specific line should be with different colour example red colour, I tried below code but it is turning all the text in the text box to red colour 

    Add-Type -AssemblyName System.Windows.Forms
    $Form = New-Object Windows.Forms.Form
    $Form.Text = "Skype For Business Optimizer"      
    $Form.Width = 458
    $Form.Height = 648
    $Form.BackColor = "GradientActiveCaption" 
    $Form.StartPosition = "CenterScreen"
    $Font = New-Object System.Drawing.Font("BELL MT",14,[System.Drawing.FontStyle]::Bold)
    # Font styles are: Regular, Bold, Italic, Underline, Strikeout
    $Form.Font = $Font
    $Label = New-Object System.Windows.Forms.Label
    $label.Margin = '4, 0, 4, 0'
    $Label.Text = "                            
                                Skype Optimizer"
    $Label.AutoSize = $True
    $label.TextAlign = 'MiddleCenter'
    $Form.Controls.Add($Label)
    
    
    # Append the richtextbox 
    $outputBox.ForeColor = [Drawing.Color]::Red
    $outputbox.Text += "`n" + "   X Skype Version    :  1.2.3.3"
    $outputBox.text += " Driver version is Correct "


    OSLM ENGINEER - SCCM 2007 & 2012


    Tuesday, June 26, 2018 12:04 PM
  • You are using a special character with your text.  TO make it green you have to set the RTB to green then output that character then change the color back.  You can also just insert the full RTF string. This can only be done with  a RichTextBox and not with a label or textbox.


    \_(ツ)_/

    Tuesday, June 26, 2018 1:59 PM
  • Okay how to make one specific line red ?

    Suppose I want to make " X Skype Version    :  1.2.3.3 "  red and all other lines shoud be black

    yes I am using rich text box

    # Append the richtextbox 
    $outputBox.ForeColor = [Drawing.Color]::Red
    $outputbox.Text += "`n" + "   X Skype Version    :  1.2.3.3"
    $outputBox.text += " Driver version is Correct "


    OSLM ENGINEER - SCCM 2007 & 2012


    Tuesday, June 26, 2018 2:06 PM
  • Also how to do this ? could you please give an example

    TO make it green you have to set the RTB to green then output that character then change the color back.  You can also just insert the full RTF string.


    OSLM ENGINEER - SCCM 2007 & 2012

    Tuesday, June 26, 2018 2:15 PM
  • You would not use "forecolor".  You would use "SelectionColor" then use "ApppendText".

    Example:

    add-type -AssemblyName system.windows.forms
    $f = [system.windows.forms.form]::new()
    $rtb = [System.Windows.Forms.RichTextBox]::new()
    $f.Controls.add($rtb)
    $rtb.AppendText('default')
    $rtb.SelectionColor = 'red'
    $rtb.AppendText('we red now')
    $rtb.SelectionColor = 'green'
    $rtb.AppendText('we green now')
    $f.ShowDialog()


    \_(ツ)_/

    Tuesday, June 26, 2018 2:33 PM
  • Looks like one step closer  , the output from your script is as below, how to put the next text in next line ?


    OSLM ENGINEER - SCCM 2007 & 2012

    Tuesday, June 26, 2018 3:05 PM
  • Add a line break to the text.


    \_(ツ)_/

    Tuesday, June 26, 2018 3:22 PM
  • Hi,

    how to make only a specif sting in text box bold/bigger ? , in below script iam trying to make the "X" bold/bigger

    $outputBox.AppendText("`n`n")
    $outputBox.SelectionColor = 'Red'
    $outputbox.AppendText('      X' )
    $outputBox.SelectionColor = 'Black'
    $outputbox.AppendText("  Headset       : $headsetma")


    OSLM ENGINEER - SCCM 2007 & 2012

    Wednesday, June 27, 2018 10:20 AM
  • I got it

    $outputbox.Selectionfont = "lucida console,12"


    OSLM ENGINEER - SCCM 2007 & 2012

    Wednesday, June 27, 2018 10:27 AM