Click here to Skip to main content
15,881,248 members
Articles / Mobile Apps / Windows Mobile

Need a flashlight for your PocketPC?

Rate me:
Please Sign up or sign in to vote.
2.40/5 (27 votes)
18 Apr 2004CPOL2 min read 74.4K   67   13   12
This is an article on how to make a flashlight out of your PocketPC

Introduction

This is one of the simplest applications ever created. It just sets the entire screen to white and you can use it as a flashlight. This application was inspired by my brother's boss. His boss had at one time had a program that turned the screen completely white so that it could be used as a flashlight. I decided that this would be a good starting point for some PocketPC apps.

Background

This implementation was surprisingly tricky. Since the .NET Compact Framework does not have all of the functionality of the full .NET Framework, I had to work around a few things. First, I had planned to draw the images using pictureBox1.CreateGraphics(), but that gave a "not supported" error. So, I just cheated and made a regular windows application and just saved the image to file. Now the application just loads a picture instead of drawing it. Next, I had to figure out how to adjust the backlight. I still have not figured out how to do that. So, once again, I cheated and just set the back color to a grey scale based on where you pressed on the scale. Last, I found that picture boxes had no click event. This is the only one where I didn't cheat. I loaded the images into the picture boxes, but then on the form's graphics control I did (form graphics).DrawImage(pictureBox1.Image, 0, 0). Past that, it was pretty easy to make. I purposely put the close button on the opposite side so that you did not close it on accident. You'll also notice that I have a timer that just runs once. I found that this is the best way that I came up with to configure the controls once the form is viewable.

Using the code

Really, there should be no reason that this code would need to be altered in any way. That doesn't mean that you shouldn't. This has only one class and it was created by Visual Studio. Really, there isn't anything special about it. This does have one special function to truncate the decimal.

C#
private int Trunc(double d) 
 // used to take the int value without the decimal place
{
  string i = d.ToString().Split(((string)(".")).ToCharArray())[0]; 
   // splits the double vaule at the decimal and only takes the first part
  return int.Parse(i); // converts the string to and int
}

To use this you just call it by saying Trunc(3.14159). This function would return 3.

Points of Interest

The main thing I learned from this application is that it is not as easy as you think to capture click events from a picture box. Otherwise, this is just a warm-up application.

History

There is no history for this app. It has one version. The end.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Generalbacklight Pin
Embex21-Nov-07 6:03
Embex21-Nov-07 6:03 
Questionso there is no way to draw image on picturebox? Pin
raybristol14-Aug-05 6:54
raybristol14-Aug-05 6:54 
AnswerRe: so there is no way to draw image on picturebox? Pin
Simon McKenzie5-Mar-08 12:48
Simon McKenzie5-Mar-08 12:48 
There is a way. Just create a graphics object on the picturebox's image (or make a new image), then paint into it:

Graphics g = Graphics.FromImage(image);

g.DrawEllipse(new Pen(Color.Black), 1, 1, 30, 30);

g.Dispose();

I don't know if the dispose is still necessary, but I used to get a lot of memory leaks if I didn't explicitly dispose of objects used when painting.


Alternatively, create your own class that inherits from picturebox and override the OnPaint method.
GeneralRe: trunc function ?? Pin
Erik_Egsgard22-Jun-04 4:09
Erik_Egsgard22-Jun-04 4:09 
GeneralAhh at last - a use for the Pocket PC ! Pin
Bob100020-Apr-04 12:57
professionalBob100020-Apr-04 12:57 
QuestionIs it serious ? Pin
BenoitM19-Apr-04 22:29
BenoitM19-Apr-04 22:29 
AnswerRe: Is it serious ? Pin
MichaelCoder20-Apr-04 9:58
MichaelCoder20-Apr-04 9:58 
Questiontrunc function ?? Pin
sriramsinga19-Apr-04 9:01
sriramsinga19-Apr-04 9:01 
AnswerRe: trunc function ?? Pin
MichaelCoder20-Apr-04 10:01
MichaelCoder20-Apr-04 10:01 
Generalipaq sdk Pin
sriramsinga19-Apr-04 8:57
sriramsinga19-Apr-04 8:57 
GeneralRe: ipaq sdk Pin
MichaelCoder20-Apr-04 10:02
MichaelCoder20-Apr-04 10:02 
GeneralRe: ipaq sdk Pin
jkutsor21-Apr-04 1:41
jkutsor21-Apr-04 1:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.