Hamish
Feb 9th, 2009, 02:51 PM
I hope this is easier to explain than it is to describe, but I doubt it.
I'm still working on the Canvas version of the PictureBox_ColorMap (http://www.vbforums.com/showthread.php?t=463553&highlight=picturebox_colormap).
Here's the code for my class:
Imports System.Windows.Controls
Imports System.Windows.Media.Imaging
Imports System.Drawing
Imports System.Windows.Input
Public Class ColorMapCanvas
Inherits Canvas
Private _ColorMap As Bitmap
Private _RaiseEventOnMouseMove As Boolean = True
Private _RaiseEventOnMouseLeftButtonDown As Boolean = True
Public Event ColorMapMouseLeftButtonDown(ByVal sender As Object, ByVal ReturnedColor As Color)
Public Event ColorMapMouseMove(ByVal sender As Object, ByVal ReturnedColor As Color)
Public Property ColorMap() As Bitmap
Get
Return _ColorMap
End Get
Set(ByVal value As Bitmap)
_ColorMap = value
End Set
End Property
Public Property RaiseEventOnMouseMove() As Boolean
Get
Return _RaiseEventOnMouseMove
End Get
Set(ByVal value As Boolean)
_RaiseEventOnMouseMove = value
End Set
End Property
Public Property RaiseEventOnMouseLeftButtonDown() As Boolean
Get
Return _RaiseEventOnMouseLeftButtonDown
End Get
Set(ByVal value As Boolean)
_RaiseEventOnMouseLeftButtonDown = value
End Set
End Property
Protected Overrides Sub OnMouseLeftButtonDown(ByVal e As MouseButtonEventArgs)
Dim p As System.Windows.Point = e.GetPosition(Me)
MyBase.OnMouseLeftButtonDown(e)
If _RaiseEventOnMouseLeftButtonDown Then
If Not _ColorMap Is Nothing AndAlso p.X <= _ColorMap.Width AndAlso p.Y <= _ColorMap.Height Then
RaiseEvent ColorMapMouseLeftButtonDown(Me, _ColorMap.GetPixel(CInt(p.X), CInt(p.Y)))
Else
RaiseEvent ColorMapMouseLeftButtonDown(Me, Nothing)
End If
End If
End Sub
Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)
Dim p As System.Windows.Point = e.GetPosition(Me)
MyBase.OnMouseMove(e)
If _RaiseEventOnMouseMove Then
If Not _ColorMap Is Nothing AndAlso p.X <= _ColorMap.Width AndAlso p.Y <= _ColorMap.Height Then
RaiseEvent ColorMapMouseMove(Me, _ColorMap.GetPixel(CInt(p.X), CInt(p.Y)))
Else
RaiseEvent ColorMapMouseMove(Me, Nothing)
End If
End If
End Sub
End Class
Now in my XAML (in another project, I keep my custom controls together in a seperate project) I have this:
<Controls:ColorMapCanvas x:Name="MapCanvas" Width="8980" Height="5160">
<Canvas.Background>
<ImageBrush x:Name="CanvasBrush" ImageSource="/Resources/TempMainMap.png" ScrollViewer.CanContentScroll="True"/>
</Canvas.Background>
</Controls:ColorMapCanvas>
I want to add setting the ColorMap property of my ColorMapCanvas control to use another resource in the same project as the XAML. I tried using:
<Controls:ColorMapCanvas x:Name="MapCanvas" ColorMap="/Resources/TempColorMap.png" Width="8980" Height="5160">
But that gives me an error "Parameter is not valid." on the ColorMap property.
I can think of 2 reasons this may happen, but can't think of a solution for either.
The "/Resources/TempColorMap.png" isn't a Bitmap, but a BitmapSource.
The ColorMapCanvas control can't access the image to be used because it's in another project.
So, can anyone tell me which of these (or something I haven't thought of) it is, and what to do about it?
I'm still working on the Canvas version of the PictureBox_ColorMap (http://www.vbforums.com/showthread.php?t=463553&highlight=picturebox_colormap).
Here's the code for my class:
Imports System.Windows.Controls
Imports System.Windows.Media.Imaging
Imports System.Drawing
Imports System.Windows.Input
Public Class ColorMapCanvas
Inherits Canvas
Private _ColorMap As Bitmap
Private _RaiseEventOnMouseMove As Boolean = True
Private _RaiseEventOnMouseLeftButtonDown As Boolean = True
Public Event ColorMapMouseLeftButtonDown(ByVal sender As Object, ByVal ReturnedColor As Color)
Public Event ColorMapMouseMove(ByVal sender As Object, ByVal ReturnedColor As Color)
Public Property ColorMap() As Bitmap
Get
Return _ColorMap
End Get
Set(ByVal value As Bitmap)
_ColorMap = value
End Set
End Property
Public Property RaiseEventOnMouseMove() As Boolean
Get
Return _RaiseEventOnMouseMove
End Get
Set(ByVal value As Boolean)
_RaiseEventOnMouseMove = value
End Set
End Property
Public Property RaiseEventOnMouseLeftButtonDown() As Boolean
Get
Return _RaiseEventOnMouseLeftButtonDown
End Get
Set(ByVal value As Boolean)
_RaiseEventOnMouseLeftButtonDown = value
End Set
End Property
Protected Overrides Sub OnMouseLeftButtonDown(ByVal e As MouseButtonEventArgs)
Dim p As System.Windows.Point = e.GetPosition(Me)
MyBase.OnMouseLeftButtonDown(e)
If _RaiseEventOnMouseLeftButtonDown Then
If Not _ColorMap Is Nothing AndAlso p.X <= _ColorMap.Width AndAlso p.Y <= _ColorMap.Height Then
RaiseEvent ColorMapMouseLeftButtonDown(Me, _ColorMap.GetPixel(CInt(p.X), CInt(p.Y)))
Else
RaiseEvent ColorMapMouseLeftButtonDown(Me, Nothing)
End If
End If
End Sub
Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)
Dim p As System.Windows.Point = e.GetPosition(Me)
MyBase.OnMouseMove(e)
If _RaiseEventOnMouseMove Then
If Not _ColorMap Is Nothing AndAlso p.X <= _ColorMap.Width AndAlso p.Y <= _ColorMap.Height Then
RaiseEvent ColorMapMouseMove(Me, _ColorMap.GetPixel(CInt(p.X), CInt(p.Y)))
Else
RaiseEvent ColorMapMouseMove(Me, Nothing)
End If
End If
End Sub
End Class
Now in my XAML (in another project, I keep my custom controls together in a seperate project) I have this:
<Controls:ColorMapCanvas x:Name="MapCanvas" Width="8980" Height="5160">
<Canvas.Background>
<ImageBrush x:Name="CanvasBrush" ImageSource="/Resources/TempMainMap.png" ScrollViewer.CanContentScroll="True"/>
</Canvas.Background>
</Controls:ColorMapCanvas>
I want to add setting the ColorMap property of my ColorMapCanvas control to use another resource in the same project as the XAML. I tried using:
<Controls:ColorMapCanvas x:Name="MapCanvas" ColorMap="/Resources/TempColorMap.png" Width="8980" Height="5160">
But that gives me an error "Parameter is not valid." on the ColorMap property.
I can think of 2 reasons this may happen, but can't think of a solution for either.
The "/Resources/TempColorMap.png" isn't a Bitmap, but a BitmapSource.
The ColorMapCanvas control can't access the image to be used because it's in another project.
So, can anyone tell me which of these (or something I haven't thought of) it is, and what to do about it?