|
//----------------------------------------------------------------------------
// File: Formats.cs
//
// Copyright (c) Microsoft Corp. All rights reserved.
//-----------------------------------------------------------------------------
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Collections;
using Microsoft.DirectX;
using Microsoft.DirectX.DirectSound;
public class FormatsForm : Form
{
private struct FormatInfo
{
public WaveFormat format;
public override string ToString()
{
return ConvertWaveFormatToString(format);
}
};
private Button buttonOk;
private Button buttonCancel;
private ListBox lbFormatsInputListbox;
private Label labelStatic;
private MainForm mf = null;
private ArrayList formats = new ArrayList();
private bool[] InputFormatSupported = new bool[20];
public FormatsForm(MainForm mf)
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
this.mf = mf;
ScanAvailableInputFormats();
FillFormatListBox();
}
#region InitializeComponent code
private void InitializeComponent()
{
this.buttonOk = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.lbFormatsInputListbox = new System.Windows.Forms.ListBox();
this.labelStatic = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// buttonOk
//
this.buttonOk.Enabled = false;
this.buttonOk.Location = new System.Drawing.Point(10, 128);
this.buttonOk.Name = "buttonOk";
this.buttonOk.Size = new System.Drawing.Size(75, 23);
this.buttonOk.TabIndex = 0;
this.buttonOk.Text = "OK";
this.buttonOk.Click += new System.EventHandler(this.buttonOk_Click);
//
// buttonCancel
//
this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.buttonCancel.Location = new System.Drawing.Point(97, 128);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(75, 23);
this.buttonCancel.TabIndex = 1;
this.buttonCancel.Text = "Cancel";
this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
//
// lbFormatsInputListbox
//
this.lbFormatsInputListbox.Location = new System.Drawing.Point(10, 24);
this.lbFormatsInputListbox.Name = "lbFormatsInputListbox";
this.lbFormatsInputListbox.Size = new System.Drawing.Size(162, 95);
this.lbFormatsInputListbox.TabIndex = 2;
this.lbFormatsInputListbox.SelectedIndexChanged += new System.EventHandler(this.lbFormatsInputListbox_SelectedIndexChanged);
//
// labelStatic
//
this.labelStatic.Location = new System.Drawing.Point(10, 11);
this.labelStatic.Name = "labelStatic";
this.labelStatic.Size = new System.Drawing.Size(75, 13);
this.labelStatic.TabIndex = 3;
this.labelStatic.Text = "Input Format:";
this.labelStatic.Click += new System.EventHandler(this.labelStatic_Click);
//
// FormatsForm
//
this.AcceptButton = this.buttonOk;
this.CancelButton = this.buttonCancel;
this.ClientSize = new System.Drawing.Size(183, 170);
this.Controls.Add(this.buttonOk);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.lbFormatsInputListbox);
this.Controls.Add(this.labelStatic);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Name = "FormatsForm";
this.Text = "Select Capture Format";
this.ResumeLayout(false);
}
#endregion
private void ScanAvailableInputFormats()
{
//-----------------------------------------------------------------------------
// Name: ScanAvailableInputFormats()
// Desc: Tests to see if 20 different standard wave formats are supported by
// the capture device
//-----------------------------------------------------------------------------
WaveFormat format = new WaveFormat();
CaptureBufferDescription dscheckboxd = new CaptureBufferDescription();
CaptureBuffer pDSCaptureBuffer = null;
// This might take a second or two, so throw up the hourglass
Cursor = Cursors.WaitCursor;
format.FormatTag = WaveFormatTag.Pcm;
// Try 20 different standard formats to see if they are supported
for (int iIndex = 0; iIndex < 20; iIndex++)
{
GetWaveFormatFromIndex(iIndex, ref format);
// To test if a capture format is supported, try to create a
// new capture buffer using a specific format. If it works
// then the format is supported, otherwise not.
dscheckboxd.BufferBytes = format.AverageBytesPerSecond;
dscheckboxd.Format = format;
try
{
pDSCaptureBuffer = new CaptureBuffer(dscheckboxd, mf.applicationDevice);
InputFormatSupported[ iIndex ] = true;
}
catch
{
InputFormatSupported[ iIndex ] = false;
}
if (pDSCaptureBuffer != null)
pDSCaptureBuffer.Dispose();
}
Cursor = Cursors.Default;
}
private void GetWaveFormatFromIndex(int Index, ref WaveFormat format)
{
//-----------------------------------------------------------------------------
// Name: GetWaveFormatFromIndex()
// Desc: Returns 20 different wave formats based on Index
//-----------------------------------------------------------------------------
int SampleRate = Index / 4;
int iType = Index % 4;
switch (SampleRate)
{
case 0: format.SamplesPerSecond = 48000; break;
case 1: format.SamplesPerSecond = 44100; break;
case 2: format.SamplesPerSecond = 22050; break;
case 3: format.SamplesPerSecond = 11025; break;
case 4: format.SamplesPerSecond = 8000; break;
}
switch (iType)
{
case 0: format.BitsPerSample = 8; format.Channels = 1; break;
case 1: format.BitsPerSample = 16; format.Channels = 1; break;
case 2: format.BitsPerSample = 8; format.Channels = 2; break;
case 3: format.BitsPerSample = 16; format.Channels = 2; break;
}
format.BlockAlign = (short)(format.Channels * (format.BitsPerSample / 8));
format.AverageBytesPerSecond = format.BlockAlign * format.SamplesPerSecond;
}
void FillFormatListBox()
{
//-----------------------------------------------------------------------------
// Name: FillFormatListBox()
// Desc: Fills the format list box based on the availible formats
//-----------------------------------------------------------------------------
FormatInfo info = new FormatInfo();
string strFormatName = string.Empty;
WaveFormat format = new WaveFormat();
for (int iIndex = 0; iIndex < InputFormatSupported.Length; iIndex++)
{
if (true == InputFormatSupported[iIndex])
{
// Turn the index into a WaveFormat then turn that into a
// string and put the string in the listbox
GetWaveFormatFromIndex(iIndex, ref format);
info.format = format;
formats.Add(info);
}
}
lbFormatsInputListbox.DataSource = formats;
}
private static string ConvertWaveFormatToString(WaveFormat format)
{
//-----------------------------------------------------------------------------
// Name: ConvertWaveFormatToString()
// Desc: Converts a wave format to a text string
//-----------------------------------------------------------------------------
return format.SamplesPerSecond + " Hz, " +
format.BitsPerSample + "-bit " +
((format.Channels == 1) ? "Mono" : "Stereo");
}
private void FormatsOK()
{
//-----------------------------------------------------------------------------
// Name: FormatsOK()
// Desc: Stores the capture buffer format based on what was selected
//-----------------------------------------------------------------------------
mf.InputFormat = ((FormatInfo)formats[lbFormatsInputListbox.SelectedIndex]).format;
this.DialogResult = DialogResult.OK;
Close();
}
private void buttonOk_Click(object sender, System.EventArgs e)
{
FormatsOK();
}
private void lbFormatsInputListbox_SelectedIndexChanged(object sender, System.EventArgs e)
{
buttonOk.Enabled = true;
}
private void buttonCancel_Click(object sender, EventArgs e)
{
}
private void labelStatic_Click(object sender, EventArgs e)
{
}
}
|
|
|
|
|
(via Instant VB)
Imports Microsoft.VisualBasic
'----------------------------------------------------------------------------
' File: Formats.cs
'
' Copyright (c) Microsoft Corp. All rights reserved.
'-----------------------------------------------------------------------------
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Imports System.Collections
Imports Microsoft.DirectX
Imports Microsoft.DirectX.DirectSound
Public Class FormatsForm
Inherits Form
Private Structure FormatInfo
Public format As WaveFormat
Public Overrides Function ToString() As String
Return ConvertWaveFormatToString(format)
End Function
End Structure
Private WithEvents buttonOk As Button
Private WithEvents buttonCancel As Button
Private WithEvents lbFormatsInputListbox As ListBox
Private WithEvents labelStatic As Label
Private mf As MainForm = Nothing
Private formats As ArrayList = New ArrayList()
Private InputFormatSupported As Boolean() = New Boolean(19){}
Public Sub New(ByVal mf As MainForm)
'
' Required for Windows Form Designer support
'
InitializeComponent()
Me.mf = mf
ScanAvailableInputFormats()
FillFormatListBox()
End Sub
#Region "InitializeComponent code"
Private Sub InitializeComponent()
Me.buttonOk = New System.Windows.Forms.Button()
Me.buttonCancel = New System.Windows.Forms.Button()
Me.lbFormatsInputListbox = New System.Windows.Forms.ListBox()
Me.labelStatic = New System.Windows.Forms.Label()
Me.SuspendLayout()
'
' buttonOk
'
Me.buttonOk.Enabled = False
Me.buttonOk.Location = New System.Drawing.Point(10, 128)
Me.buttonOk.Name = "buttonOk"
Me.buttonOk.Size = New System.Drawing.Size(75, 23)
Me.buttonOk.TabIndex = 0
Me.buttonOk.Text = "OK"
'Me.buttonOk.Click += New System.EventHandler(Me.buttonOk_Click);
'
' buttonCancel
'
Me.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel
Me.buttonCancel.Location = New System.Drawing.Point(97, 128)
Me.buttonCancel.Name = "buttonCancel"
Me.buttonCancel.Size = New System.Drawing.Size(75, 23)
Me.buttonCancel.TabIndex = 1
Me.buttonCancel.Text = "Cancel"
'Me.buttonCancel.Click += New System.EventHandler(Me.buttonCancel_Click);
'
' lbFormatsInputListbox
'
Me.lbFormatsInputListbox.Location = New System.Drawing.Point(10, 24)
Me.lbFormatsInputListbox.Name = "lbFormatsInputListbox"
Me.lbFormatsInputListbox.Size = New System.Drawing.Size(162, 95)
Me.lbFormatsInputListbox.TabIndex = 2
'Me.lbFormatsInputListbox.SelectedIndexChanged += New System.EventHandler(Me.lbFormatsInputListbox_SelectedIndexChanged);
'
' labelStatic
'
Me.labelStatic.Location = New System.Drawing.Point(10, 11)
Me.labelStatic.Name = "labelStatic"
Me.labelStatic.Size = New System.Drawing.Size(75, 13)
Me.labelStatic.TabIndex = 3
Me.labelStatic.Text = "Input Format:"
'Me.labelStatic.Click += New System.EventHandler(Me.labelStatic_Click);
'
' FormatsForm
'
Me.AcceptButton = Me.buttonOk
Me.CancelButton = Me.buttonCancel
Me.ClientSize = New System.Drawing.Size(183, 170)
Me.Controls.Add(Me.buttonOk)
Me.Controls.Add(Me.buttonCancel)
Me.Controls.Add(Me.lbFormatsInputListbox)
Me.Controls.Add(Me.labelStatic)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
Me.Name = "FormatsForm"
Me.Text = "Select Capture Format"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub ScanAvailableInputFormats()
'-----------------------------------------------------------------------------
' Name: ScanAvailableInputFormats()
' Desc: Tests to see if 20 different standard wave formats are supported by
' the capture device
'-----------------------------------------------------------------------------
Dim format As WaveFormat = New WaveFormat()
Dim dscheckboxd As CaptureBufferDescription = New CaptureBufferDescription()
Dim pDSCaptureBuffer As CaptureBuffer = Nothing
' This might take a second or two, so throw up the hourglass
Cursor = Cursors.WaitCursor
format.FormatTag = WaveFormatTag.Pcm
' Try 20 different standard formats to see if they are supported
For iIndex As Integer = 0 To 19
GetWaveFormatFromIndex(iIndex, format)
' To test if a capture format is supported, try to create a
' new capture buffer using a specific format. If it works
' then the format is supported, otherwise not.
dscheckboxd.BufferBytes = format.AverageBytesPerSecond
dscheckboxd.Format = format
Try
pDSCaptureBuffer = New CaptureBuffer(dscheckboxd, mf.applicationDevice)
InputFormatSupported(iIndex) = True
Catch
InputFormatSupported(iIndex) = False
End Try
If Not pDSCaptureBuffer Is Nothing Then
pDSCaptureBuffer.Dispose()
End If
Next iIndex
Cursor = Cursors.Default
End Sub
Private Sub GetWaveFormatFromIndex(ByVal Index As Integer, ByRef format As WaveFormat)
'-----------------------------------------------------------------------------
' Name: GetWaveFormatFromIndex()
' Desc: Returns 20 different wave formats based on Index
'-----------------------------------------------------------------------------
Dim SampleRate As Integer = Index \ 4
Dim iType As Integer = Index Mod 4
Select Case SampleRate
Case 0
format.SamplesPerSecond = 48000
Case 1
format.SamplesPerSecond = 44100
Case 2
format.SamplesPerSecond = 22050
Case 3
format.SamplesPerSecond = 11025
Case 4
format.SamplesPerSecond = 8000
End Select
Select Case iType
Case 0
format.BitsPerSample = 8
format.Channels = 1
Case 1
format.BitsPerSample = 16
format.Channels = 1
Case 2
format.BitsPerSample = 8
format.Channels = 2
Case 3
format.BitsPerSample = 16
format.Channels = 2
End Select
format.BlockAlign = CShort(Fix(format.Channels * (format.BitsPerSample / 8)))
format.AverageBytesPerSecond = format.BlockAlign * format.SamplesPerSecond
End Sub
Private Sub FillFormatListBox()
'-----------------------------------------------------------------------------
' Name: FillFormatListBox()
' Desc: Fills the format list box based on the availible formats
'-----------------------------------------------------------------------------
Dim info As FormatInfo = New FormatInfo()
Dim strFormatName As String = String.Empty
Dim format As WaveFormat = New WaveFormat()
For iIndex As Integer = 0 To InputFormatSupported.Length - 1
If True = InputFormatSupported(iIndex) Then
' Turn the index into a WaveFormat then turn that into a
' string and put the string in the listbox
GetWaveFormatFromIndex(iIndex, format)
info.format = format
formats.Add(info)
End If
Next iIndex
lbFormatsInputListbox.DataSource = formats
End Sub
Private Shared Function ConvertWaveFormatToString(ByVal format As WaveFormat) As String
'-----------------------------------------------------------------------------
' Name: ConvertWaveFormatToString()
' Desc: Converts a wave format to a text string
'-----------------------------------------------------------------------------
If (format.Channels = 1) Then
Return format.SamplesPerSecond & " Hz, " & format.BitsPerSample & "-bit " & ("Mono")
Else
Return format.SamplesPerSecond & " Hz, " & format.BitsPerSample & "-bit " & ("Stereo")
End If
End Function
Private Sub FormatsOK()
'-----------------------------------------------------------------------------
' Name: FormatsOK()
' Desc: Stores the capture buffer format based on what was selected
'-----------------------------------------------------------------------------
mf.InputFormat = (CType(formats(lbFormatsInputListbox.SelectedIndex), FormatInfo)).format
Me.DialogResult = System.Windows.Forms.DialogResult.OK
Close()
End Sub
Private Sub buttonOk_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles buttonOk.Click
FormatsOK()
End Sub
Private Sub lbFormatsInputListbox_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbFormatsInputListbox.SelectedIndexChanged
buttonOk.Enabled = True
End Sub
Private Sub buttonCancel_Click(ByVal sender As Object, ByVal e As EventArgs) Handles buttonCancel.Click
End Sub
Private Sub labelStatic_Click(ByVal sender As Object, ByVal e As EventArgs) Handles labelStatic.Click
End Sub
End Class
David Anton
http://www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
C++ to C# Converter: converts C++ to C#
C++ to VB Converter: converts C++ to VB
C++ to Java Converter: converts C++ to Java
Instant C++: converts C# to C++/CLI and VB to C++/CLI
|
|
|
|
|
//----------------------------------------------------------------------------
// File: Devices.cs
//
// Copyright (c) Microsoft Corp. All rights reserved.
//-----------------------------------------------------------------------------
using System;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.DirectX.DirectSound;
public class DevicesForm : Form
{
private Button buttonOk;
private Button buttonCancel;
private Label labelStatic;
private ComboBox comboboxCaptureDeviceCombo;
private MainForm mf = null;
CaptureDevicesCollection devices = new CaptureDevicesCollection();
public DevicesForm(MainForm mf)
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
this.mf = mf;
foreach (DeviceInformation info in devices)
comboboxCaptureDeviceCombo.Items.Add(info.Description);
comboboxCaptureDeviceCombo.SelectedIndex = 0;
}
#region InitializeComponent code
private void InitializeComponent()
{
this.buttonOk = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.labelStatic = new System.Windows.Forms.Label();
this.comboboxCaptureDeviceCombo = new System.Windows.Forms.ComboBox();
this.SuspendLayout();
//
// buttonOk
//
this.buttonOk.Location = new System.Drawing.Point(10, 41);
this.buttonOk.Name = "buttonOk";
this.buttonOk.Size = new System.Drawing.Size(75, 23);
this.buttonOk.TabIndex = 0;
this.buttonOk.Text = "OK";
this.buttonOk.Click += new System.EventHandler(this.buttonOk_Click);
//
// buttonCancel
//
this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.buttonCancel.Location = new System.Drawing.Point(231, 41);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(75, 23);
this.buttonCancel.TabIndex = 1;
this.buttonCancel.Text = "Cancel";
this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
//
// labelStatic
//
this.labelStatic.Location = new System.Drawing.Point(0, 14);
this.labelStatic.Name = "labelStatic";
this.labelStatic.Size = new System.Drawing.Size(88, 13);
this.labelStatic.TabIndex = 2;
this.labelStatic.Text = "Capture Device:";
this.labelStatic.Click += new System.EventHandler(this.labelStatic_Click);
//
// comboboxCaptureDeviceCombo
//
this.comboboxCaptureDeviceCombo.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboboxCaptureDeviceCombo.Location = new System.Drawing.Point(93, 11);
this.comboboxCaptureDeviceCombo.Name = "comboboxCaptureDeviceCombo";
this.comboboxCaptureDeviceCombo.Size = new System.Drawing.Size(213, 21);
this.comboboxCaptureDeviceCombo.Sorted = true;
this.comboboxCaptureDeviceCombo.TabIndex = 3;
this.comboboxCaptureDeviceCombo.SelectedIndexChanged += new System.EventHandler(this.comboboxCaptureDeviceCombo_SelectedIndexChanged);
//
// DevicesForm
//
this.AcceptButton = this.buttonOk;
this.CancelButton = this.buttonCancel;
this.ClientSize = new System.Drawing.Size(316, 79);
this.Controls.Add(this.buttonOk);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.labelStatic);
this.Controls.Add(this.comboboxCaptureDeviceCombo);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Name = "DevicesForm";
this.Text = "Select Capture Device";
this.ResumeLayout(false);
}
#endregion
private void buttonOk_Click(object sender, System.EventArgs e)
{
if (0 < comboboxCaptureDeviceCombo.Items.Count)
mf.CaptureDeviceGuid = devices[0].DriverGuid;
Close();
}
private void buttonCancel_Click(object sender, EventArgs e)
{
}
private void labelStatic_Click(object sender, EventArgs e)
{
}
private void comboboxCaptureDeviceCombo_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
|
|
|
|
|
//--------------------------------------------------------------------------------------
// File: AssemblyInfo.cs
//
// Assembly information for all managed samples
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//--------------------------------------------------------------------------------------
using System;
using System.Security;
using System.Security.Permissions;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
// Set assembly information
[assembly: AssemblyTitle("Microsoft DirectX SDK Sample")]
[assembly: AssemblyDescription("Sample Code for the Microsoft DirectX SDK")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("DirectX SDK")]
[assembly: AssemblyCopyright("Copyright (c) Microsoft Corporation. All rights reserved.")]
// Update version
[assembly: AssemblyVersion("9.12.589.0000")]
// We will use UInt which isn't CLS compliant, possible unsafe code as well
[assembly: CLSCompliant(false)]
[assembly: ComVisible(false)]
// Security information
[assembly: SecurityPermissionAttribute(SecurityAction.RequestMinimum, UnmanagedCode=true)]
[assembly: SecurityPermissionAttribute(SecurityAction.RequestMinimum, Execution=true)]
// We want to be able to read the registry key
[assembly: RegistryPermissionAttribute(SecurityAction.RequestMinimum,Read="HKEY_LOCAL_MACHINE\\Software\\Microsoft\\DirectX SDK")]
|
|
|
|
|
(via Instant VB)
'--------------------------------------------------------------------------------------
' File: AssemblyInfo.cs
'
' Assembly information for all managed samples
'
' Copyright (c) Microsoft Corporation. All rights reserved.
'--------------------------------------------------------------------------------------
Imports System
Imports System.Security
Imports System.Security.Permissions
Imports System.Reflection
Imports System.Runtime.InteropServices
Imports System.Runtime.CompilerServices
' Set assembly information
<Assembly: AssemblyTitle("Microsoft DirectX SDK Sample")>
<Assembly: AssemblyDescription("Sample Code for the Microsoft DirectX SDK")>
<Assembly: AssemblyCompany("Microsoft")>
<Assembly: AssemblyProduct("DirectX SDK")>
<Assembly: AssemblyCopyright("Copyright (c) Microsoft Corporation. All rights reserved.")>
' Update version
<Assembly: AssemblyVersion("9.12.589.0000")>
' We will use UInt which isn't CLS compliant, possible unsafe code as well
<Assembly: CLSCompliant(False)>
<Assembly: ComVisible(False)>
' Security information
<Assembly: SecurityPermissionAttribute(SecurityAction.RequestMinimum, UnmanagedCode:=True)>
<Assembly: SecurityPermissionAttribute(SecurityAction.RequestMinimum, Execution:=True)>
' We want to be able to read the registry key
<Assembly: RegistryPermissionAttribute(SecurityAction.RequestMinimum,Read:="HKEY_LOCAL_MACHINE\Software\Microsoft\DirectX SDK")>
David Anton
http://www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
C++ to C# Converter: converts C++ to C#
C++ to VB Converter: converts C++ to VB
C++ to Java Converter: converts C++ to Java
Instant C++: converts C# to C++/CLI and VB to C++/CLI
|
|
|
|
|
(via Instant VB)
'----------------------------------------------------------------------------
' File: Devices.cs
'
' Copyright (c) Microsoft Corp. All rights reserved.
'-----------------------------------------------------------------------------
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Imports Microsoft.DirectX.DirectSound
Public Class DevicesForm
Inherits Form
Private WithEvents buttonOk As Button
Private WithEvents buttonCancel As Button
Private WithEvents labelStatic As Label
Private WithEvents comboboxCaptureDeviceCombo As ComboBox
Private mf As MainForm = Nothing
Private devices As CaptureDevicesCollection = New CaptureDevicesCollection()
Public Sub New(ByVal mf As MainForm)
'
' Required for Windows Form Designer support
'
InitializeComponent()
Me.mf = mf
For Each info As DeviceInformation In devices
comboboxCaptureDeviceCombo.Items.Add(info.Description)
Next info
comboboxCaptureDeviceCombo.SelectedIndex = 0
End Sub
#Region "InitializeComponent code"
Private Sub InitializeComponent()
Me.buttonOk = New System.Windows.Forms.Button()
Me.buttonCancel = New System.Windows.Forms.Button()
Me.labelStatic = New System.Windows.Forms.Label()
Me.comboboxCaptureDeviceCombo = New System.Windows.Forms.ComboBox()
Me.SuspendLayout()
'
' buttonOk
'
Me.buttonOk.Location = New System.Drawing.Point(10, 41)
Me.buttonOk.Name = "buttonOk"
Me.buttonOk.Size = New System.Drawing.Size(75, 23)
Me.buttonOk.TabIndex = 0
Me.buttonOk.Text = "OK"
'Me.buttonOk.Click += New System.EventHandler(Me.buttonOk_Click);
'
' buttonCancel
'
Me.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel
Me.buttonCancel.Location = New System.Drawing.Point(231, 41)
Me.buttonCancel.Name = "buttonCancel"
Me.buttonCancel.Size = New System.Drawing.Size(75, 23)
Me.buttonCancel.TabIndex = 1
Me.buttonCancel.Text = "Cancel"
'Me.buttonCancel.Click += New System.EventHandler(Me.buttonCancel_Click);
'
' labelStatic
'
Me.labelStatic.Location = New System.Drawing.Point(0, 14)
Me.labelStatic.Name = "labelStatic"
Me.labelStatic.Size = New System.Drawing.Size(88, 13)
Me.labelStatic.TabIndex = 2
Me.labelStatic.Text = "Capture Device:"
'Me.labelStatic.Click += New System.EventHandler(Me.labelStatic_Click);
'
' comboboxCaptureDeviceCombo
'
Me.comboboxCaptureDeviceCombo.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Me.comboboxCaptureDeviceCombo.Location = New System.Drawing.Point(93, 11)
Me.comboboxCaptureDeviceCombo.Name = "comboboxCaptureDeviceCombo"
Me.comboboxCaptureDeviceCombo.Size = New System.Drawing.Size(213, 21)
Me.comboboxCaptureDeviceCombo.Sorted = True
Me.comboboxCaptureDeviceCombo.TabIndex = 3
'Me.comboboxCaptureDeviceCombo.SelectedIndexChanged += New System.EventHandler(Me.comboboxCaptureDeviceCombo_SelectedIndexChanged);
'
' DevicesForm
'
Me.AcceptButton = Me.buttonOk
Me.CancelButton = Me.buttonCancel
Me.ClientSize = New System.Drawing.Size(316, 79)
Me.Controls.Add(Me.buttonOk)
Me.Controls.Add(Me.buttonCancel)
Me.Controls.Add(Me.labelStatic)
Me.Controls.Add(Me.comboboxCaptureDeviceCombo)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
Me.Name = "DevicesForm"
Me.Text = "Select Capture Device"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub buttonOk_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles buttonOk.Click
If 0 < comboboxCaptureDeviceCombo.Items.Count Then
mf.CaptureDeviceGuid = devices(0).DriverGuid
End If
Close()
End Sub
Private Sub buttonCancel_Click(ByVal sender As Object, ByVal e As EventArgs) Handles buttonCancel.Click
End Sub
Private Sub labelStatic_Click(ByVal sender As Object, ByVal e As EventArgs) Handles labelStatic.Click
End Sub
Private Sub comboboxCaptureDeviceCombo_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles comboboxCaptureDeviceCombo.SelectedIndexChanged
End Sub
End Class
David Anton
http://www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
C++ to C# Converter: converts C++ to C#
C++ to VB Converter: converts C++ to VB
C++ to Java Converter: converts C++ to Java
Instant C++: converts C# to C++/CLI and VB to C++/CLI
|
|
|
|
|
Thank you, your code has cleared up the errors I was getting. However, there still seems to be 1 problem. On the c# program the devices form comes up first but the main form comes up in vb. The reason seems to be that in the c# project the program starts in this function:
[STAThread]<br />
public static void Main()<br />
{<br />
try<br />
{<br />
using(MainForm form = new MainForm())<br />
{<br />
form.ShowDialog();<br />
}<br />
}<br />
catch{}<br />
}
But when I placed a bunch of breakpoints in my vb program it doesn't seem to enter the equivelent sub or any other procedure. This is true even when I click on a button in the main form.
ps I agree I don't like the original formatting and structuring of the program. This is actually an example program from the directx sdk which is only in c++ or c#. If I completely understood it I would probably just rewrite it before incorporating it into my program but unfortunately there's not much documention on it.
thank you again for your help.
|
|
|
|
|
Check the project properties ('Application' tab) for the VB project. You probably just need to select the right form as the startup form.
David Anton
http://www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
C++ to C# Converter: converts C++ to C#
C++ to VB Converter: converts C++ to VB
C++ to Java Converter: converts C++ to Java
Instant C++: converts C# to C++/CLI and VB to C++/CLI
|
|
|
|
|
sCmd = Chr(&H8s) & Chr(&H2s)
|
|
|
|
|
try:
Console.WriteLine(sCmd)
and check the output.
|
|
|
|
|
Hi,
&H8s is an integer value; the &H prefix indicates hexadecimal, the s suffix indicates
a short type; so it really is the number 8 (and there was no need to use hex in the first place).
Chr() is a function that turns a number into the character with that ASCII value.
And the & operator is used here to concatenate.
Therefore sCmd will be assigned a string consisting of two characters whose ASCII values
are 8 and 2.
If you were not able to discover this yourself, either by experimenting, or by googling,
I would suggest you work your way through a book on VB.NET to become familiar with it.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
|
|
The same as:
sCmd = (Convert.ToChar(8)).ToString() + (Convert.ToChar(2)).ToString()
---
single minded; short sighted; long gone;
|
|
|
|
|
It means someone came from VB.NET via VB6 and hasn't learned to write clean code, yet.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Please help me to filter my data on Crystal Report...if it is possible pls give me instructions...tnx
sunshine
|
|
|
|
|
Hii ,
i want to know the name of the control that is selected at runtime for runtime generated controls like label,rb,cb,tb ,etc . If i select a particular control at run time i want to know the name and it has to display in combobox without repetition of name ,and show properties of that control in propertygrid
s = Me.ActiveControl.Name if i am using this it is giving only panel1 as active control . i want the control i selected recently
Waiting For Ur Help...
DVSRIRAM
|
|
|
|
|
I don't know if it can count as a solution.
What you can do for textbox, richtextbox, checkbox is handle an event like Keydown, checkchanged, selectedindexchanged
In this example (sorry, in c#) i enable the savebutton when i modify a control. For you, see below the example.
private void CreateEventHandlers()
{
tbxC1.KeyDown += new KeyEventHandler(EnableSave);
tbxC2.KeyDown += new KeyEventHandler(EnableSave);
cmbxT1.SelectedIndexChanged += delegate { EnableSave(); };
tbxC3.KeyDown += new KeyEventHandler(EnableSave);
tbxC4.KeyDown += new KeyEventHandler(EnableSave);
}
private void EnableSave()
{
if (!m_bUpdating)
cobject.saveObject.Enabled = true;
}
private void EnableSave(object sender, KeyEventArgs e)
{
if (m_bUpdating)
return;
if (e.KeyCode == Keys.F1)
return;
else if (e.Control && e.KeyCode == Keys.C)
return;
else if (e.Control && e.KeyCode == Keys.V)
computerObjectFilter1.saveObject.Enabled = true;
else if (e.Control)
return;
else if (e.KeyCode == Keys.Up || e.KeyCode == Keys.Down || e.KeyCode == Keys.Left || e.KeyCode == Keys.Right || e.KeyCode == Keys.End || e.KeyCode == Keys.Home || e.KeyCode == Keys.PageUp || e.KeyCode == Keys.PageDown || e.KeyCode == Keys.Next || e.KeyCode == Keys.Insert)
return;
else
cobject.saveObject.Enabled = true;
}
For you, change the content of enable save to:
Console.WriteLine(sender.ToString)
Console.WriteLine(CType(sender, Button).Name.ToString())
The result will be something like:
System.Windows.Forms.Button, Text: &OK
btnOK
So you can make for every type of control a sort of enable save so you can cast them into the control so you can access all that you want, or you do the following:
1. Test Console.WriteLine(sender.ToString) with Instr() if it contains a Button, TextBox, ...
2. Than Cast correct resulting the test
You also asked Label, well, at the moment i don't have a solution for it. But if the one above is satisfying, you are a step ahead...
lmk
|
|
|
|
|
Thanks For the response ,
But i got it another way .
DVSRIRAM
|
|
|
|
|
Nice,
Can you share your solution? That is what this site is all about.
|
|
|
|
|
Firstly, an apology. My question isn't directly related to VB .NET but actually VBA in Office 2003. However, i have read these forums many times regarding VB .NET and C# questions and always have found responces friendly and informative. Hopefully the same can come from this question.
Simply, i have stored within an Access database OLE objects which are google maps of areas of the country. What i need to do is import this data into a word template. I know there are methods of using the Win32 API to store the data in memory and read directly to that from word, but i have no idea as to how this would be accomplished. What i was hoping for was a method similar to passing the data as a bookmark to word, but as bookmarks only accept Strings, i'm stuck for a way for this to work.
I have also been looking into another method of storing in the database the file path to the images, passing this path to word, then getting this path into the LoadPicture() method for the image. But after passing the path through as an bookmark, focus is lost on the bookmark which stores the path and i cannot reference it anymore.
Any advice you could offer to solve this problem would be very much appreciated. Although i do ask you that no messages contain the sentence "Stop using VBA!!!".... because i've been telling myself that enough already!
Many Thanks,
Plation
|
|
|
|
|
If no one can answer this question, would anyone be tempted in starting a project with me to figure out how to do this? When we find the answer we can post an article on codeproject about it.
Tempted? I'm sure im not the only person in the world who has wanted to do this.
|
|
|
|
|
Hi guys,
I am struggling to change the font style of a selected node in a treeview and a selected item in a listview control, your help is very much appreciated.
Regards
|
|
|
|
|
Got it and a bit embarrassed, its amazingly simple.
here are my lines, I used the AfterSelect event of the TreeView to set the font of the node, its parent and all its ancestors to bold, when another node is selected, i set the new node and its ancestors to bold, while returning the previously selected node to the normal font of the TreeView . By removing the while... statement in both methods, only the selected node is set to bold and back to normal. I know there are most likely better solutions but this one works fine.
<code>Dim previousSelectedNode as TreeNode
...
...
Private Sub Treeview1_AfterSelect(ByVal sender As System.Object, ByVal e As _ System.Windows.Forms.TreeViewEventArgs) Handles Treeview1.AfterSelect
Dim xnode As TreeNode
If previousSelectedNode IsNot Nothing Then DeSelectNode()
e.Node.NodeFont = New Font(Treeview1.Font, FontStyle.Bold)
xnode = e.Node
While xnode.Parent IsNot Nothing
xnode = xnode.Parent
xnode.NodeFont = New Font(Treeview1.Font, FontStyle.Bold)
End While
previousSelectedNode = e.Node
End Sub
'Deselecting a node
Private Sub DeSelectNode()
previousSelectedNode.NodeFont = Treeview1.Font
While previousSelectedNode.Parent IsNot Nothing
previousSelectedNode = previousSelectedNode.Parent
previousSelectedNode.NodeFont = Treeview1.Font
End While
End Sub
|
|
|
|
|
Hi i have a form with a datagridview and a listbox. The datagridview is bound to a table with 2 columns. the first column is a column that needs to store the name of a genre(specified in the listbox). the second column(which I have made invisible) is merely the name of the 24 hour template. what I mean by this is that the point of the datagrid is to allow a user to drag and drop genres to each hour of a day(so they need to drag 24 genres) onto the datagrid) and then save this as a 24 hour template. the datagrid is thus bound to the child table of a table called "24HourTemplate". when the user click save it will prompt for a name for the template and record the chnages to the 2 tables. how do I perform a drag and drop. I have enabled it for the tables but nothing happens?
Mr Oizo
|
|
|
|
|