Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Keywords: Form RichTextBox Control .Net dotNet System.Windows.Forms System.Drawing System.Drawing.Point System.Windows.Forms.Form System.Windows.Forms.RichTextBox System.Windows.Forms.Button
;*************************************************************************** ;** Use a Windows .Net Form with a RichTextBox Control ;** ;** Purpose: Accept RichTextBox Input ;** Inputs: ;** Outputs: Results written to screen and an output file ;** Reference: ;** REQUIRES WinBatch 2013A or newer ;** ;** Developer: Deana Falk 2014.02.10 ;*************************************************************************** If Version( )< '2013A' Pause('Notice', 'Need 2013A or Newer Version of WinBatch') Exit EndIf infile = 'C:\Temp\Hello World.rtf' outfile = DirScript():'Result.rtf' If FileExist( outfile ) Then FileDelete( outfile ) _True = ObjectType( 'BOOL', -1 ) _False = ObjectType( 'BOOL', 0 ) ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ObjectClrOption - Load assembly into the WinBatch process ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ObjectClrOption( 'use', 'System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' ) ObjectClrOption( 'use', 'System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' ) ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ObjectClrNew - Create a class implemented by a managed assembly. ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Form1 = ObjectClrNew('System.Windows.Forms.Form') Button1 = ObjectClrNew('System.Windows.Forms.Button') RichTextBox1 = ObjectClrNew('System.Windows.Forms.RichTextBox') ; Enumerations enumStartPos = ObjectClrNew('System.Windows.Forms.FormStartPosition') enumDialogResult = ObjectClrNew( 'System.Windows.Forms.DialogResult') ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; Define Form1 ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; Set the caption bar text of the form. Form1.Text = 'RichTextBox' ; Set the start position of the form to the center of the screen. Form1.StartPosition = ObjectClrType( 'System.Windows.Forms.FormStartPosition', enumStartPos.CenterScreen ) ;CenterScreen ; Set the accept button of the form to button1. Form1.AcceptButton = button1 ; Obtain the Width of the form for later use with controls formwidth = Form1.Width ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; Define RichTextBox1 ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; Position RichTextBox RichTextBox1.Location = ObjectClrNew('System.Drawing.Point',0,10) ; Define width to width of the form RichTextBox1.Width = formwidth ; Specify tabindex RichTextBox1.TabIndex = 0 ; Fill RichTextBox1 RichTextBox1.LoadFile( infile ) ; *OR* ;RichTextBox1.Text = 'Hello' ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; Define Button1 ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; Set the position of the button on the form. button1.Location = ObjectClrNew('System.Drawing.Point',100,110) ; Set the text of button1 to 'OK'. button1.Text = 'OK' ; Specify tabindex button1.TabIndex = 1 ; IMPORTANT: The dialog box can be assigned one of the values of the DialogResult enumeration by assigning it to the DialogResult property of a Button on the form. button1.DialogResult = ObjectClrType( 'System.Windows.Forms.DialogResult', enumDialogResult.OK ) ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; Add Controls ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Form1.Controls.Add(Button1) Form1.Controls.Add(RichTextBox1) ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; Display the form as a modal dialog box. ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ret = Form1.ShowDialog() ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; Get Results ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Pause( 'Text Contents of RichTextBox1', RichTextBox1.Text ) Pause( 'RTF Contents of RichTextBox1', RichTextBox1.Rtf ) seltext = RichTextBox1.SelectedText If seltext != '' Then Pause( 'User SelectedText of RichTextBox1', seltext ) ;Save the contents of RichTextBox to a file RichTextBox1.SaveFile(outfile) ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; Clean up ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Button1.Dispose() RichTextBox1.Dispose() Form1.Dispose() ; Open RTF file in Default Application If FileExist(outfile) Then ShellExecute(outfile, '', '', @NORMAL, '') Exit
Article ID: W17848
Filename: RichTextBox.txt
File Created: 2014:02:11:14:39:52
Last Updated: 2014:02:11:14:39:52