Picturebox - Missing Functions...

  • Thread starter Thread starter Christian Stelte
  • Start date Start date
C

Christian Stelte

Hello!

Last Year i wrote an eVB program using pictureboxes. Now I have to port this
to the CF using c#.

I'm now missing several properties:

- There is no border around the box
- To that effect no 'button-animation' when the box was clicked
- I found no function to draw text on it (in eVB it was: PBox.DrawText)

Any Ideas how I solve this Problems?

Regards

Chris

Btw: How I find the current Application Path? Like Application.StartupPath
in the BigBrother-Framework.
 
Christian Stelte said:
- I found no function to draw text on it (in eVB it was: PBox.DrawText)

I think I've found a solution, but it generates a
'System.NotSupportedException':

code:
------
private System.Windows.Forms.PictureBox[] PBox = new PictureBox[32];
PBox[0] = new PictureBox();
this.Controls.Add(PBox[0]);
PBox[0].Location = new System.Drawing.Point(80, 40);
PBox[0].Size = new System.Drawing.Size(80, 80);
PBox[0].BackColor = System.Drawing.Color.IndianRed;
PBox[0].Image = new Bitmap( @"\Program Files\test\418.bmp");
String drawString = "Sample Text";
Font drawFont = new Font("Arial", 16, FontStyle.Regular);
SolidBrush drawBrush = new SolidBrush(Color.Black);
//
// next line generates the exception:
//
Graphics g = PBox[0].CreateGraphics();
g.DrawString(drawString, drawFont, drawBrush, 10.0F, 70.0F);
g.Dispose();
 
I think I've found a solution, but it generates a
'System.NotSupportedException':

In another IDE I got a complete exception:

---
An unhandled exception of type 'System.NotSupportedException' occurred in
System.Windows.Forms.dll
Additional information: NotSupportedException
---

Did anyone used PictureBox1.CreateGraphics() succesfully? Maybe it was a bug
in the CF? I mention this cause in this posting he have the same problem:

http://forums.belution.com/en/csharp/000/000/93s.shtml

Chris
 
The CreateGraphics method is inherited from the Control class but is not
implemented on the individual controls. You will have to derive a custom
control from the Control class.

The CreateGraphics() is supported only for the Control and Form classes.
Calling this method for any other classes will throw NotSupportedException.
 
CreateGraphics is not supported on the PictureBox. From the new CF FAQ:
2.5. Why does CreateGraphics fail when I call it on a TextBox?
Only the Control and Form classes support Control.CreateGraphics().
(http://msdn.microsoft.com/mobility/prodtechinfo/devtools/netcf/FAQ/default.
aspx)

Your best bet is to just create a custom control that allows you to draw the
image and then draw some text over top. What are you trying to accomplish
with the picture and the text, a graphical button?

If you haven't determined how to get the app path yet:
http://msdn.microsoft.com/library/d...n-us/dncfhowto/html/HOWTOExecutingAppPath.asp
 
Tim Wilson said:
What are you trying to accomplish
with the picture and the text, a graphical button?

Yes, or is the a chance to get an image in a Button?

Chris
 
Tim Wilson said:
Your best bet is to just create a custom control that allows you to draw the
image and then draw some text over top.

Using Form.CreateGraphics() works! Great! :-)

But

- It write the text under the PictureBox (z-Order). Ok, the PBox could not
behind the form.
- If I would create a Custom Control (until now I don't know how...) how do
I paint the Imagefile? Decode and draw the file Pixel by Pixel?
- Or do I derive from the PBox Class? If yes how do I align the image on top
of the CustomControl to get space for the text?

Any sample available?

Chris
 
Back
Top