Results 1 to 7 of 7

Thread: [RESOLVED] Rotating my form

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2009
    Posts
    904

    Resolved [RESOLVED] Rotating my form

    when i do this code:
    Code:
    me.hide()
    newform.show()
    then the current form hides and the new form i shown.It happens in such a way that the current form becomes invisible and the new form is visible.I want to show a form in such a way that the old form will rotate once and when the rotation completes then the new form will be shown instead of the old form.......How to do this?any ideas?

    I think i did explained it well

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Rotating my form

    you can't actually rotate a form, but it is possible with GDI+ to create that effect.

    i'll have a go at it

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2009
    Posts
    904

    Re: Rotating my form

    ok paul i will wait for a reply
    Actually recently i installed norton antivirus 2010 in my machine and in it,when i click the performance linklabel then then new form comes exactly in such a way that i explained in my first post......

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Rotating my form

    try this. you need to add a new form - frmEffect, then paste this:

    vb Code:
    1. Public Class frmEffect
    2.  
    3.     Dim img As Bitmap
    4.     Dim frmLocation As Point
    5.     Dim originalCentre As Point
    6.  
    7.     Public Sub New(ByVal bgImage As Bitmap, ByVal frmBounds As Rectangle)
    8.  
    9.         ' This call is required by the Windows Form Designer.
    10.         InitializeComponent()
    11.  
    12.         ' Add any initialization after the InitializeComponent() call.
    13.  
    14.         img = bgImage
    15.         Me.BackgroundImage = bgImage
    16.         Me.Bounds = frmBounds
    17.         frmLocation = Me.Location
    18.         originalCentre = New Point(Me.Width \ 2, Me.Height \ 2)
    19.  
    20.         Me.DoubleBuffered = True
    21.  
    22.     End Sub
    23.  
    24.     ''' <summary>
    25.     ''' rotation timer
    26.     ''' </summary>
    27.     ''' <param name="sender"></param>
    28.     ''' <param name="e"></param>
    29.     ''' <remarks>interval = 20</remarks>
    30.     Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    31.  
    32.         Static angle As Integer = 0
    33.  
    34.         If angle = 360 Then Timer1.Enabled = False : Me.BackgroundImageLayout = ImageLayout.Stretch : Timer2.Enabled = True : Return
    35.  
    36.         angle += 2
    37.  
    38.         Me.BackgroundImage = Nothing
    39.  
    40.         ' Copy the output bitmap from the source image.
    41.         Dim bm_in As New Bitmap(img)
    42.  
    43.         ' Make an array of points defining the
    44.         ' image's corners.
    45.         Dim wid As Single = bm_in.Width
    46.         Dim hgt As Single = bm_in.Height
    47.         Dim corners As Point() = { _
    48.             New Point(0, 0), _
    49.             New Point(CInt(wid), 0), _
    50.             New Point(0, CInt(hgt)), _
    51.             New Point(CInt(wid), CInt(hgt))}
    52.  
    53.         ' Translate to center the bounding box at the origin.
    54.         Dim cx As Integer = CInt(wid / 2)
    55.         Dim cy As Integer = CInt(hgt / 2)
    56.  
    57.         For i As Integer = 0 To 3
    58.             corners(i).X -= cx
    59.             corners(i).Y -= cy
    60.         Next i
    61.  
    62.         ' Rotate.
    63.         Dim theta As Single = CSng(angle * Math.PI _
    64.             / 180.0)
    65.         Dim sin_theta As Single = CSng(Math.Sin(theta))
    66.         Dim cos_theta As Single = CSng(Math.Cos(theta))
    67.         Dim X As Single
    68.         Dim Y As Single
    69.         For i As Integer = 0 To 3
    70.             X = corners(i).X
    71.             Y = corners(i).Y
    72.             corners(i).X = CInt(X * cos_theta + Y * sin_theta)
    73.             corners(i).Y = CInt(-X * sin_theta + Y * cos_theta)
    74.         Next i
    75.  
    76.         ' Translate so X >= 0 and Y >=0 for all corners.
    77.         Dim xmin As Integer = corners(0).X
    78.         Dim ymin As Integer = corners(0).Y
    79.         For i As Integer = 1 To 3
    80.             If xmin > corners(i).X Then xmin = corners(i).X
    81.             If ymin > corners(i).Y Then ymin = corners(i).Y
    82.         Next i
    83.         For i As Integer = 0 To 3
    84.             corners(i).X -= xmin
    85.             corners(i).Y -= ymin
    86.         Next i
    87.  
    88.         ' Create an output Bitmap and Graphics object.
    89.         Dim bm_out As New Bitmap(CInt(-2 * xmin), CInt(-2 * _
    90.             ymin))
    91.         Dim gr_out As Graphics = Graphics.FromImage(bm_out)
    92.  
    93.         Dim p() As Point = {corners(3), corners(2)}
    94.  
    95.         ' Drop the last corner lest we confuse DrawImage,
    96.         ' which expects an array of three corners.
    97.         ReDim Preserve corners(2)
    98.  
    99.         ' Draw the result onto the output Bitmap.
    100.         gr_out.DrawImage(bm_in, corners)
    101.  
    102.         ReDim Preserve corners(3)
    103.         corners(3) = p(1)
    104.         corners(2) = p(0)
    105.  
    106.         Dim path As New Drawing.Drawing2D.GraphicsPath
    107.         path.AddPolygon(corners)
    108.         Dim newCentre As New Point(Rectangle.Round(path.GetBounds).Size.Width \ 2, Rectangle.Round(path.GetBounds).Size.Height \ 2)
    109.         Dim l As Point = frmLocation
    110.         l.Offset(originalCentre.X - newCentre.X, originalCentre.Y - newCentre.Y)
    111.         Me.Bounds = New Rectangle(l, Rectangle.Round(path.GetBounds).Size)
    112.         Me.Region = New Region(path)
    113.         Me.BackgroundImage = bm_out
    114.         Application.DoEvents()
    115.  
    116.     End Sub
    117.  
    118.     ''' <summary>
    119.     ''' shrink timer
    120.     ''' </summary>
    121.     ''' <param name="sender"></param>
    122.     ''' <param name="e"></param>
    123.     ''' <remarks>interval = 25</remarks>
    124.     Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
    125.         Dim r As Rectangle = Me.Bounds
    126.         If Me.Width > 10 And Me.Height > 10 Then
    127.             r.Inflate(-10, -10)
    128.             Me.Bounds = r
    129.         Else
    130.             Me.Close()
    131.             'load your new form here
    132.         End If
    133.     End Sub
    134.  
    135. End Class

    to show the rotating form, use this in your first form:

    vb Code:
    1. Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
    2.     Dim formImage As New Bitmap(Me.Width, Me.Height)
    3.     Dim gr As Graphics = Graphics.FromImage(formImage)
    4.     gr.CopyFromScreen(Me.Location, New Point(0, 0), Me.Size)
    5.     Dim frm As New frmEffect(formImage, Me.Bounds)
    6.     frm.Show()
    7. End Sub

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Rotating my form

    this might be more helpful:
    Attached Files Attached Files

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2009
    Posts
    904

    Re: Rotating my form

    thanks a lot paul the code works great.I wont ask you to explain it since i need to learn myself a lot in order to understand it.I want to learn the graphics and drawing in vb.net,so can you suggest where should i start from?

  7. #7
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Rotating my form

    try this. it looks quite informative, but i haven't read it

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width