tanc02
asked on
Rotate picture control
I print a word on a picture control. How do I rotate the
picture control by angle of 270 degree.
So I can see that word vertically ???
picture control by angle of 270 degree.
So I can see that word vertically ???
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
try this instead:
Call bmp_rotate(Picture1, Picture2, Pi / 2)
Call bmp_rotate(Picture1, Picture2, Pi / 2)
ASKER
bobbit31,
It is working now, but if you try to change this :
Picture1.Print " test"
to
Picture1.Print "test"
and you will see the rotated "test" is so far away from
the top-left corner.
How to make it appear on the top-left corner ?
I will increase the another 100 points if you can do it.
Thanks !
It is working now, but if you try to change this :
Picture1.Print " test"
to
Picture1.Print "test"
and you will see the rotated "test" is so far away from
the top-left corner.
How to make it appear on the top-left corner ?
I will increase the another 100 points if you can do it.
Thanks !
add this after all the dim's in the bmp_rotate sub
pic2.Height = pic1.Width
pic2.Width = pic1.Height
and use this:
Private Sub Command1_Click()
Const Pi = 3.14159265359
Picture1.AutoSize = True
Picture1.AutoRedraw = True
Picture2.AutoRedraw = True
Picture1.ScaleMode = 3
Picture2.ScaleMode = 3
DrawText Picture1, "This is a test" & vbCrLf & "hello"
Call bmp_rotate(Picture1, Picture2, Pi / 2)
End Sub
Public Sub DrawText(pic1 As Control, str As String)
pic1.ScaleMode = 3
pic1.Height = pic1.TextHeight(str) + 5
pic1.Width = pic1.TextWidth(str) + 5
pic1.Print str
End Sub
basically what it does, is it automatically sizes the picture boxes so that your rotated one doesn't have any of that wasted space.
pic2.Height = pic1.Width
pic2.Width = pic1.Height
and use this:
Private Sub Command1_Click()
Const Pi = 3.14159265359
Picture1.AutoSize = True
Picture1.AutoRedraw = True
Picture2.AutoRedraw = True
Picture1.ScaleMode = 3
Picture2.ScaleMode = 3
DrawText Picture1, "This is a test" & vbCrLf & "hello"
Call bmp_rotate(Picture1, Picture2, Pi / 2)
End Sub
Public Sub DrawText(pic1 As Control, str As String)
pic1.ScaleMode = 3
pic1.Height = pic1.TextHeight(str) + 5
pic1.Width = pic1.TextWidth(str) + 5
pic1.Print str
End Sub
basically what it does, is it automatically sizes the picture boxes so that your rotated one doesn't have any of that wasted space.
ASKER
When I hit the command1 button, two pictures control disappeared!
maybe this could help:
http://vbmaster.net/visual-basic/vb/read.asp?article=16&topic=Win%20API%20Programming&tid=3
http://vbmaster.net/visual-basic/vb/read.asp?article=16&topic=Win%20API%20Programming&tid=3
don't forget the pic1.scalemode = 3
Forgive me!
ASKER
I do have pic1.scalemode = 3, the picture boxes just disappeared.
The code works, how you got pic disappeared?
ASKER
I don't know. I will try again !
ASKER
It is still disappear. Can I have the latest code ?
Thanks !
Thanks !
ASKER
I know why !
Because
pic1.Height = pic1.TextHeight(str) + 5
pic1.Width = pic1.TextWidth(str) + 5
5 is too small.
Because
pic1.Height = pic1.TextHeight(str) + 5
pic1.Width = pic1.TextWidth(str) + 5
5 is too small.
so did you get it working?
ASKER
still yes and no,
Because I am using Times New Roman, and it is variable font. I don't know how should I change this :
pic1.Height = pic1.TextHeight(str) + 5
pic1.Width = pic1.TextWidth(str) + 5
because 5 is too small. This is the reason my picture boxes
keep missing.
Because I am using Times New Roman, and it is variable font. I don't know how should I change this :
pic1.Height = pic1.TextHeight(str) + 5
pic1.Width = pic1.TextWidth(str) + 5
because 5 is too small. This is the reason my picture boxes
keep missing.
ok, try setting the scalemode property of picture1 and picture2 to 3... not at run-time, but in the design time properties list.
then still use this:
pic1.Height = pic1.TextHeight(str) + 5
pic1.Width = pic1.TextWidth(str) + 5
then still use this:
pic1.Height = pic1.TextHeight(str) + 5
pic1.Width = pic1.TextWidth(str) + 5
ASKER
This is what I have:
Sub bmp_rotate(pic1 As Control, pic2 As Control, ByVal theta!)
Const Pi = 3.14159265359
Dim c1x As Integer
Dim c1y As Integer
Dim c2x As Integer
Dim c2y As Integer
Dim a As Single
Dim r As Integer
Dim p1x As Integer
Dim p1y As Integer
Dim p2x As Integer
Dim p2y As Integer
Dim n As Integer
pic2.Height = pic1.Width
pic2.Width = pic1.Height
c1x = pic1.ScaleWidth / 2
c1y = pic1.ScaleHeight / 2
c2x = pic2.ScaleWidth / 2
c2y = pic2.ScaleHeight / 2
n = pic2.ScaleWidth
If n < pic2.ScaleHeight Then n = pic2.ScaleHeight
n = n / 2 - 1
For p2x = 0 To n
For p2y = 0 To n
If p2x = 0 Then
a = Pi / 2
Else
a = Atn(p2y / p2x)
End If
r = Sqr(1& * p2x * p2x + 1& * p2y * p2y)
p1x = r * Cos(a + theta)
p1y = r * Sin(a + theta)
c0& = pic1.Point(c1x + p1x, c1y + p1y)
c1& = pic1.Point(c1x - p1x, c1y - p1y)
c2& = pic1.Point(c1x + p1y, c1y - p1x)
c3& = pic1.Point(c1x - p1y, c1y + p1x)
If c0& <> -1 Then pic2.PSet (c2x + p2x, c2y + p2y), c0&
If c1& <> -1 Then pic2.PSet (c2x - p2x, c2y - p2y), c1&
If c2& <> -1 Then pic2.PSet (c2x + p2y, c2y - p2x), c2&
If c3& <> -1 Then pic2.PSet (c2x - p2y, c2y + p2x), c3&
Next
t% = DoEvents()
Next
End Sub
Private Sub Command1_Click()
Const Pi = 3.14159265359
Picture1.AutoSize = True
Picture1.AutoRedraw = True
Picture2.AutoRedraw = True
Picture1.ScaleMode = 3
Picture2.ScaleMode = 3
DrawText Picture1, "This is a test" & vbCrLf & "hello"
Call bmp_rotate(Picture1, Picture2, Pi / 2)
End Sub
Public Sub DrawText(pic1 As Control, str As String)
pic1.ScaleMode = 3
pic1.Height = pic1.TextHeight(str) + 5
pic1.Width = pic1.TextWidth(str) + 5
pic1.Print str
End Sub
and I have set scalemode to 3 in properties box.
Sub bmp_rotate(pic1 As Control, pic2 As Control, ByVal theta!)
Const Pi = 3.14159265359
Dim c1x As Integer
Dim c1y As Integer
Dim c2x As Integer
Dim c2y As Integer
Dim a As Single
Dim r As Integer
Dim p1x As Integer
Dim p1y As Integer
Dim p2x As Integer
Dim p2y As Integer
Dim n As Integer
pic2.Height = pic1.Width
pic2.Width = pic1.Height
c1x = pic1.ScaleWidth / 2
c1y = pic1.ScaleHeight / 2
c2x = pic2.ScaleWidth / 2
c2y = pic2.ScaleHeight / 2
n = pic2.ScaleWidth
If n < pic2.ScaleHeight Then n = pic2.ScaleHeight
n = n / 2 - 1
For p2x = 0 To n
For p2y = 0 To n
If p2x = 0 Then
a = Pi / 2
Else
a = Atn(p2y / p2x)
End If
r = Sqr(1& * p2x * p2x + 1& * p2y * p2y)
p1x = r * Cos(a + theta)
p1y = r * Sin(a + theta)
c0& = pic1.Point(c1x + p1x, c1y + p1y)
c1& = pic1.Point(c1x - p1x, c1y - p1y)
c2& = pic1.Point(c1x + p1y, c1y - p1x)
c3& = pic1.Point(c1x - p1y, c1y + p1x)
If c0& <> -1 Then pic2.PSet (c2x + p2x, c2y + p2y), c0&
If c1& <> -1 Then pic2.PSet (c2x - p2x, c2y - p2y), c1&
If c2& <> -1 Then pic2.PSet (c2x + p2y, c2y - p2x), c2&
If c3& <> -1 Then pic2.PSet (c2x - p2y, c2y + p2x), c3&
Next
t% = DoEvents()
Next
End Sub
Private Sub Command1_Click()
Const Pi = 3.14159265359
Picture1.AutoSize = True
Picture1.AutoRedraw = True
Picture2.AutoRedraw = True
Picture1.ScaleMode = 3
Picture2.ScaleMode = 3
DrawText Picture1, "This is a test" & vbCrLf & "hello"
Call bmp_rotate(Picture1, Picture2, Pi / 2)
End Sub
Public Sub DrawText(pic1 As Control, str As String)
pic1.ScaleMode = 3
pic1.Height = pic1.TextHeight(str) + 5
pic1.Width = pic1.TextWidth(str) + 5
pic1.Print str
End Sub
and I have set scalemode to 3 in properties box.
for both picture boxes? and it is still not working?
ASKER
yes, for both picture boxes. Any idea ?
don't ask me why, but set your form scalemode either to user or pixel in the properties list... should work
ASKER
It is working now. WOW !
I have to set form's scale mode. Cool !
I will increase another 100 points for you.
I have to set form's scale mode. Cool !
I will increase another 100 points for you.
thanks for the points, glad to help!
ASKER
Your code work, but it is rotated by angle of 90 degree
What I want is 270 degree.