Saturday, December 1, 2012

Create the Search TextBox


In Windows 8, there is no Start Menu. Is a good idea to start creating our own Windows 8 Start Menu. That menu is custom and programmed in Visual Basic with the Express Edition or with the Professional Edition.

In the previous post, we were able to create a form and place it over the taskbar. Now let’s take a look on something interesting in the Windows Start Menu. Please take a look at the next image.


[ In the Windows 7 Start menu]
 In the Windows 7 Start menu

There is a textbox use to help you find a program or a file in your computer. Personally, I never liked the windows search tools because it never gives me the file I wanted. Now this is our time to create our custom search textbox.

Unfortunately, we can’t just put a textbox. It is too simple. Text search box comes with a little button with a magnet inside it. That little button is part of the design of the window Start Button and even if you don’t think is useful; we still have to put it.

Otherwise, the Start Menu will not look like the windows Start Menu, right?
There are 2 ways we could do it and I will show you: the usercontrol and inherits function. There are no controls like that in Visual Basic Express 2010 or Visual Studio 2010. You have to build the control.

For those of you who are too lazy to do a usercontrol or a the new textbox type, is OK. Just skip the reading. Make a simple textbox with a button next to it (or over it). It will work but it won’t give the same feeling.

Here is the sample of my new TextBox.

''' <summary>
''' English: this is a sample of Inherits
''' Francais: ceci est un exemple d'héritage
''' </summary>
''' <remarks></remarks>
Public Class TextBoxButton
    Inherits TextBox

    Public mButton As Button
    Public Property Button As Button
        Get
            Return mButton
        End Get

       Set(value As Button)
            mButton = value
        End Set
    End Property
    Protected Overrides Sub OnCreateControl()
        Me.Controls.Add(Me.mButton)
        Me.mButton.Dock = DockStyle.Right
        MyBase.OnCreateControl()
    End Sub
    Public Sub New()
        MyBase.New()
        mButton = New Button
        With Me.mButton
            .Width = 20
            .FlatAppearance.BorderSize = 0
            .FlatStyle = FlatStyle.Popup
            .BackColor = Color.Transparent
            .Image = My.Resources.search.ToBitmap 'put the image you want
        End With

    End Sub
End Class


My new textbox is called TextBoxButton. Is simple a button inside a Textbox. So my Textbox is some kind of a enhance Textbox. So instead of using the regular Textbox from System.Windows.Forms.Textbox , I’ll use this improved textbox.

The class is very small and I done it like that on purpose. It is easy to improve it because it works the same way as a class form where you could put function or variables.

If you use and add the TextboxButton, you will see something like the next image:


TextBox without button


The icon button inside the textbox makes it better. That is good for the user.
TextBox with button


Edit : January 26th 2013

Download the sample project here : WindowsApplication1.zip




8 comments:

  1. Can I download this?

    ReplyDelete
    Replies
    1. Wait until Sunday, i will place the sample project and you could download it.
      I "upgraded" the sample project and i havent keep the original one.

      Delete
  2. you select the file then click download

    ReplyDelete
  3. i downloaded WindowsApplication1.zip program and ran it but it doesn't
    do anything. does it work yet?
    papat555@yahoo.com

    ReplyDelete
    Replies
    1. it doesn't do anything because there is no search function inside. Is only the control object (inherit TextBox with a search button). We have to add an event handler or something like that too.

      Delete
  4. Nice post, it works good!
    And was that i stay looking for...

    ReplyDelete
  5. Hey There. I found your blog using msn. This is a very well written article. I’ll be sure to bookmark it and come back to read more of your useful info. Thanks for the post. I’ll definitely return.
    Search Button

    ReplyDelete