- Start Visual Studio .NET.
- Choose File->New->Project... from the menu.
- In the New Project dialog box, choose either "Visual C# Projects" or "Visual Basic Projects" in the Projects Type List, and choose "Windows Application " in the Templates List.
- Type the project name as "Multimedia Convert" in the Project Name field, and then choose OK. If desired, type a new location for your project or select a directory using the Browse button, and then choose OK.
- In the "Solution Explorer" window, right-click on the "References" folder, and select "Add Reference..." from the context menu. In the "Add Reference" dialog box, select the ".NET" tab and select Leadtools.Multimedia and click OK. If this dll does not appear under the .NET tab, you will need select the Browse tab and add it from the "<LEADTOOLS_INSTALLDIR>\Bin\DotNet\Win32 " folder, by selecting the following DLL:
- Leadtools.Multimedia.dll
- Make sure Form1 is in design view. Go to the toolbox (View->Toolbox) and drag and drop a ConvertCtrl control on the form. NOTE: If you do not have ConvertCtrl in your toolbox, select Tools->Choose Toolbox Items from the menu. Click Browse and then select Leadtools.Multimedia.dll from "<LEADTOOLS_INSTALLDIR>\Bin\DotNet\Win32" and then click Open and then click OK. After adding it to the form, set the following properties on the convert control:
Property Value Name _convertctrl Anchor Top, Bottom, Left, Right BackColor Black - Go to the toolbox (View->Toolbox) and drag and drop a ProgressBar control on the form (below the convert control) and set the following properties:
Property Value Name _progress Anchor Bottom, Left, Right Step 1 - Go to the toolbox (View->Toolbox) and drag and drop a Button control to the bottom of the form and set the following properties:
Property Value Name _buttonConvert Text Convert Anchor Bottom, Right - Switch Form1 to code view (right-click Form1 in the solution explorer then select View Code) and add the following lines at the beginning of the file:
[Visual Basic]
Imports Leadtools.Multimedia
[C#]using Leadtools.Multimedia;
- Declare the following private variable:
[Visual Basic]
Private _sourceFile As String Private _targetFile As String
[C#]private string _sourceFile; private string _targetFile;
- Add an event handler to the Form1 Load event and code it as follows:
[Visual Basic]
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load _sourceFile = @"<LEADTOOLS_INSTALLDIR>\Media\DaDa_DVD_MPEG2.mpg" _targetFile = "DaDa_MJPEG.avi" End Sub
[C#]private void Form1_Load(object sender, System.EventArgs e) { _sourceFile = @"<LEADTOOLS_INSTALLDIR>\Media\DaDa_DVD_MPEG2.mpg"; _targetFile = "DaDa_MJPEG.avi"; }
- Add an event handler to the _convertctrl Progress event and code it as follows:
[Visual Basic]
Private Sub _convertctrl_Progress(ByVal sender As System.Object, ByVal e As ProgressEventArgs) Handles _convertctrl.Progress _progress.Value = CInt((_progress.Maximum * e.percent / 100)) End Sub
[C#]private void _convertctrl_Progress(object sender, ProgressEventArgs e) { _progress.Value = (int)(_progress.Maximum * e.percent / 100); }
- Add an event handler to the _convertctrl Complete event and code it as follows:
[Visual Basic]
Private Sub _convertctrl_Complete(ByVal sender As System.Object, ByVal e As EventArgs) Handles _convertctrl.Complete MessageBox.Show("Conversion Complete") _buttonConvert.Enabled = True End Sub
[C#]private void _convertctrl_Complete(object sender, EventArgs e) { MessageBox.Show("Conversion Complete"); _buttonConvert.Enabled = true; }
- Add an event handler to the _buttonConvert Click event and code it as follows:
[Visual Basic]
Private Sub _buttonConvert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _buttonConvert.Click Try _convertctrl.Preview = True _convertctrl.SourceFile = _sourceFile _convertctrl.VideoCompressors.MJpeg.Selected = True _convertctrl.TargetFile = _targetFile _convertctrl.StartConvert() _buttonConvert.Enabled = False Catch ex As Exception MessageBox.Show(ex.Message) End Try End Sub
[C#]private void _buttonConvert_Click(object sender, System.EventArgs e) { try { _convertctrl.Preview = true; _convertctrl.SourceFile = _sourceFile; _convertctrl.VideoCompressors.MJpeg.Selected = true; _convertctrl.TargetFile = _targetFile; _convertctrl.StartConvert(); _buttonConvert.Enabled = false; } catch (Exception ex) { MessageBox.Show(this, ex.Message); } }
- Build, and Run the program to test it.