Solved

Raised 3D Effect for PictureBox

Posted on 2002-05-02
5
339 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

726 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