views:

197

answers:

3

 

  protected override void OnPaint(PaintEventArgs e) 
  { 
      base.OnPaint(e); 
      Bitmap bmp = new Bitmap("C:\\test.bmp"); 
      e.Graphics.DrawImage(bmp, 0, 0); 
  }

I tried the above code but an error saying could not find part of the path is shown in the line

Bitmap bmp = new Bitmap("C:\\test.bmp");

what could be the error?

+1  A: 

It should be "C:\\test.bmp". Note the double backslash!

You can also use this string literal notation: @"C:\test.bmp"

Dmitry Brant
i tried that too but i am getting the same error
Timmi
Wrong. CE has no concept of drives.
ctacke
+3  A: 

If this is a .Net Compact Framework application (as suggested by the windows-mobile tag), then there is no such thing as C:\test.bmp on a WinMo device. Try "\\test.bmp", assuming that you actually have a file named "test.bmp" at the root level of your device.

MusiGenesis
i am new to windows mobile so i dont know much abut the device. Can you please give me a little detailed explanation, how to solve the error
Timmi
You solve the error by putting the actual path to your file. It might be where your app is, it might be somewhere else. Only you can tell where that is.
ctacke
@Timmi: on a WinMo device, paths start with just a backslash, so if you have your Bitmap file in the Windows folder, the path would be `\Windows\test.bmp`. You can't access files on your PC from your WinMo device (at least not easily), so you need to first copy `test.bmp` from your PC onto the device somewhere. ActiveSync will let you do this on a pre-Vista computer, and on Vista or later you should be able to just browse to your attached device.
MusiGenesis
@Timmi: an easier way, however, would be to load the bitmap file into an invisible PictureBox on your form in the designer (by setting its Image property), and then change your code to `e.Graphics.DrawImage(pictureBox1.Image, 0, 0)`.
MusiGenesis
A: 

Is it a high resolution image? which you are trying to load,

Shadow