TogglePreview Method

Summary
Switches the state of the preview mode on or off.
Syntax
C#
C++/CLI
public virtual void TogglePreview() 
public: 
virtual void TogglePreview();  
Remarks

This is a convenient method to turn the preview mode on and off. If the method fails, an error is raised. For more information, refer to the Error Codes.

Example
C#
using Leadtools; 
using Leadtools.Multimedia; 
using LeadtoolsMultimediaExamples.Fixtures; 
 
 
public bool _result = false; 
public bool _exit = false; 
public CaptureCtrlForm _form = new CaptureCtrlForm(); 
 
public void KeyPressesExample() 
{ 
   CaptureCtrl capturectrl = _form.CaptureCtrl; 
   string outFile = Path.Combine(LEAD_VARS.MediaDir, "CaptureCtrl_KeyPressesExample.avi"); 
 
   try 
   { 
      // set a video device, use the name of your device here 
      if (capturectrl.VideoDevices["USB"] == null) 
         throw new Exception("No USB capture device available"); 
 
      capturectrl.VideoDevices["USB"].Selected = true; 
 
      // select the MPEG4 video compressor 
      capturectrl.VideoCompressors.Mpeg4.Selected = true; 
 
      // set an audio device, use the name of your device here 
      capturectrl.AudioDevices["USB"].Selected = true; 
 
      // enable preview 
      capturectrl.Preview = true; 
 
      // enable CC 
      capturectrl.ClosedCaptioning = true; 
 
      // set the target output file 
      capturectrl.TargetFile = outFile; 
 
      // subscribe to the key events 
      capturectrl.KeyDown += KeyDown_Helper; 
      capturectrl.KeyUp += KeyUp_Helper; 
      capturectrl.KeyPress += KeyPress_Helper; 
 
      // capture it now! 
      capturectrl.StartCapture(CaptureMode.AutoFramesAndAudio); 
 
      // we'll loop on the state and pump messages for this example. 
      // but you should not need to if running from a Windows Forms application. 
      while (_exit == false) 
         Application.DoEvents(); 
   } 
   catch (Exception) 
   { 
      _result = false; 
   } 
 
   // clean up event handlers 
   capturectrl.KeyDown -= KeyDown_Helper; 
   capturectrl.KeyUp -= KeyUp_Helper; 
   capturectrl.KeyPress -= KeyPress_Helper; 
} 
 
void KeyPress_Helper(object sender, Leadtools.Multimedia.KeyPressEventArgs e) 
{ 
   switch ((char)e.keyAscii) 
   { 
      case 'p': 
         // toggle preview mode 
         _form.CaptureCtrl.TogglePreview(); 
         break; 
      case 'f': 
         // toggle full screen mode 
         _form.CaptureCtrl.ToggleFullScreenMode(); 
         break; 
      case 'c': 
         // toggle closed captioning 
         _form.CaptureCtrl.ToggleClosedCaptioning(); 
         break; 
      case 's': 
         // stop the capture and exit 
         _form.CaptureCtrl.StopCapture(); 
         _exit = true; 
         break; 
      case ' ': 
         // pause the capture or run if paused, this shows in the output file 
         if (_form.CaptureCtrl.State == CaptureState.Running || _form.CaptureCtrl.State == CaptureState.Pending) 
            _form.CaptureCtrl.PauseCapture(); 
         else if (_form.CaptureCtrl.State == CaptureState.Paused) 
            _form.CaptureCtrl.RunCapture(); 
         break; 
   } 
 
   // set result 
   _result = true; 
} 
 
void KeyUp_Helper(object sender, KeyUpEventArgs e) 
{ 
   // set result 
   _result = true; 
} 
 
public void KeyDown_Helper(object sender, KeyDownEventArgs e) 
{ 
   // set result 
   _result = true; 
} 
 
static class LEAD_VARS 
{ 
   public const string MediaDir = @"C:\LEADTOOLS23\Media"; 
} 
Requirements

Target Platforms

Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Multimedia Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.