Take the following steps to start a project and to add some code that will demonstrate the various interactive modes of the LEADTOOLS Silverlight Control and the Pan Viewer:
Open the Page.xaml file and copy the below XAML code into the editor:
[XAML]
<UserControl x:Class="Load_And_Display.MainPage"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:Leadtools_Windows_Controls="clr-namespace:Leadtools.Windows.Controls;assembly=Leadtools.Windows.Controls"Width="800" Height="600"><Grid x:Name="LayoutRoot" Background="White"><Grid.ColumnDefinitions><ColumnDefinition Width="5*"/><ColumnDefinition Width="2*"/></Grid.ColumnDefinitions><ScrollViewer VerticalScrollBarVisibility="Disabled" HorizontalScrollBarVisibility="Disabled" Grid.Column="0"><StackPanel Orientation="Vertical" ><Button Name="myButton" Content="Load" FontSize="30" Click="Button_Click" Height="40"></Button><Leadtools_Windows_Controls:RasterImageViewer x:Name="viewerControl" SizeMode="Normal" Height="550"></Leadtools_Windows_Controls:RasterImageViewer></StackPanel></ScrollViewer><ScrollViewer VerticalScrollBarVisibility="Disabled" HorizontalScrollBarVisibility="Disabled" Grid.Column="1"><StackPanel Orientation="Vertical" ><TextBlock Text="Pan Window :"/><Leadtools_Windows_Controls:ImagePanViewer x:Name="_imagePanViewer" Width="150" Height="150" HorizontalAlignment="Left"></Leadtools_Windows_Controls:ImagePanViewer><TextBlock Text="Interactive Mode :"/><ComboBox Name="_cmbInteractiveMode" SelectedIndex="0" Width="200" HorizontalAlignment="Left" SelectionChanged="ComboBox_SelectionChanged"><ComboBoxItem Content="None"/><ComboBoxItem Content="Pan"/><ComboBoxItem Content="Center At"/><ComboBoxItem Content="Zoom To"/><ComboBoxItem Content="Scale"/><ComboBoxItem Content="Magnify Glass"/></ComboBox></StackPanel></ScrollViewer></Grid></UserControl>
Switch to Page.xaml code view (right-click Page.xaml in the solution explorer then select View Code) and add the following class function:
Private Sub ComboBox_SelectionChanged(ByVal sender As Object, ByVal e As SelectionChangedEventArgs)If _cmbInteractiveMode Is Nothing OrElse _cmbInteractiveMode.SelectedItem Is Nothing ThenReturnEnd IfDim item As String = (CType(IIf(TypeOf _cmbInteractiveMode.SelectedItem Is ComboBoxItem, _cmbInteractiveMode.SelectedItem, Nothing), ComboBoxItem)).Content.ToString()Select Case itemCase "Pan"viewerControl.InteractiveMode = Leadtools.Windows.Controls.InteractiveMode.PanCase "Center At"viewerControl.InteractiveMode = Leadtools.Windows.Controls.InteractiveMode.CenterAtCase "Magnify Glass"viewerControl.InteractiveMode = Leadtools.Windows.Controls.InteractiveMode.MagnifyGlassCase "Scale"viewerControl.InteractiveMode = Leadtools.Windows.Controls.InteractiveMode.ScaleCase "Zoom To"viewerControl.InteractiveMode = Leadtools.Windows.Controls.InteractiveMode.ZoomToCase ElseviewerControl.InteractiveMode = Leadtools.Windows.Controls.InteractiveMode.NoneEnd SelectEnd Sub
private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e){if (_cmbInteractiveMode == null || _cmbInteractiveMode.SelectedItem == null)return;string item = (_cmbInteractiveMode.SelectedItem as ComboBoxItem).Content.ToString();switch (item){case "Pan":viewerControl.InteractiveMode = Leadtools.Windows.Controls.InteractiveMode.Pan;break;case "Center At":viewerControl.InteractiveMode = Leadtools.Windows.Controls.InteractiveMode.CenterAt;break;case "Magnify Glass":viewerControl.InteractiveMode = Leadtools.Windows.Controls.InteractiveMode.MagnifyGlass;break;case "Scale":viewerControl.InteractiveMode = Leadtools.Windows.Controls.InteractiveMode.Scale;break;case "Zoom To":viewerControl.InteractiveMode = Leadtools.Windows.Controls.InteractiveMode.ZoomTo;break;default:viewerControl.InteractiveMode = Leadtools.Windows.Controls.InteractiveMode.None;break;}}
Update the Button_Click event as shown below:
Private Sub Button_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)TryDim ofd As OpenFileDialog = New OpenFileDialog()If ofd.ShowDialog() = True ThenDim fileStream As FileStream = ofd.File.OpenRead()TryDim codecs As RasterCodecs = New RasterCodecs()viewerControl.Image = codecs.Load(fileStream)_imagePanViewer.Source = viewerControlFinallyfileStream.Dispose()End TryEnd IfCatch ex As ExceptionMessageBox.Show(ex.Message)End TryEnd Sub
private void Button_Click(object sender, RoutedEventArgs e){try{OpenFileDialog ofd = new OpenFileDialog();if (ofd.ShowDialog() == true){using (FileStream fileStream = ofd.File.OpenRead()){RasterCodecs codecs = new RasterCodecs();viewerControl.Image = codecs.Load(fileStream);_imagePanViewer.Source = viewerControl;}}}catch (Exception ex){MessageBox.Show(ex.Message);}}
Build, and Run the program to test it.
Click the "Load" button, and select an image. NOTE: if you encounter an "Invalid File Format" or "Feature Not Supported" exception, please refer to the topic Invalid File Format/Feature Not Supported.
Raster .NET | C API | C++ Class Library | JavaScript HTML5
Document .NET | C API | C++ Class Library | JavaScript HTML5
Medical .NET | C API | C++ Class Library | JavaScript HTML5
Medical Web Viewer .NET
