Page Flip in VB.NET

This tutorial will teach you how to create a flipping of image program as a page in vb.net. Now, let's start this tutorial! 1. Let's start with creating a Windows Form Application for this tutorial by following the following steps in Microsoft Visual Studio: Go to File, click New Project, and choose Windows Application. 2. Next, add two Buttons named Button2 for flipping right the image and Button3 for the left flipping. Add 10 PictureBox and two Timer. You must design your interface like this: output 3. Now, we will do the coding. We will first declare and initialize variables and have the image put in the C directory with a filename of 'test.jpg'.
  1.     Private count As Integer
  2.     Private count1 As Integer
  3.     Dim oImage As New Bitmap(500, 360)
  4.     Dim oGraphics As Graphics = Graphics.FromImage(oImage)
  5.     Dim imageFile1 As Image = Image.FromFile("c:/test.jpg")
We will then code for Ticking the Timer1 as it will be turning to the right page.
  1.    Private Sub Timer1_Tick(ByVal Sender As Object, ByVal e As EventArgs) Handles Timer1.Tick
  2.         count = count + 1
  3.  
  4.         If count = 1 Then
  5.             PictureBox2.Visible = True
  6.         End If
  7.         If count = 2 Then
  8.             PictureBox2.Visible = False
  9.             PictureBox3.Visible = True
  10.         End If
  11.         If count = 3 Then
  12.             PictureBox3.Visible = False
  13.             PictureBox4.Visible = True
  14.         End If
  15.         If count = 4 Then
  16.             PictureBox4.Visible = False
  17.             PictureBox5.Visible = True
  18.         End If
  19.         If count = 5 Then
  20.             PictureBox5.Visible = False
  21.             PictureBox6.Visible = True
  22.         End If
  23.         If count = 6 Then
  24.             PictureBox6.Visible = False
  25.             PictureBox7.Visible = True
  26.         End If
  27.         If count = 7 Then
  28.             PictureBox7.Visible = False
  29.             PictureBox8.Visible = True
  30.         End If
  31.         If count = 8 Then
  32.             PictureBox8.Visible = False
  33.             PictureBox9.Visible = True
  34.         End If
  35.         If count = 9 Then
  36.             PictureBox9.Visible = False
  37.             PictureBox10.Visible = True
  38.         End If
  39.         If count = 10 Then
  40.             Exit Sub
  41.         End If
  42.     End Sub
Then for Ticking the Timer2 as it will be turning to the Left page.
  1.    Private Sub Timer2_Tick(ByVal Sender As Object, ByVal e As EventArgs) Handles Timer2.Tick
  2.         count1 = count1 - 1
  3.  
  4.         If count1 = 1 Then
  5.             PictureBox2.Visible = True
  6.         End If
  7.         If count1 = 2 Then
  8.  
  9.             PictureBox3.Visible = False
  10.             PictureBox2.Visible = True
  11.         End If
  12.         If count1 = 3 Then
  13.  
  14.             PictureBox4.Visible = False
  15.             PictureBox3.Visible = True
  16.         End If
  17.         If count1 = 4 Then
  18.  
  19.             PictureBox5.Visible = False
  20.             PictureBox4.Visible = True
  21.         End If
  22.         If count1 = 5 Then
  23.  
  24.             PictureBox6.Visible = False
  25.             PictureBox5.Visible = True
  26.         End If
  27.         If count1 = 6 Then
  28.  
  29.             PictureBox7.Visible = False
  30.             PictureBox6.Visible = True
  31.         End If
  32.         If count1 = 7 Then
  33.  
  34.             PictureBox8.Visible = False
  35.             PictureBox7.Visible = True
  36.         End If
  37.         If count1 = 8 Then
  38.  
  39.             PictureBox9.Visible = False
  40.             PictureBox8.Visible = True
  41.         End If
  42.         If count1 = 9 Then
  43.             PictureBox10.Visible = False
  44.         End If
  45.         If count1 = 10 Then
  46.             Exit Sub
  47.         End If
  48.     End Sub
Now, we will do a sub procedure named test up to test7.This will create Create different parallelogram for drawing image.
  1.  Private Sub test()
  2.         Dim oImage As New Bitmap(500, 360)
  3.         Dim oGraphics As Graphics = Graphics.FromImage(oImage)
  4.         Dim imageFile1 As Image = Image.FromFile("c:/test.jpg")
  5.  
  6.         ' Create parallelogram for drawing image.
  7.         Dim ulCorner1 As New Point(50, 92)
  8.         Dim urCorner1 As New Point(360, 92)
  9.         Dim llCorner1 As New Point(50, 340)
  10.         Dim destPara1 As Point() = {ulCorner1, urCorner1, llCorner1}
  11.  
  12.         ' Create rectangle for source image.
  13.         Dim srcRect As New Rectangle(50, 50, 800, 533)
  14.         Dim units As GraphicsUnit = GraphicsUnit.Pixel
  15.         oGraphics.DrawImage(imageFile1, destPara1, srcRect, units)
  16.         Me.PictureBox2.Image = oImage
  17.     End Sub
  18.     Private Sub test1()
  19.         Dim oImage As New Bitmap(500, 360)
  20.         Dim oGraphics As Graphics = Graphics.FromImage(oImage)
  21.         Dim imageFile1 As Image = Image.FromFile("c:/test.jpg")
  22.  
  23.         ' Create parallelogram for drawing image.
  24.         Dim ulCorner1 As New Point(100, 35)
  25.         Dim urCorner1 As New Point(360, 104)
  26.         Dim llCorner1 As New Point(100, 275)
  27.         Dim destPara1 As Point() = {ulCorner1, urCorner1, llCorner1}
  28.  
  29.         ' Create rectangle for source image.
  30.         Dim srcRect As New Rectangle(50, 50, 800, 533)
  31.         Dim units As GraphicsUnit = GraphicsUnit.Pixel
  32.         oGraphics.DrawImage(imageFile1, destPara1, srcRect, units)
  33.         Me.PictureBox3.Image = oImage
  34.     End Sub
  35.     Private Sub test2()
  36.  
  37.         Dim oImage As New Bitmap(500, 360)
  38.         Dim oGraphics As Graphics = Graphics.FromImage(oImage)
  39.         Dim imageFile1 As Image = Image.FromFile("c:/test.jpg")
  40.  
  41.         ' Create parallelogram for drawing image.
  42.         Dim ulCorner1 As New Point(200, 7)
  43.         Dim urCorner1 As New Point(360, 104)
  44.         Dim llCorner1 As New Point(200, 250)
  45.         Dim destPara1 As Point() = {ulCorner1, urCorner1, llCorner1}
  46.  
  47.         ' Create rectangle for source image.
  48.         Dim srcRect As New Rectangle(50, 50, 800, 533)
  49.         Dim units As GraphicsUnit = GraphicsUnit.Pixel
  50.         oGraphics.DrawImage(imageFile1, destPara1, srcRect, units)
  51.         Me.PictureBox4.Image = oImage
  52.     End Sub
  53.  
  54.     Private Sub test3()
  55.         Dim oImage As New Bitmap(500, 360)
  56.         Dim oGraphics As Graphics = Graphics.FromImage(oImage)
  57.         Dim imageFile1 As Image = Image.FromFile("c:/test.jpg")
  58.  
  59.         ' Create parallelogram for drawing image.
  60.         Dim ulCorner1 As New Point(300, 7)
  61.         Dim urCorner1 As New Point(360, 104)
  62.         Dim llCorner1 As New Point(300, 250)
  63.         Dim destPara1 As Point() = {ulCorner1, urCorner1, llCorner1}
  64.  
  65.         ' Create rectangle for source image.
  66.         Dim srcRect As New Rectangle(50, 50, 800, 533)
  67.         Dim units As GraphicsUnit = GraphicsUnit.Pixel
  68.         oGraphics.DrawImage(imageFile1, destPara1, srcRect, units)
  69.         Me.PictureBox5.Image = oImage
  70.     End Sub
  71.  
  72.     Private Sub test4()
  73.         Dim oImage As New Bitmap(500, 360)
  74.         Dim oGraphics As Graphics = Graphics.FromImage(oImage)
  75.         Dim imageFile1 As Image = Image.FromFile("c:/test.jpg")
  76.  
  77.         ' Create parallelogram for drawing image.
  78.         Dim ulCorner1 As New Point(400, 7)
  79.         Dim urCorner1 As New Point(360, 104)
  80.         Dim llCorner1 As New Point(400, 250)
  81.         Dim destPara1 As Point() = {ulCorner1, urCorner1, llCorner1}
  82.  
  83.         ' Create rectangle for source image.
  84.         Dim srcRect As New Rectangle(50, 50, 800, 533)
  85.         Dim units As GraphicsUnit = GraphicsUnit.Pixel
  86.         oGraphics.DrawImage(imageFile1, destPara1, srcRect, units)
  87.         Me.PictureBox6.Image = oImage
  88.     End Sub
  89.  
  90.     Private Sub test5()
  91.         Dim oImage As New Bitmap(500, 360)
  92.         Dim oGraphics As Graphics = Graphics.FromImage(oImage)
  93.         Dim imageFile1 As Image = Image.FromFile("c:/test.jpg")
  94.  
  95.         ' Create parallelogram for drawing image.
  96.         Dim ulCorner1 As New Point(500, 14)
  97.         Dim urCorner1 As New Point(360, 104)
  98.         Dim llCorner1 As New Point(500, 257)
  99.         Dim destPara1 As Point() = {ulCorner1, urCorner1, llCorner1}
  100.  
  101.         ' Create rectangle for source image.
  102.         Dim srcRect As New Rectangle(50, 50, 800, 533)
  103.         Dim units As GraphicsUnit = GraphicsUnit.Pixel
  104.         oGraphics.DrawImage(imageFile1, destPara1, srcRect, units)
  105.         Me.PictureBox7.Image = oImage
  106.     End Sub
  107.  
  108.     Private Sub test6()
  109.         Dim oImage As New Bitmap(500, 360)
  110.         Dim oGraphics As Graphics = Graphics.FromImage(oImage)
  111.         Dim imageFile1 As Image = Image.FromFile("c:/test.jpg")
  112.  
  113.         ' Create parallelogram for drawing image.
  114.         Dim ulCorner1 As New Point(590, 32)
  115.         Dim urCorner1 As New Point(360, 104)
  116.         Dim llCorner1 As New Point(590, 270)
  117.         Dim destPara1 As Point() = {ulCorner1, urCorner1, llCorner1}
  118.  
  119.         ' Create rectangle for source image.
  120.         Dim srcRect As New Rectangle(50, 50, 800, 533)
  121.         Dim units As GraphicsUnit = GraphicsUnit.Pixel
  122.         oGraphics.DrawImage(imageFile1, destPara1, srcRect, units)
  123.         Me.PictureBox8.Image = oImage
  124.     End Sub
  125.  
  126.     Private Sub test7()
  127.         Dim oImage As New Bitmap(800, 360)
  128.         Dim oGraphics As Graphics = Graphics.FromImage(oImage)
  129.         Dim imageFile1 As Image = Image.FromFile("c:/test.jpg")
  130.  
  131.         ' Create parallelogram for drawing image.
  132.         Dim ulCorner1 As New Point(650, 104)
  133.         Dim urCorner1 As New Point(360, 104)
  134.         Dim llCorner1 As New Point(650, 340)
  135.         Dim destPara1 As Point() = {ulCorner1, urCorner1, llCorner1}
  136.  
  137.         ' Create rectangle for source image.
  138.         Dim srcRect As New Rectangle(50, 50, 800, 533)
  139.         Dim units As GraphicsUnit = GraphicsUnit.Pixel
  140.         oGraphics.DrawImage(imageFile1, destPara1, srcRect, units)
  141.         Me.PictureBox9.Image = oImage
  142.         Me.PictureBox10.Image = oImage
  143.     End Sub
Now, we will code for Button2 for flipping the page into the right position.
  1.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  2.         '-------Button2 events-----------------------------
  3.         'set counter low for upward count in timer1 _tick event
  4.         count = 0
  5.         PictureBox10.Visible = False
  6.         Timer1.Enabled = True
  7.     End Sub
And for Button3 for flipping the page into the left position.
  1.     Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
  2.         '-------Button3 events-----------------------------
  3.         'set counter high for backward count in timer2 _tick event
  4.         'sets timer2 count1 to 9
  5.         count1 = 10
  6.         '---------Get picturebox2 out of the way as it overlaps onto picturebox10's side
  7.         PictureBox2.Visible = False
  8.         PictureBox10.Visible = True
  9.         Timer2.Enabled = True
  10.     End Sub
Lastly, in the Form_Load put all the tests in their.
  1.     Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  2.         '--------Set timer intervals----------------------
  3.         Timer1.Interval = 35
  4.         Timer2.Interval = 35
  5.         '--------Load bitmap into pictureboxes 2-10-------
  6.  
  7.         test()
  8.         test1()
  9.         test2()
  10.         test3()
  11.         test4()      'Can you get this section to work from within a function????
  12.         test5()      'a variable would be nice to store the image in so we could
  13.         test6()      'call a different image for each flip.
  14.         test7()
  15.         '-------------------------------------------------
  16.     End Sub

Output:

output output For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below. Best Regards, Engr. Lyndon Bermoy IT Instructor/System Developer/Android Developer/Freelance Programmer Mobile: 09488225971 Landline: 826-9296 E-mail:[email protected] Add and Follow me on Facebook: https://www.facebook.com/donzzsky Visit and like my page on Facebook at: https://www.facebook.com/BermzISware

Add new comment