.Net CF - working with events in C#

  • Thread starter Thread starter David A. Mathew
  • Start date Start date
D

David A. Mathew

I noticed when trying write an application for PocketPC and deciding to
program in VB or C# that for event handling VB seems to have more options
than C#. Specifically I want to be able to respond to mouse clicks on a
pictureBox control. VB clearly has a _click event for pictureboxes amoung
many other events, However C# only had one event... something like
_parentChanged and that was it. Is there a way I can add event handlers like
_click to a pictureBox (or any other component) in C#? I could just switch
to VB but my experience so far is in C and Java so I feel more at home with
C# than VB.

David A. Mathew
(e-mail address removed)
 
David,

The Compact Framework PictureBox is not 'clickable' in the traditional
sense.

Handle the mouseup event to respond to a 'click' on a PictureBox.

Example below of converting pixels to latlong for a MapPoint Web Service
map in a picturebox.

// define your event handler
pbMap.MouseUp += new System.Windows.Forms.MouseEventHandler(pbMap_MouseUp);

// code your event handler
private void pbMap_MouseUp(object sender, MouseEventArgs e)
{
//Define a PixelCoord
PixelCoord point = new PixelCoord();
point.X = e.X;
point.Y = e.Y;

this.ConvertOnClient(point);
}

-Darren
 
The same events are available in VB and C# - they are in effect no different
as far as feature sets go (well C# does have unsafe code, which I love, but
it's not often needed). I can only guess that you're looking at the events
the UI says are available. Mistake. It's usually wrong. It lists some
that aren't available, and often doesn't list those that are.

-Chris
 
Hi David,

Yes, the porperty browser doesn't list the click event, but it is there and
is supported by CF for PictureBox.
But because it is not in the property browser you need to hooked in the
code.
All .NET languages use the same framework's assemblies thus, it is not
possible one language to have some event, but other not.
Event section in MSDN doesn't specify explicitly if an event is supported by
CF or not. That can be found if you look at the respective OnXXX method.
OnClick is supported by CF so the Click event.
I run a test on Windows CE .NET and Pocked PC emulators. Yes, it fires click
event.
 
Back
Top