How to Flip Your Visual Basic Form in another Form

I recently joined myLot forum. It is a paid to post forum introduced by my friend. Hah! Hah! I'm thinking about making money while hanging around the net with friends. Isn't that great? You can get money if you start a good discussion and even get money when responding in discussion in a good manners. The good thing is myLot can pay me via PayPal or e-Gold. So, if you are interested too, then you can simply join the myLot forum for free by clicking here and then click on sign up.

Ups, back to the topic. While browsing the forum, I found a Visual Basic question about how to flip the content of the VB form. So, I decided to help him and make this simple step by step code.

OK lets make it simple because I also hate to type a lot . We are using VB6 to create this small project. So, make sure you have VB6 installed to follow this steps.

Step 1: Open up VB6 and create new project using 'Standard EXE'.

Step 2: Add one CommandButton (we will use this to trigger the flipping)

Step 3: Add other controls we like (e.g: labels, frame, image, picture), arrange and modify their property as we like.

Step 4: Add other form (the name by default is Form2... let it be like that)

Step 5: Add a PictureBox control in Form2.

Step 6: Paste This code in Form1
Option Explicit

Private Declare Function
StretchBlt Lib "gdi32" ( _
ByVal hDC As Long, ByVal x As Long, ByVal y As Long, _
ByVal nWidth As Long, ByVal nHeight As Long, _
ByVal hSrcDC As Long, ByVal xSrc As Long, _
ByVal ySrc As Long, ByVal nSrcWidth As Long, _
ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long

Private Const
SRCCOPY = &HCC0020

Private Sub Command1_Click()
Dim lx As Long
Dim
ly As Long
Dim
lRet As Long

' get the size of Form1
lx = ScaleX(Me.ScaleWidth, Me.ScaleMode, vbPixels)
ly = ScaleY(Me.ScaleHeight, Me.ScaleMode, vbPixels)

' load Form2 but hide it
Call Form2.Hide

' resize the picture in Form2 to fit our Form1 size
Call Form2.Picture1.Move(0, 0, Me.ScaleWidth, Me.ScaleHeight)

' Set the AutoRedraw True to let it paint
Form2.Picture1.AutoRedraw = True

' use a simple StretchBlt API to draw Form1 on Form2
lRet = StretchBlt(Form2.Picture1.hDC, lx, 0, -lx, ly&, _
Me.hDC, 0, 0, lx&, ly&, SRCCOPY)

' Set the AutoRedraw back to false and refresh
Form2.Picture1.AutoRedraw = False
Call
Form2.Picture1.Refresh

' resize Form2 to the size of Form1 and Show the form
Call Form2.Move(Form2.Left, Form2.Top, Me.Width, Me.Height)
Call Form2.Show

End Sub

Private Sub
Form_Load()
Command1.Caption = "Flip The Form"
End Sub

Step 7: Paste This code in Form2
Option Explicit

Private Sub
Form_Load()
' Set BorderStyle to none
Picture1.BorderStyle = 0
End Sub

Private Sub
Form_Resize()
On Error Resume Next
' resize the picture to fit form area
Call Picture1.Move(0, 0, Me.ScaleWidth, Me.ScaleHeight)
End Sub

Then Run or press F5 and then Click on the "Flip The Form" button to see it. Observe how I simply use StretchBlt API to flip the form image. I hope this code will help you. Enjoy!

Comments

Popular posts from this blog

How to Create Hyperlink on Blogger Post

How to Add a Sudo User on AlmaLinux 9.2 (Turquoise Kodkod): A Step-by-Step Guide

How to Check AlmaLinux Version on the Command Line: A Quick Guide