In the process of developing software, in order to improve the degree of commercialization of software, we feel that the beauty of the interface is an important factor in the success of a software. We carefully studied some successful commercial software. From these software, we can see Yes, the background of the program window can display very beautiful and three-dimensional patterns. When using Visual Basic 3.0 or 4.0 for form design, if you only follow the functions provided by the system, you can only choose one color from a limited number of colors or use a program to draw some simple lines. If you want to achieve a texture pattern with a strong three-dimensional feel, you can generally only use the PICTURE attribute of the form to call the bitmap file. There are many shortcomings in using this method. One is that the size of the form is limited by the size of the bitmap, and it is troublesome to adjust. , does not have versatility and flexibility; the second is a waste of resources, because the pattern is basically a repeating pattern, and using a bitmap of the same size as the form is a waste.
The following introduces a method to implement form background patterns. Create a grid control on the form, set the grid rows to be invisible, remove the fixed rows and columns, and use a program to make the grid control the same size as the form, and change it as the size of the form changes. Then design a pattern to form a BMP bitmap file (the program in this article uses the file Pict1.bmp), or intercept a pattern from other images. You can also use the pattern provided by the Windows system (such as c:windowsTiles.bmp) to Call in the Picture control. Set each unit of the grid to be the same size as the pattern, so that the number of units just covers the entire form background, and then display the pattern in all units. The above process is realized through the subroutine Backpict(), regardless of the size of the pattern or the size of the window.
The program can automatically adjust the grid control size, grid unit size and number of units. The program was debugged successfully on VisualBasic4.0.
1. Create a new form Form1 with the following properties:
Caption="Realization of background patterns"
Borderstyle=3 (no maximum and minimum buttons)
2. Create a grid control Grid1. Its position and size will be set in the program (the same size as Form1), and its properties are:
Enabled=False (the focus will not fall on the grid control Grid1)
Fillstyle=1 (change the Text properties of all cells)
Fixedcols=0 (no fixed rows)
Fixedrows=0 (no fixed columns)
Gridlines=False (grid lines are not visible),
Visible=True
3. Create the image control Picture1. When the program is running, put the basic pattern of the background pattern into it, and the properties are
Visible=False (invisible)
Autosize=True (automatically adjust size)
4. Add Sheridan3DControls to the control, select the three-dimensional command button SSCommand, and create two
button
SSCommand1.Caption="Exit"
SSCommand2.Caption="Change background" (demonstrates different background patterns)
Their property Picture can call the same or different pattern as the background. If you use the ordinary command button control
Command can also be used, but the command button has no background pattern.
5. Create a background pattern forming subroutine:
DimpictfileAsString`Bitmap file name
DimFILEPATHAsString`File path
SubBackpict(pictfile)
picture1.ScaleMode=3
Form1.ScaleMode=3
picture1.Picture=LoadPicture(pictfile)
`The grid control covers the entire form background
grid1.Top=-1
grid1.Left=-1
grid1.Width=Width
grid1.Height=Height
grid1.Cols=Int(Form1.ScaleWidth/picture1.ScaleWidth) 1
grid1.Rows=Int(Form1.ScaleHeight/picture1.ScaleHeight) 1
`All cell sizes are equal to the base pattern size
ForI=0Togrid1.Cols-1
Forj=0Togrid1.Rows-1
grid1.ColWidth(I)=picture1.ScaleWidth*15
grid1.RowHeight(j)=picture1.ScaleHeight*15
Nextj
NextI
`Select all cells
grid1.SelStartCol=0
grid1.SelStartRow=0
grid1.SelEndCol=grid1.Cols-1
grid1.SelEndRow=grid1.Rows-1
grid1.Picture=Picture1.Picture
EndSub
6. Form main program
PRivateSubForm_Load()
PrivateSubForm_Load()
`Get the path name of the running program, with a backslash after the path name
IfRight(App.Path,1)<>""Then
filePath=App.Path&""
Else
filePath=App.Path
EndIf
`The form initially displays a background composed of the Tiles.bmp basic pattern
pictfile="c:windowsTiles.bmp"
backpict(pictfile)
EndSub
7. Exit program command button
PrivateSubSSCommand1_Click()
End
EndSub
8. Demonstrate different shading patterns
PrivateSubSSCommand2_Click()
`Two background patterns alternately demonstrate
Ifpictfile=filePath&"Pict1.bmp"Then
pictfile="c:windowsTiles.bmp"
Else
pictfile=filePath&"Pict1.bmp"
EndIf
Backpict(pictfile)
EndSub->