Solved

Rotate picture control

Posted on 2002-04-29
23
460 Views
Last Modified: 2010-05-02
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 ???
0
Comment
Question by:tanc02
  • 11
  • 9
  • 3
23 Comments
 
LVL 18

Accepted Solution

by:
bobbit31 earned 200 total points
ID: 6978468
try something like this (put two picture controls on form (named picture1 and picture2) you can just make picture1 invisible.

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

       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 - pixel
    Picture2.ScaleMode = 3 - pixel
    Picture1.Print "           test"
    Call bmp_rotate(Picture1, Picture2, (3 * Pi) / 2)
   
End Sub
0
 
LVL 1

Author Comment

by:tanc02
ID: 6978507
bobbit31,

Your code work, but it is rotated by angle of 90 degree
What I want is 270 degree.
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 6978620
try this instead:

Call bmp_rotate(Picture1, Picture2, Pi / 2)
0
 
LVL 1

Author Comment

by:tanc02
ID: 6978670
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 !

0
 
LVL 18

Expert Comment

by:bobbit31
ID: 6978737
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.
0
 
LVL 1

Author Comment

by:tanc02
ID: 6978776
When I hit the command1 button, two pictures control disappeared!
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6978781
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 6978788
don't forget the pic1.scalemode = 3
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6978791
Forgive me!
0
 
LVL 1

Author Comment

by:tanc02
ID: 6979017
I do have pic1.scalemode = 3, the picture boxes just disappeared.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6979438
The code works, how you got pic disappeared?
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 1

Author Comment

by:tanc02
ID: 6980614
I don't know. I will try again !
0
 
LVL 1

Author Comment

by:tanc02
ID: 6980622
It is still disappear. Can I have the latest code ?
Thanks !
0
 
LVL 1

Author Comment

by:tanc02
ID: 6980637
I know why !
Because

   pic1.Height = pic1.TextHeight(str) + 5
   pic1.Width = pic1.TextWidth(str) + 5

5 is too small.
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 6980899
so did you get it working?
0
 
LVL 1

Author Comment

by:tanc02
ID: 6980915
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.
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 6980954
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


0
 
LVL 1

Author Comment

by:tanc02
ID: 6980970
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.
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 6980977
for both picture boxes? and it is still not working?
0
 
LVL 1

Author Comment

by:tanc02
ID: 6980994
yes, for both picture boxes. Any idea ?
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 6981054
don't ask me why, but set your form scalemode either to user or pixel in the properties list... should work
0
 
LVL 1

Author Comment

by:tanc02
ID: 6981066
It is working now. WOW !
I have to set form's scale mode. Cool !
I will increase another 100 points for you.
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 6981081
thanks for the points, glad to help!
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

708 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

15 Experts available now in Live!

Get 1:1 Help Now