Class MainWindowクラスの全コード
Class MainWindow
Dim LeftButtonDown As Boolean = False
Public Sub New()
' この呼び出しはデザイナーで必要です。
InitializeComponent()
AddHandler border1.MouseRightButtonDown, AddressOf border1_MouseRightButtonDown
AddHandler border1.MouseRightButtonUp, AddressOf border1_MouseRightButtonUp
AddHandler border2.MouseWheel, AddressOf border2_MouseWheel
AddHandler canvas1.MouseRightButtonDown, AddressOf canvas1_MouseRightButtonDown
AddHandler canvas1.MouseRightButtonUp, AddressOf canvas1_MouseRightButtonUp
End Sub
Private Sub border1_MouseRightButtonDown(ByVal sender As Object, ByVal e As MouseButtonEventArgs)
e.Handled = True
End Sub
Private Sub border1_MouseRightButtonUp(ByVal sender As Object, ByVal e As MouseButtonEventArgs)
MessageBox.Show("右クリックしました")
End Sub
Dim colorValue As Integer = 0
Private Sub border2_MouseWheel(ByVal sender As Object, ByVal e As MouseWheelEventArgs)
colorValue = colorValue + (e.Delta / 4)
If colorValue < 0 Then colorValue = 0
If colorValue > 255 Then colorValue = 255
Dim c As Color = Color.FromArgb(255, 255, _
Convert.ToByte(255 - colorValue), Convert.ToByte(colorValue))
border2.Background = New SolidColorBrush(c)
End Sub
Private Sub canvas1_MouseRightButtonDown(ByVal sender As Object, ByVal e As MouseButtonEventArgs)
e.Handled = True
End Sub
Private Sub canvas1_MouseRightButtonUp(ByVal sender As Object, ByVal e As MouseButtonEventArgs)
Dim pt As Point = e.GetPosition(canvas1)
contextMenu.SetValue(Canvas.LeftProperty, pt.X)
contextMenu.SetValue(Canvas.TopProperty, pt.Y)
contextMenu.IsOpen = True
End Sub
Private Sub menu_MouseLeftButtonUp(ByVal sender As Object, ByVal e As MouseButtonEventArgs)
If TypeOf sender Is TextBlock Then
Dim tblock As TextBlock = CType(sender, TextBlock)
Dim pinfo As System.Reflection.PropertyInfo _
= GetType(Colors).GetProperty(CType(tblock.Text, String))
Dim c As Color
If pinfo Is Nothing Then c = Colors.Black Else c = pinfo.GetValue(Nothing, Nothing)
canvas1.Background = New SolidColorBrush(c)
End If
contextMenu.IsOpen = False
End Sub
End Class