To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
VBForums  

VB Wire News
MSDN Subscribers: Download the VS 2010 Release Candidate
MSDN Subscribers: Download the VS 2010 Release Candidate
Sell Your Code and Make Money?
Creating your own Tetris game using VB.NET
Article :: Improving Software Economics, Part 4 of 7: Top 10 Principles of Iterative Software Management



Go Back   VBForums > Visual Basic > Visual Basic 6 and Earlier

Reply Post New Thread
 
Thread Tools Search this Thread Display Modes
Old Sep 24th, 2004, 10:56 AM   #1
Tomexx
Hyperactive Member
 
Join Date: Aug 99
Location: Ont, Canada, Earth
Posts: 451
Tomexx is an unknown quantity at this point (<10)
Center picture in picture box (code needs polishing)

Hi,
TO TRY THE CODE: place a picturebox on a form and name it DOWN

I want to use picture box as a command button in order to avoid the focus rectangle when the regular command button is down.
To do that I draw edge at runtime around my picture box (see code below)

The button part works well (picture box looks like the button)

The only part I have trouble with is centering the picture in the picture box. I've got the code from Arron Young and it works on a picture box but when I combine it with my code to draw the edges around the picture box it doesn't center.

Anyway here's the code (the last sub - CenterPicture() is the one I want to use with the rest of my code.... so far unsuccessfully.

VB Code:
  1. Private Declare Function DrawEdge Lib "user32" (ByVal hDC As Long, qrc As RECT, ByVal Edge As Long, ByVal grfFlags As Long) As Long
  2. Private Type RECT
  3.     Left As Long
  4.     Top As Long
  5.     Right As Long
  6.     Bottom As Long
  7. End Type
  8. Private Const BDR_RAISEDOUTER = &H1
  9. Private Const BDR_SUNKENOUTER = &H2
  10. Private Const BDR_RAISEDINNER = &H4
  11. Private Const BDR_SUNKENINNER = &H8
  12. Private Const EDGE_RAISED = (BDR_RAISEDOUTER Or BDR_RAISEDINNER)
  13. Private Const EDGE_SUNKEN = (BDR_SUNKENOUTER Or BDR_SUNKENINNER)
  14. Private Const EDGE_ETCHED = (BDR_SUNKENOUTER Or BDR_RAISEDINNER)
  15. Private Const EDGE_BUMP = (BDR_RAISEDOUTER Or BDR_SUNKENINNER)
  16. Private Const BF_LEFT = &H1
  17. Private Const BF_TOP = &H2
  18. Private Const BF_RIGHT = &H4
  19. Private Const BF_BOTTOM = &H8
  20. Private Const BF_RECT = (BF_LEFT Or BF_TOP Or BF_RIGHT Or BF_BOTTOM)
  21. Dim ButtonBorder As Long     ' picture variable to store Edge type
  22. ' Draw picture with edges at startup
  23. Private Sub Form_Load()
  24.   DOWN.AutoRedraw = False
  25.   ButtonBorder = EDGE_RAISED       ' draw "button edge" around picture
  26. End Sub
  27. ' This will make our picturebox look like a PRESSED button
  28. Private Sub DnPressed()
  29.   ButtonBorder = EDGE_SUNKEN
  30.   DOWN.Refresh
  31. End Sub
  32. ' This will make our picturebox look like a RELEASSED button
  33. Private Sub DnReleased()
  34.   ButtonBorder = EDGE_RAISED
  35.   DOWN.Refresh
  36. End Sub
  37. ' Simulate Command_MouseDown() & command_MouseUp()
  38. Private Sub DOWN_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  39.   Call DnPressed
  40. End Sub
  41. Private Sub DOWN_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  42.   Call DnReleased
  43. End Sub
  44. Private Sub DOWN_DblClick()
  45.   Call DnPressed
  46. End Sub
  47. ' Repaint drawn edges around our picture
  48. Private Sub DOWN_Paint()
  49.   Dim r As RECT
  50.   DOWN.Cls
  51.   r.Bottom = DOWN.ScaleHeight
  52.   r.Right = DOWN.ScaleWidth
  53.   DrawEdge DOWN.hDC, r, ButtonBorder, BF_RECT
  54. End Sub
  55. '**********************************************************************************
  56. '**********************************************************************************
  57. '**********************************************************************************
  58. ' Arron Young's code to center picture inside a picturebox THAT NEED'S TO BE INTEGRATED WITH THE ABOVE CODE
  59. Private Sub CenterPicture()
  60.   With DOWN
  61.     DOWN.Line (0, 0)-(.ScaleWidth, .ScaleHeight), .BackColor, BF
  62.     .PaintPicture .Picture, (.ScaleWidth - .ScaleX(.Picture.Width, vbHimetric, .ScaleMode)) / 2, _
  63.                             (.ScaleHeight - .ScaleY(.Picture.Height, vbHimetric, .ScaleMode)) / 2
  64.   End With
  65. End Sub
  66. '**********************************************************************************
  67. '**********************************************************************************
  68. '**********************************************************************************
  69.  
__________________
Thanks

Tomexx.
Tomexx is offline   Reply With Quote
Old Sep 24th, 2004, 11:00 AM   #2
Tomexx
Hyperactive Member
 
Join Date: Aug 99
Location: Ont, Canada, Earth
Posts: 451
Tomexx is an unknown quantity at this point (<10)
Change Scalemode of the picture box to 3-Pixel, appearence to flat, and BorderStyle to none
__________________
Thanks

Tomexx.
Tomexx is offline   Reply With Quote
Old Sep 24th, 2004, 11:04 AM   #3
Tomexx
Hyperactive Member
 
Join Date: Aug 99
Location: Ont, Canada, Earth
Posts: 451
Tomexx is an unknown quantity at this point (<10)
Ok, here's the project
Attached Files
File Type: zip edgesapi.zip (2.8 KB, 9 views)
__________________
Thanks

Tomexx.
Tomexx is offline   Reply With Quote
Reply

Go Back   VBForums > Visual Basic > Visual Basic 6 and Earlier


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 11:58 AM.




To view more projects, click here

Acceptable Use Policy


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.