|
-
Mar 2nd, 2012, 03:50 AM
#1
Thread Starter
Frenzied Member
How to centre the graphic in the picture box
How to centre the graphic draw in the picture box?
Picture1.Line (Text1.Text, Picture1.ScaleHeight - Text2.Text)-(Text3.Text, Picture1.ScaleHeight - Text4.Text), vbBlue
Picture1.FillStyle = 0
Picture1.FillColor = vbRed
Picture1.Circle (Text1.Text, Picture1.ScaleHeight - Text2.Text), 100
Picture1.FillStyle = 0
Picture1.FillColor = vbRed
Picture1.Circle (Text3.Text, Picture1.ScaleHeight - Text4.Text), 100
Picture1.Line (Text3.Text, Picture1.ScaleHeight - Text4.Text)-(Text5.Text, Picture1.ScaleHeight - Text6.Text), vbBlue
Picture1.FillStyle = 0
Picture1.FillColor = vbRed
Picture1.Circle (Text5.Text, Picture1.ScaleHeight - Text6.Text), 100
Picture1.Line (Text5.Text, Picture1.ScaleHeight - Text6.Text)-(Text7.Text, Picture1.ScaleHeight - Text8.Text), vbBlue
-
Mar 2nd, 2012, 04:03 AM
#2
Re: How to centre the graphic in the picture box
I believe that the center of a PictureBox is
x= Picture1.ScaleWidth / 2 , y = Picture1.ScaleHeight / 2
-
Mar 2nd, 2012, 09:16 AM
#3
Re: How to centre the graphic in the picture box
The algo for centering anything on a background object
centerX = (bkgObj.Width - tgtObj.Width) \ 2
centerY = (bkgObj.Height - tgtObj.Height) \ 2
-
Mar 2nd, 2012, 10:32 AM
#4
Re: How to centre the graphic in the picture box
Matrick
In addition to the foregoing posts, I'll mention that
I've found the graphic method specs somewhat "obtuse".
So I create generic subs that make it easier for me to
establish the various paremeters. For example:
... for a Line
Code:
Sub ZLINE(nXX1, nXX2, nYY1, nYY2, nDW, nCC)
'
With PB1
.DrawStyle = 0
.DrawWidth = nDW
PB1.Line (nXX1, nYY1)-(nXX2, nYY2), nCC
End With
'
End Sub
... for a Circle
Code:
Sub ZCIRC(nXX1, nYY1, nDW, nRADIUS, nCC)
'
With PB1
odw = .DrawWidth
.DrawWidth = nDW
PB1.Circle (nXX1, nYY1), nRADIUS, nCC
.DrawWidth = odw
End With
'
End Sub
Then, in the calling sub, to draw your graphics,
(not centered yet) I would do this..
Code:
xx1 = Val(Text1.Text)
xx2 = Val(Text3.Text)
yy1 = Val(Text2.Text)
yy2 = Val(Text4.Text)
'
ZLINE xx1, xx2, yy1, yy2, 1, vbBlue
ZCIRC xx1, yy1, 1, 100, vbRed
ZCIRC xx2, yy2, 1, 100, vbRed
'
' etc
'
To deal with the centering requirements, I would
modify the code as follows by applying offsets
Code:
With PB1
' raw coords
xx1 = Val(Text1.Text)
xx2 = Val(Text3.Text)
yy1 = Val(Text2.Text)
yy2 = Val(Text4.Text)
' calc offsets
lenX = xx2 - xx1
lenY = yy2 - yy1
cenX = xx1 + lenX / 2
cenY = yy1 + lenY / 2
cenXpb = .Width / 2
cenYpb = .Height / 2
oox = cenXpb - cenX
ooy = cenYpb - cenY
' apply offsets
xx1o = xx1 + oox
xx2o = xx2 + oox
yy1o = yy1 + ooy
yy2o = yy2 + ooy
ZLINE xx1o, xx2o, yy1o, yy2o, 1, vbBlue
ZCIRC xx1o, yy1o, 1, 100, vbRed
ZCIRC xx2o, yy2o, 1, 100, vbRed
'
End With
I have not tested this.
It is a admittedly "brute force" approach, but I
hope that it gives you some ideas.
Spoo
-
Mar 3rd, 2012, 11:30 AM
#5
Re: How to centre the graphic in the picture box
 Originally Posted by LaVolpe
The algo for centering anything on a background object
centerX = (bkgObj.Width - tgtObj.Width) \ 2
centerY = (bkgObj.Height - tgtObj.Height) \ 2
Yes, I would add however that in some cases you need to use the scalewidth and scaleheight of the background object to get the correct results.
-
Mar 6th, 2012, 10:19 AM
#6
Thread Starter
Frenzied Member
Re: How to centre the graphic in the picture box
I would like to draw the line at the centre of picture box. Mybe I would like to move the line I drew to the center of picturebox
Picture1.Line (Text1.Text, Picture1.ScaleHeight - Text2.Text)-(Text3.Text, Picture1.ScaleHeight - Text4.Text), vbBlue
Picture1.FillStyle = 0
Picture1.FillColor = vbRed
Picture1.Circle (Text1.Text, Picture1.ScaleHeight - Text2.Text), 100
Picture1.FillStyle = 0
Picture1.FillColor = vbRed
Picture1.Circle (Text3.Text, Picture1.ScaleHeight - Text4.Text), 100
Picture1.Line (Text3.Text, Picture1.ScaleHeight - Text4.Text)-(Text5.Text, Picture1.ScaleHeight - Text6.Text), vbBlue
Picture1.FillStyle = 0
Picture1.FillColor = vbRed
Picture1.Circle (Text5.Text, Picture1.ScaleHeight - Text6.Text), 100
Picture1.Line (Text5.Text, Picture1.ScaleHeight - Text6.Text)-(Text7.Text, Picture1.ScaleHeight - Text8.Text), vbBlue
-
Mar 6th, 2012, 11:29 AM
#7
Re: How to centre the graphic in the picture box
Matrik
Your post #6 appears to be the same as your OP (post #1)
Did you happen to notice my post #4?
If you did but felt it was too "obtuse", so be it .. no problem 
But, if you did and have some questions, I'll be glad to expand.
Spoo
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|