Did you know that you can do maths in visual basic?
it is easy as do maths in school !
Sample (This Is How You Make A Virtual Desktop):
-First click panel and dock in parent container,
change the backgroundimage as you like. you can use code to change b_image :
Panel1.BackgroundImage = New Bitmap("Location")
you can change that "Location" to any location you want like "C:\Desktop.png"
-Second, let's coding. Make a new Public Sub, type this :
Public Sub DesktopList(Byval Panel as Panel, ByVal Location As String, ByVal IconSize As Integer, ByVal IconPerIconSize As Integer)
Dim PositionX As Integer = IconPerIconSize
Dim PositionY As Integer = IconPerIconSize
Dim CurrentList As Integer = 0
For Each i In My.Computer.FileSystem.GetFiles(Location)
If PositionX = Panel.Size.Width - (IconSize + IconPerIconSize) Or PositionX > Panel.Size.Width - (IconSize + IconPerIconSize) Then
PositionY += IconSize + IconPerIconSize
PositionX = IconPerIconSize
End If
Dim ItemsImage As New PictureBox
ItemsImage.Size = New Point(IconSize, IconSize)
ItemsImage.Location = New Point(PositionX, PositionY)
ItemsImage.SizeMode = PictureBoxSizeMode.CenterImage
If i.Contains(".jpg") Or i.Contains(".png") Or i.Contains(".bmp") Then
ItemsImage.Image = New Bitmap(i)
ItemsImage.SizeMode = PictureBoxSizeMode.Zoom
Else
ItemsImage.Image = Icon.ExtractAssociatedIcon(i).ToBitmap
End If
ItemsImage.Name = i
Panel.Controls.Add(ItemsImage)
CurrentList += 1
PositionX += IconSize + IconPerIconSize
Next
End Sub
isn't that confusing?
it is easy to understand. Here :
ItemsImage.Location = New Point(PositionX, PositionY)
it mean if there exist any file in "Location", it will create new picturebox in panel1.
second is :
If PositionX = Panel.Size.Width - (IconSize + IconPerIconSize) Or PositionX > Panel.Size.Width - (IconSize + IconPerIconSize) Then
it mean if the position x of picturebox equal or more than (Panel1 Width - (IconSize + IconPerIconSize)) this will place the picturebox below the line.
if not the it will create the picture outside of panel1, so if it equal or bigger than, it will create in below... second line.
Understand? if not, you can research it yourself.
And this for picture :
If i.Contains(".jpg") Or i.Contains(".png") Or i.Contains(".bmp") Then
if the picture is contains .bmp or .jpg or .png (You can add all image format, just add
or i.contains(".image format")
)
I make like this because
ItemsImage.SizeMode = PictureBoxSizeMode.CenterImage
will make the picture zoomed.
so i change to
ItemsImage.SizeMode = PictureBoxSizeMode.Zoom
in the if statement to make it center of image.
and this for load the picture if png, bmp, or else :
ItemsImage.Image = New Bitmap(i)
it will load directly the image from the (i) location. (i) is a filename, looping each file in "location"
this for .lnk or .exe or else :
ItemsImage.Image = Icon.ExtractAssociatedIcon(i).ToBitmap
it will extracted the image of the file and change to bitmap, so picturebox can load that image.
and there, no more important. If you want to use this however you don't understand anything... just plug-n-play. copy that code and paste as new
Public Sub
and to call that use this
DesktopList(Panel1, "Location", IconSize, IconPerIconSize)
where Panel1 is the panel to draw desktop, "location" is the location like
My.Computer.FileSystem.SpecialDirectories.Desktop
that will load all file in desktop. Iconsize is the icon size, like 32 (32x32), 64 (64x64) just type 32 or 64 or 120 or else. don't type 32x32 or else. IconPerIconSize is the space between each icon.
this is example of
DesktopList(Panel1, My.Computer.FileSystem.SpecialDirectories.Desktop, 32, 10)
this is with no background image
and this is with background image and code (Space between icon is 100, look what happen) :
DesktopList(Panel1, My.Computer.FileSystem.SpecialDirectories.Desktop, 32, 100)
look that, a scroll bar. it mean there exist more icon below. the size is 32 but space between icon is 100. it is how it work.
and this is for this code :
DesktopList(Panel1, My.Computer.FileSystem.SpecialDirectories.Desktop, 64, 10)
Oh no... what is that? the backcolor for the picturebox is not transparent ! what we have gonna do?
just add
ItemsImage.BackColor = Color.Transparent
in the last of the code in that public sub.
i mean after
PositionX += IconSize + IconPerIconSize
for beginner if you not understand.
now this is how it will look like :
isn't that amazing?
if you want to make it look like professional, addhandler to each picturebox with your own sub.
In the next tutorial, I will teach you how to make taskbar.
If you are beginner but you want to make own Operating System, just wait for me and I will help you.
also if you want to make it with .net control, you can use listview.
bye~
Check Out My Project At VSlang InternetTM.
More Project :
- Poroxnoss Text Editor 2 - Added soon...
- TAP 2D Game Maker - Coming really soon...
- Easy Desktop - Discontinue..