iCon Block - SpinOff

Heres your chance to share your own tutorials with the community. Just post them on here. If your lucky they may even be posted on the main site.
13 posts Page 1 of 2
User avatar
CodenStuff
Site Admin
Site Admin
Posts: 4389
Joined: Tue Aug 04, 2009 1:47 am

iCon Block - SpinOff
CodenStuff
Hello all


Ive got another little tutorial for you, although its more of a re-codeing. Ive taken the code of Application Launcher Bar and mixed it around and added a few things to make a different kindof launcher.

Image

This one is in the form of a block which sits in the middle of the screen and can hold 60 icon shortcuts for quick access to your favourite programs. Ill tell you the features of this one first:

Double-Click now hides the block
Taskbar icon for launching the block
Can choose transparency
Themes
Always on top (on/off)
Icon descriptions (hovering over an icon will now tell you where it leads/what it opens)
Can turn descriptions on/off
You can now add folders to the block (represented by custom folder icon)
You can also add harddrive links to the block (represented by custom harddrive icon)

Ill be updating the original Application Launcher Bar with the icon upgrade code in just a minute for those of you who still want to use the original, we all get equal rights in here :)

OK onto the quick and easy tutorial.

First you need to start a new project and make the form have the dimensions of 526, 332 no more and no less.

Now you need to add the following controls and things to your form like this:

ContextMenuStrip with the following menus:
Image

Now you need to change the 'CheckonClick' propertie to "True" on the following menus - Always on Top ...Descriptions on/off...Remove

You will also need an OpenFileDialog and NotifyIcon control on your form. Choose an icon for notifyicon and change the propertie 'ContextMenu' to your contextmenustrip you made earlier...do the same for form1's 'Contextmenu' propertie.

Also change Form1s show in taskbar propertie to 'False' because we dont want it laying about.

Almost finished. Now you need to add 2 embedded resources to your project, these are *.ico files. You need:

1 called Folder.ico
1 called Harddrive.ico
Those are used to represent the folders and harddrives if you place them on the block, choose ones to suit your windows theme.

I used these ones: Image...Image ...they may look grainy but when you save them to your comp they look fine ;)

Now for the code and its a simple cut and paste job:
Code: Select all
Imports System.Runtime.InteropServices
Imports System.IO
Public Class Form1
    Public rowz = 20
    Public cols = 5
    'HANDLES MOUSE EVENTS WHEN MOUSE MOVES OVER AN ICON ON BAR
    Private Sub Lab_MouseEnter(ByVal sender As System.Object, ByVal e As System.EventArgs)
        CType(sender, PictureBox).Size = New Size(50, 50)
        CType(sender, PictureBox).Location = New Point(sender.Location.X, sender.Location.Y)
        Label3.Text = CType(sender, PictureBox).Tag.ToString
    End Sub
    Private Sub Lab_MouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs)
        CType(sender, PictureBox).Size = New Size(40, 40)
        CType(sender, PictureBox).Location = New Point(sender.Location.X, sender.Location.Y)
        Label3.Text = "Welcome to iCon Block - www.codenstuff.com"
    End Sub
    'THIS IS WHAT HAPPENS WHEN YOU CLICK AN ICON ON THE BAR - OPENS or DELETES
    Private Sub Fclick(ByVal sender As System.Object, ByVal e As System.EventArgs)
        If RemoveToolStripMenuItem.Checked = True Then
            Dim findlink As String = CType(sender, PictureBox).Tag.ToString
            Dim replace As String = ""
            Dim indx As Integer = RichTextBox1.Find(findlink)
            If indx <> -1 Then
                RichTextBox1.Select(indx, findlink.Length)
                If RichTextBox1.SelectedText <> "" Then
                    RichTextBox1.SelectedText = replace
                End If
            End If
            CType(sender, PictureBox).Dispose()
            saveme()
        Else
            Dim w = CType(sender, PictureBox).Tag.ToString
            System.Diagnostics.Process.Start(w)
        End If
    End Sub
    'READS SAVED ICONS AND LOADS THEM AT STARTUP INTO THE BAR
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim back = Convert.ToString(My.Settings.backg)
        If My.Computer.FileSystem.FileExists(Application.StartupPath + "\Settings.bar") Then
            Dim lines = IO.File.ReadAllLines(Application.StartupPath + "\Settings.bar")
            For Each line As String In lines
                If line <> "" Then
                    RichTextBox1.AppendText(line + vbNewLine)
                    Dim w As New PictureBox
                    Try
                        Dim shortcut, starget As String
                        Dim oshelllink
                        Dim wsh As Object = CreateObject("WScript.Shell")
                        wsh = CreateObject("WScript.Shell")
                        shortcut = line
                        oshelllink = wsh.CreateShortcut(shortcut)
                        starget = oshelllink.TargetPath
                        '**********************************************
                        Using ico As Icon = Drawing.Icon.ExtractAssociatedIcon(starget)
                            Dim s = ico.ToBitmap
                            w.Image = s
                        End Using
                    Catch ex As Exception
                        Try
                            Using ico As Icon = Drawing.Icon.ExtractAssociatedIcon(line)
                                Dim s = ico.ToBitmap
                                w.Image = s
                            End Using
                        Catch wex As Exception
                            If line.Length = 3 Then

                                Using ico As Icon = My.Resources.Harddrive
                                    Dim s = ico.ToBitmap
                                    w.Image = s
                                End Using
                            Else
                                Using ico As Icon = My.Resources.Folder
                                    Dim s = ico.ToBitmap
                                    w.Image = s
                                End Using
                            End If
                        End Try
                    End Try
                    If rowz = 520 Then
                        rowz = 20
                        cols += 50
                    End If
                    w.Location = New Point(rowz, cols)
                    w.Size = New Size(40, 40)
                    w.Tag = line
                    w.BackColor = Color.Transparent
                    w.SizeMode = PictureBoxSizeMode.StretchImage
                    AddHandler w.Click, AddressOf Fclick
                    AddHandler w.MouseEnter, AddressOf Lab_MouseEnter
                    AddHandler w.MouseLeave, AddressOf Lab_MouseLeave
                    Me.Controls.Add(w)
                    rowz += 50
                End If
            Next
        End If
        If back = "" Then
        Else
            Me.BackgroundImage = System.Drawing.Image.FromFile(back)
        End If
       
    End Sub
    'DETECTS PROGRAM DRAGGED ONTO BAR AND ADDs IT and SHOWS ITS ICON
    Private Sub Form1_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles MyBase.DragDrop
        If rowz = 520 And cols = 205 Then
            MsgBox("You have reached the limit.  Please remove some icons to add more.")
        Else
            If e.Data.GetDataPresent(DataFormats.FileDrop) Then
                Dim draggedFiles As String() = CType(e.Data.GetData(DataFormats.FileDrop), String())
                For Each filename As String In draggedFiles
                    RichTextBox1.AppendText(filename + vbNewLine)
                    Dim w As New PictureBox
                    '**********************************************
                    Try
                        Dim shortcut, starget As String
                        Dim oshelllink
                        Dim wsh As Object = CreateObject("WScript.Shell")
                        wsh = CreateObject("WScript.Shell")
                        shortcut = filename
                        oshelllink = wsh.CreateShortcut(shortcut)
                        starget = oshelllink.TargetPath
                        '**********************************************
                        Using ico As Icon = Drawing.Icon.ExtractAssociatedIcon(starget)
                            Dim s = ico.ToBitmap
                            w.Image = s
                        End Using
                    Catch ex As Exception
                        Try
                            Using ico As Icon = Drawing.Icon.ExtractAssociatedIcon(filename)
                                Dim s = ico.ToBitmap
                                w.Image = s
                            End Using
                        Catch wex As Exception
                            If filename.Length = 4 Then
                                Using ico As Icon = My.Resources.Harddrive
                                    Dim s = ico.ToBitmap
                                    w.Image = s
                                End Using
                            End If
                            Using ico As Icon = My.Resources.Folder
                                Dim s = ico.ToBitmap
                                w.Image = s
                            End Using
                        End Try
                    End Try
                    If rowz = 520 Then
                        rowz = 20
                        cols += 50
                    End If
                    w.Location = New Point(rowz, cols)
                    w.Size = New Size(40, 40)
                    w.Tag = filename
                    w.BackColor = Color.Transparent
                    w.SizeMode = PictureBoxSizeMode.StretchImage
                    AddHandler w.Click, AddressOf Fclick
                    AddHandler w.MouseEnter, AddressOf Lab_MouseEnter
                    AddHandler w.MouseLeave, AddressOf Lab_MouseLeave
                    Me.Controls.Add(w)
                    rowz += 50
                Next
                saveme()
            End If
        End If
    End Sub
    'CHECKS TO MAKE SURE ITEM DRAGGED IS A FILE
    Private Sub Form1_DragEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles MyBase.DragEnter
        If e.Data.GetDataPresent(DataFormats.FileDrop) Then
            e.Effect = DragDropEffects.Copy
        End If
    End Sub
    'SAVES THE SHORTCUTS
    Public Sub saveme()
        If My.Computer.FileSystem.FileExists(Application.StartupPath + "\Settings.bar") Then
            My.Computer.FileSystem.DeleteFile(Application.StartupPath + "\Settings.bar", FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.DeletePermanently)
        End If
        My.Computer.FileSystem.WriteAllText(Application.StartupPath + "\Settings.bar", RichTextBox1.Text, True)
    End Sub
    Private Sub Form1_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDoubleClick
        Me.Hide()
    End Sub

    Private Sub RemoveToolStripMenuItem_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RemoveToolStripMenuItem.CheckedChanged
        If RemoveToolStripMenuItem.Checked = False Then
            Application.Restart()
        End If
    End Sub

    Private Sub ThemeToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ThemeToolStripMenuItem.Click, ThemeToolStripMenuItem.CheckedChanged
        If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
            Me.BackgroundImage = System.Drawing.Image.FromFile(OpenFileDialog1.FileName)
            My.Settings.backg = OpenFileDialog1.FileName
            My.Settings.Save()
        End If
    End Sub
    Private Sub AlwaysToolStripMenuItem_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AlwaysToolStripMenuItem.CheckedChanged
        If AlwaysToolStripMenuItem.Checked = False Then
            Me.TopMost = False
        Else
            Me.TopMost = True
        End If
    End Sub
    Private Sub NotifyIcon1_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseClick
        Me.Show()
    End Sub

    Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
        NotifyIcon1.Dispose()
        Me.Close()
    End Sub

    Private Sub ToolStripMenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem2.Click
        Me.Opacity = 100.0
        Me.Refresh()
    End Sub

    Private Sub ToolStripMenuItem3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem3.Click
        Me.Opacity = 75.0 / 100
    End Sub

    Private Sub ToolStripMenuItem4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem4.Click
        Me.Opacity = 50.0 / 100
        Me.Refresh()
    End Sub

    Private Sub ToolStripMenuItem5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem5.Click
        Me.Opacity = 25.0 / 100
        Me.Refresh()
    End Sub

    Private Sub DescriptionsOnOffToolStripMenuItem_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DescriptionsOnOffToolStripMenuItem.CheckedChanged
        If DescriptionsOnOffToolStripMenuItem.Checked = False Then
            Label3.Visible = False
        Else
            Label3.Visible = True
        End If
    End Sub
End Class

And thats you finished :D

Source-code for this tutorial:
IconBlock.zip

Enjoy!. Any questions please ask and I will help.
You do not have the required permissions to view the files attached to this post.
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
User avatar
Martin
Supreme VIP
Supreme VIP
Posts: 369
Joined: Sat Aug 01, 2009 12:26 pm

Re: iCon Block - SpinOff
Martin
It Dident Work Good For Me But I Like It clapper; clapper; clapper;
Image
User avatar
CodemaN
VIP Access - Denied
VIP Access - Denied
Posts: 74
Joined: Fri Sep 18, 2009 3:18 pm

Re: iCon Block - SpinOff
CodemaN
thank you man...!!!!
User avatar
Diazepa
VIP - Donator
VIP - Donator
Posts: 70
Joined: Sat Sep 12, 2009 11:38 pm

Re: iCon Block - SpinOff
Diazepa
Looks good!

A hint: Add tabs :D
User avatar
Nery
Co-Admin Moderator
Co-Admin Moderator
Posts: 1117
Joined: Mon Sep 07, 2009 8:11 pm

Re: iCon Block - SpinOff
Nery
Code: Select all
If IConBlockSpinoff.IsGreat = True Then
    Nery.happiness = 100%
Else
    Nery.WouldDo = ReportAllErrorsToCodenstuff
Endif
User avatar
Neki
Top Poster
Top Poster
Posts: 96
Joined: Sun Oct 11, 2009 10:12 am

Re: iCon Block - SpinOff
Neki
Great thing! I love it!
User avatar
RunarM
Hardcore Programmer
Hardcore Programmer
Posts: 508
Joined: Wed Nov 18, 2009 11:33 pm

Re: iCon Block - SpinOff
RunarM
How can i make it possible to move it?
Just another day in my life.
http://www.codexvideos.com
User avatar
tedhead2
Excellent Poster
Excellent Poster
Posts: 338
Joined: Sun Jan 03, 2010 8:36 am

Re: iCon Block - SpinOff
tedhead2
RunarM wrote:
How can i make it possible to move it?
Here:
Code: Select all
Form1.Postion= My.Computer.Mouse.Location
correct me if i'm wrong! :)
Image
User avatar
Bogoh67
VIP - Site Partner
VIP - Site Partner
Posts: 656
Joined: Sun Apr 18, 2010 8:20 pm

Re: iCon Block - SpinOff
Bogoh67
Martin64 wrote:
It Dident Work Good For Me But I Like It clapper; clapper; clapper;
yup i agree
User avatar
Bogoh67
VIP - Site Partner
VIP - Site Partner
Posts: 656
Joined: Sun Apr 18, 2010 8:20 pm

Re: iCon Block - SpinOff
Bogoh67
i have a question in the code what type is, "backg" and what does it say?
13 posts Page 1 of 2
Return to “Tutorials”