Search found 13262 matches

by jvierra
Mon Mar 18, 2019 8:56 pm
Forum: Windows PowerShell
Topic: Unable to call Function to parse the string from AD result
Replies: 3
Views: 64

Re: Unable to call Function to parse the string from AD result

How to format a telephone number:


$n = '2123346789'
'({0}){1}-{2}' -f $n.SubString(0,3),$n.Substring(3,3),$n.SubString(6,4)
by jvierra
Mon Mar 18, 2019 3:31 pm
Forum: PowerShell GUIs
Topic: RichTextBox: Adding dynamically-generated picture to existing content
Replies: 23
Views: 219

Re: RichTextBox: Adding dynamically-generated picture to existing content

I just wanted you to understand why your code was unusable and unnecessary so you would understand how PowerShell, Net and the clipboard work.
by jvierra
Mon Mar 18, 2019 2:02 pm
Forum: PowerShell GUIs
Topic: RichTextBox: Adding dynamically-generated picture to existing content
Replies: 23
Views: 219

Re: RichTextBox: Adding dynamically-generated picture to existing content

With the Net Framwork we can also use this to copy and restore the clipboard


# save clipboard contents
$clp = [System.Windows.Forms.Clipboard]::GetDataObject()
# restore clipboard contents
[System.Windows.Forms.Clipboard]::SetDataObject($clp)
by jvierra
Mon Mar 18, 2019 1:53 pm
Forum: PowerShell GUIs
Topic: RichTextBox: Adding dynamically-generated picture to existing content
Replies: 23
Views: 219

Re: RichTextBox: Adding dynamically-generated picture to existing content

Just for the sake of argument here is how the C# could would translate into PowerShell. # save clipboard contents $saved = [System.Windows.Forms.Clipboard]::GetDataObject().GetFormats() | ForEach-Object{ [System.Windows.Forms.Clipboard]::GetData($_) } # restore contents $saved | ForEach-Object{ [Sys...
by jvierra
Mon Mar 18, 2019 1:44 pm
Forum: PowerShell GUIs
Topic: RichTextBox: Adding dynamically-generated picture to existing content
Replies: 23
Views: 219

Re: RichTextBox: Adding dynamically-generated picture to existing content

It is not really necessary to restore the clipboard for end users. This would only be done as an example of how the clipboards works. My code is all you need. If users want a clipboard that saves the data per process then the next update to Windows 10 will allow that. It will be the users choice. Ju...
by jvierra
Mon Mar 18, 2019 1:28 pm
Forum: PowerShell GUIs
Topic: RichTextBox: Adding dynamically-generated picture to existing content
Replies: 23
Views: 219

Re: RichTextBox: Adding dynamically-generated picture to existing content

The code you posted is titled "How do I backup and restore the system clipboard in C#?" It has nothing to do with adding an image to the clipboard and pasting it into a control. Also note that none of the answers were marked as correct because the code does not work in C#. The last guess on the page...
by jvierra
Mon Mar 18, 2019 1:22 pm
Forum: PowerShell GUIs
Topic: RichTextBox: Adding dynamically-generated picture to existing content
Replies: 23
Views: 219

Re: RichTextBox: Adding dynamically-generated picture to existing content

That is not what you want to do. Just copy the image to the clipboard and paste it into the control. It takes two steps. Copy then paste. The rest of that has nothing to do with what you are trying to do. And yes, I am fully aware of how to copy and restore the clipboard formats in C/C++/C# and VB. ...
by jvierra
Mon Mar 18, 2019 12:55 pm
Forum: PowerShell GUIs
Topic: RichTextBox: Adding dynamically-generated picture to existing content
Replies: 23
Views: 219

Re: RichTextBox: Adding dynamically-generated picture to existing content

You also must add the "Dispose()" or the file will remain open.
by jvierra
Mon Mar 18, 2019 12:52 pm
Forum: PowerShell GUIs
Topic: RichTextBox: Adding dynamically-generated picture to existing content
Replies: 23
Views: 219

Re: RichTextBox: Adding dynamically-generated picture to existing content

Most of the code you posted is unnecessary. You are trying to add every format to the clipboard but have not really added anything. Just do this: [System.Windows.Forms.Clipboard]::SetImage([System.Drawing.Image]::FromFile("$ScriptDirectory/barcode.png")) $richTextBox2.Select($richTextBox2.Text.Lengt...