Solved

Raised 3D Effect for PictureBox

Posted on 2002-05-02
5
313 Views
Last Modified: 2008-02-01
Probably my final question for a while in this topic area...

For a PictureBox control, how can I give it a "raised" 3D effect? If you make it 3D instead of Flat for Appearance, it's always "sunken" into the form. There has to be an easy way to do this.
0
Comment
Question by:dplambert
  • 3
5 Comments
 
LVL 22

Accepted Solution

by:
rspahitz earned 50 total points
ID: 6986495
Try this:
1) add a picturebox named Picture1
2) set the picturebox borderstyle=none
3) add a line control INTO the picturebox, named Line1
4) set the line's index=0
5) add this code where appropriate (I put it in form_load):

Private Sub Form_Load()
  Dim sglRightEdge As Single
  Dim sglBottomEdge As Single
 
  sglRightEdge = Picture1.ScaleWidth - Line1(0).BorderWidth - 10
  sglBottomEdge = Picture1.ScaleHeight - Line1(0).BorderWidth - 10
  ' right edge
  With Line1(0)
    .X1 = sglRightEdge
    .Y1 = 0
    .X2 = sglRightEdge
    .Y2 = sglBottomEdge
  End With
 
  ' bottom edge
  Load Line1(1)
  With Line1(1)
    .X1 = 0
    .Y1 = sglBottomEdge
    .X2 = sglRightEdge
    .Y2 = sglBottomEdge
    .Visible = True
  End With
 
  ' top edge
  Load Line1(2)
  With Line1(2)
    .X1 = 0
    .Y1 = 0
    .X2 = sglRightEdge
    .Y2 = 0
    .BorderColor = vbWhite
    .Visible = True
  End With
 
  Load Line1(3)
  With Line1(3)
    .X1 = 0
    .Y1 = 0
    .X2 = 0
    .Y2 = sglBottomEdge
    .BorderColor = vbWhite
    .Visible = True
  End With
End Sub
0
 
LVL 15

Expert Comment

by:ameba
ID: 6986882
It is also possible to use DrawEdge API in Paint event of the Form.  Let me know if you want code sample (uses DrawEdge, InflateRect, GetDC).
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 6986992
Good point, Ameba.

This should work better (without the API):

Private Sub Form_Paint()
  Picture1.Line (0, 0)-(Picture1.ScaleWidth, Picture1.ScaleHeight), vbWhite, B
  Picture1.Line (-10, -10)-(Picture1.ScaleWidth - 10, Picture1.ScaleHeight - 10), vbBlack, B
End Sub

(Make sure that the picturebox has the autoredraw property set to True.)
0
 
LVL 3

Author Comment

by:dplambert
ID: 6987478
Why isn't there a property setting for this? Something real simple?
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 6987484
The reason is because it was not part of the original design.

If you want, you can simply create your own picturebox to support such a property by creating a new user control and adding more styles to the borderstyle setting...then you can call it a DPLPictureBox!
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now