How to place picture box image in label

LyndaCouch

New member
Joined
Mar 14, 2005
Messages
1
Programming Experience
Beginner
Is it possible to place a picture box image inside a label so that the 3-D border still shows all around the edges? Please give ideas or code examples.

Thanks,

Lynda Couch
 

Rohito

New member
Joined
Jun 26, 2005
Messages
4
Location
India
Programming Experience
5-10
Creation of Graphics object:

Method I:
You can draw over a label - or any other control, when it paints itself. The control raises a paint event.

The event arguments give you a graphics object, that allows you to paint on the label.

Method II:
If the drawing is of temperory nature. You can say label.CreateGraphics() to retrieve the graphics object.

Drawing the image:

To draw the image call the graphics object's .DrawImage routine.

Drawing the border:

Method I:
You can draw the border yourself, around the image you painted using DrawLine routine of the graphics object. To get the necessary coloured pen, you may use

Drawing.SystemPens.<member> (control dark, control dark dark, etc.)

Method II:
You can call the DrawEdge API.

VB.NET:
Private Declare Function DrawEdge Lib "user32.dll" (ByVal hdc As IntPtr, ByRef qrc As RECT, ByVal edge As Int32, ByVal grfFlags As Int32) As Int32
  
<StructLayout(LayoutKind.Sequential)> _ 
Private Structure RECT
 Public Left As Int32
 Public Top As Int32
 Public Right As Int32
 Public Bottom As Int32
End Structure
 
Private Const BDR_INNER As Int32 = &HC
Private Const BDR_OUTER As Int32 = &H3
Private Const BDR_RAISED As Int32 = &H5
Private Const BDR_RAISEDINNER As Int32 = &H4
Private Const BDR_RAISEDOUTER As Int32 = &H1
Private Const BDR_SUNKEN As Int32 = &HA
Private Const BDR_SUNKENINNER As Int32 = &H8
Private Const BDR_SUNKENOUTER As Int32 = &H2
Private Const EDGE_BUMP As Int32 = (BDR_RAISEDOUTER Or BDR_SUNKENINNER)
Private Const EDGE_ETCHED As Int32 = (BDR_SUNKENOUTER Or BDR_RAISEDINNER)
Private Const EDGE_RAISED As Int32 = (BDR_RAISEDOUTER Or BDR_RAISEDINNER)
Private Const EDGE_SUNKEN As Int32 = (BDR_SUNKENOUTER Or BDR_SUNKENINNER)

In the above constants, EDGE_SUNKEN is of your interest.

To use this though, you will need to get the hDC of the graphics object. You can do this by
Dim hDC as IntPtr = <graphics>.GetHDC()

After drawing on this hDC, don't forget to call <graphics>.ReleaseHDC(hDC)



 
Top Bottom