Как преобразовать этот код сканера C# код в WPF VB
Я хочу преобразовать этот код C# в WPF vb
я также использовал веб-сайт, как converter.telerik.com его преобразуют, но какой-то код неверен.
поэтому, пожалуйста, помогите мне преобразовать этот код, я новичок в WPF VB и C# также.
заранее спасибо.
Что я уже пробовал:
Вот код xaml.
<Window x:Class="TestAppWpf.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="TestAppWpf" Height="450" Width="500"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" /> <ColumnDefinition Width="*" /> </Grid.ColumnDefinitions> <StackPanel> <GroupBox Header="Source"> <StackPanel> <RadioButton Name="SourceFromTwainUI" IsChecked="True"> Use TWAIN UI </RadioButton> <Button Margin="5" IsEnabled="{Binding ElementName=SourceFromTwainUI, Path=IsChecked}" Click="OnSelectSourceButtonClick"> Select Source </Button> <RadioButton Name="SourceUserSelected">Manual source</RadioButton> <ComboBox Name="ManualSource" IsEnabled="{Binding ElementName=SourceUserSelected, Path=IsChecked}" /> </StackPanel> </GroupBox> <Button Margin="5" Name="ScanButton" Click="scanButton_Click">Scan</Button> <Separator /> <CheckBox Margin="5" Name="UseAdfCheckBox">Use ADF</CheckBox> <CheckBox Margin="5" Name="UseDuplexCheckBox">Use Duplex</CheckBox> <Separator /> <CheckBox Margin="5" Name="UseUICheckBox">Use UI</CheckBox> <CheckBox Margin="5" Name="ShowProgressCheckBox">Show Progress</CheckBox> <Separator /> <CheckBox Margin="5" Name="BlackAndWhiteCheckBox">B & W</CheckBox> <CheckBox Margin="5" Name="GrabAreaCheckBox">Grab Area</CheckBox> <Separator /> <CheckBox Margin="5" Name="AutoDetectBorderCheckBox">Auto Detect Border</CheckBox> <CheckBox Margin="5" Name="AutoRotateCheckBox">Auto Rotate</CheckBox> <Separator /> <Button Margin="5" Click="OnSaveButtonClick">Save</Button> </StackPanel> <Border Grid.Column="1" BorderThickness="3, 0, 0, 0" BorderBrush="Gray"> <Image Margin="5" Name="MainImage" Stretch="UniformToFill" /> </Border> </Grid> </Window>
and code behind C# code is : =
using System; using System.Drawing; using System.IO; using System.Windows; using System.Windows.Media.Imaging; using System.Windows.Interop; using Microsoft.Win32; using TwainDotNet; using TwainDotNet.TwainNative; using TwainDotNet.Wpf; using TwainDotNet.Win32; namespace TestAppWpf { public partial class Window1 : Window { private static AreaSettings AreaSettings = new AreaSettings(Units.Centimeters, 0.1f, 5.7f, 0.1F + 2.6f, 5.7f + 2.6f); private Twain _twain; private ScanSettings _settings; private Bitmap resultImage; public Window1() { InitializeComponent(); Loaded += delegate { _twain = new Twain(new WpfWindowMessageHook(this)); _twain.TransferImage += delegate(Object sender, TransferImageEventArgs args) { if (args.Image != null) { resultImage = args.Image; IntPtr hbitmap = new Bitmap(args.Image).GetHbitmap(); MainImage.Source = Imaging.CreateBitmapSourceFromHBitmap( hbitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); Gdi32Native.DeleteObject(hbitmap); } }; _twain.ScanningComplete += delegate { IsEnabled = true; }; var sourceList = _twain.SourceNames; ManualSource.ItemsSource = sourceList; if (sourceList != null && sourceList.Count > 0) ManualSource.SelectedItem = sourceList[0]; }; } private void OnSelectSourceButtonClick(object sender, RoutedEventArgs e) { _twain.SelectSource(); } private void scanButton_Click(object sender, RoutedEventArgs e) { IsEnabled = false; _settings = new ScanSettings { UseDocumentFeeder = UseAdfCheckBox.IsChecked, ShowTwainUI = UseUICheckBox.IsChecked ?? false, ShowProgressIndicatorUI = ShowProgressCheckBox.IsChecked, UseDuplex = UseDuplexCheckBox.IsChecked, Resolution = (BlackAndWhiteCheckBox.IsChecked ?? false) ? ResolutionSettings.Fax : ResolutionSettings.ColourPhotocopier, Area = !(GrabAreaCheckBox.IsChecked ?? false) ? null : AreaSettings, ShouldTransferAllPages = true, Rotation = new RotationSettings { AutomaticRotate = AutoRotateCheckBox.IsChecked ?? false, AutomaticBorderDetection = AutoDetectBorderCheckBox.IsChecked ?? false } }; try { if (SourceUserSelected.IsChecked == true) _twain.SelectSource(ManualSource.SelectedItem.ToString()); _twain.StartScanning(_settings); } catch (TwainException ex) { MessageBox.Show(ex.Message); } IsEnabled = true; } private void OnSaveButtonClick(object sender, RoutedEventArgs e) { if (resultImage != null) { var saveFileDialog = new SaveFileDialog(); if (saveFileDialog.ShowDialog() == true) resultImage.Save(saveFileDialog.FileName); } } } }
Graeme_Grant
Пожалуйста, переформатируйте свой код правильно.