[WPFピクチャ ビューアーの作成]をダウンロードする。
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
xmlns:self="clr-namespace:WpfAPictureViewer"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="30" />
</Grid.RowDefinitions>
<WindowsFormsHost x:Name="wfHost" Grid.Row="0">
<self:UserControl1 x:Name="myControl" />
</WindowsFormsHost>
<StackPanel Grid.Row="1" Name="StackPanel1" Orientation="Horizontal">
<CheckBox Content="Stretch" Height="16" Width="100" Name="CheckBox1" IsChecked="True" />
<Button Content="Show a picture" Height="23" Name="Button1" />
<Button Content="Clear the picture" Height="23" Name="Button2" />
<Button Content="Set the background color" Height="23" Name="Button3" />
<Button Content="Close" Height="23" Name="Button4" />
</StackPanel>
</Grid>
</Window>
Class MainWindow
Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button1.Click
If myControl.OpenFileDialog1.ShowDialog() = Forms.DialogResult.OK Then
myControl.PictureBox1.Load(myControl.OpenFileDialog1.FileName)
End If
End Sub
Private Sub Button2_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button2.Click
myControl.PictureBox1.Image = Nothing
End Sub
Private Sub Button3_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button3.Click
If myControl.ColorDialog1.ShowDialog() = Forms.DialogResult.OK Then
myControl.PictureBox1.BackColor = myControl.ColorDialog1.Color
End If
End Sub
Private Sub Button4_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button4.Click
Close()
End Sub
Private Sub CheckBox1_Checked(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles CheckBox1.Checked
myControl.PictureBox1.SizeMode = Forms.PictureBoxSizeMode.Zoom
End Sub
Private Sub CheckBox1_Unchecked(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles CheckBox1.Unchecked
myControl.PictureBox1.SizeMode = Forms.PictureBoxSizeMode.StretchImage
End Sub
End Class