Results 1 to 14 of 14

Thread: Custom text box

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2011
    Location
    Sri Lanka
    Posts
    40

    Question Custom text box

    Im creating a simple application to search and manipulate a database.I want to add a text box to search a name but I want the textbox to be eyecandy.I dont want the traditional textbox.Instead I would like something like this



    Can anyone please tell me how to do this.I dont know how to make custom controls.Please help.
    Thank you

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Custom text box

    here's 2 examples of the same custom textbox (not the control your image pertains to):

    http://www.scproject.biz/Using%20Forms.htm#fifthexample

    http://www.scproject.biz/Using%20Forms.htm#sixthexample

  3. #3
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    Re: Custom text box

    This is as far as I got. Has not been fully tested.
    Attached Images Attached Images  
    Attached Files Attached Files

  4. #4

    Thread Starter
    Member
    Join Date
    Oct 2011
    Location
    Sri Lanka
    Posts
    40

    Re: Custom text box

    Quote Originally Posted by ForumAccount View Post
    This is as far as I got. Has not been fully tested.
    Thank you so much Master of Orion.But can you teach me how to use this in a windows form?I am new to programming and have no idea how to implement this on a vb form.

    Thank you

  5. #5
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: Custom text box

    Quote Originally Posted by chathu1234 View Post
    Thank you so much Master of Orion.But can you teach me how to use this in a windows form?I am new to programming and have no idea how to implement this on a vb form.

    Thank you
    Add his file to your project (right click the project in the solution explorer on the right, select add then select existing file), then build your project (from the build menu at the top of visual studio), then add the control to your form(s), it's at the very top with a purple "gear" icon of the toolbox on the left.
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  6. #6

    Thread Starter
    Member
    Join Date
    Oct 2011
    Location
    Sri Lanka
    Posts
    40

    Re: Custom text box

    Quote Originally Posted by ForumAccount View Post
    This is as far as I got. Has not been fully tested.
    Thank you master of Orion.I added your control via existing item and got it to working.I have got the textbox with rounded ends but I dont get the search image infront of the textbox.Can you please help to fix this issue

  7. #7

    Thread Starter
    Member
    Join Date
    Oct 2011
    Location
    Sri Lanka
    Posts
    40

    Re: Custom text box

    Thanks juggalobrotha..I managed to do that but the textbox does not show the search image on it.Can you take a look please
    Last edited by chathu1234; Dec 20th, 2011 at 09:18 PM.

  8. #8

    Thread Starter
    Member
    Join Date
    Oct 2011
    Location
    Sri Lanka
    Posts
    40

    Re: Custom text box

    Quote Originally Posted by .paul. View Post
    here's 2 examples of the same custom textbox (not the control your image pertains to):

    http://www.scproject.biz/Using%20Forms.htm#fifthexample

    http://www.scproject.biz/Using%20Forms.htm#sixthexample
    Thank you paul.I did not get what I wanted done from this.But I surely learnt a lot new.
    Thank you

  9. #9

    Thread Starter
    Member
    Join Date
    Oct 2011
    Location
    Sri Lanka
    Posts
    40

    Re: Custom text box

    Quote Originally Posted by JuggaloBrotha View Post
    Add his file to your project (right click the project in the solution explorer on the right, select add then select existing file), then build your project (from the build menu at the top of visual studio), then add the control to your form(s), it's at the very top with a purple "gear" icon of the toolbox on the left.
    Thanks juggalobrotha..I managed to do that but the textbox does not show the search image on it.Can you take a look please

  10. #10
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: Custom text box

    Quote Originally Posted by chathu1234 View Post
    Thanks juggalobrotha..I managed to do that but the textbox does not show the search image on it.Can you take a look please
    Add an ImageList (from the toolbox) to your form. Add a spyglass image to it, then on ForumAccountant's TextBox control set it's ImageList property to your form's ImageList and then it should show the image like in his screenshot picture.

    It might be easier to add an Image property to the control and an ImageAlignment property (being Left or Right) so that you just set a single image and tell it which side to display on.


    Edit: Oh, set the ImageKey property to the actual image that's in the ImageList too. Here's an example project.
    Attached Files Attached Files
    Last edited by JuggaloBrotha; Dec 20th, 2011 at 09:29 PM.
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  11. #11

    Thread Starter
    Member
    Join Date
    Oct 2011
    Location
    Sri Lanka
    Posts
    40

    Re: Custom text box

    Quote Originally Posted by JuggaloBrotha View Post
    Add an ImageList (from the toolbox) to your form. Add a spyglass image to it, then on ForumAccountant's TextBox control set it's ImageList property to your form's ImageList and then it should show the image like in his screenshot picture.

    It might be easier to add an Image property to the control and an ImageAlignment property (being Left or Right) so that you just set a single image and tell it which side to display on.


    Edit: Oh, set the ImageKey property to the actual image that's in the ImageList too. Here's an example project.
    Thank you so much Juggalobrotha...I got it to working.Is there a way to add the image to the control itself so I can use the control in every form.Otherwise I would have to add an imagelist to every form I create wouldnt I?

    And also I cant change the font in the textbox.Desperately need help on this also.

    Thanks in advance
    Last edited by chathu1234; Dec 22nd, 2011 at 01:17 AM.

  12. #12
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: Custom text box

    Well ultimately it uses an Image variable from the ImageList when rendering things, so it shouldn't be all that hard to just expose the Image property and you could do away with the ImageList properties altogether if you wanted to.

    Changing the Font should be as easy as exposing the underlaying TextBox's Font property. I see that he has a class that's used to overlay the actual textbox control and it's simply a matter of exposing those properties through the ImageTextBox class.

    I might have time this evening to poke around with it and see about getting the Font, Fore & Back color properties to be available in his control and I'll post it here.
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  13. #13
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: Custom text box

    I wasn't able to finish this, but I did get it to just be an Image property instead of using an ImageList and an ImageIndex property to have an image showing, but when you actually set it to an image, it crashes and I'm really at a loss to why, the error message shown (at design time, in the designer) doesn't help because the Paint event that uses the Image property already checks that it's not a null reference:
    Name:  Paint_Error.png
Views: 339
Size:  24.5 KB
    It has a problem with this block of code:
    Code:
            If Me.Image IsNot Nothing Then
                e.Graphics.DrawImage(Me.Image, Me.GetImageRectangle(), 0, 0, 16, 16, GraphicsUnit.Pixel)
            End If
    I also added the Font, ForeColor and BackColor properties too, though if you change the font (right now) to a larger font then you have to re-size the control on the form yourself to accomodate that. I don't know how to have the control re-size itself vertically like a normal textbox does when you change the font size (and the TB is not allowing multiple lines of course).

    Other than those 2 issues, it's mostly done for you. If I get the chance next week I might try and finish it, but I suspect ForumAccountant will get to it before me anyways.
    Attached Files Attached Files
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  14. #14

    Thread Starter
    Member
    Join Date
    Oct 2011
    Location
    Sri Lanka
    Posts
    40

    Re: Custom text box

    Quote Originally Posted by JuggaloBrotha View Post
    I wasn't able to finish this, but I did get it to just be an Image property instead of using an ImageList and an ImageIndex property to have an image showing, but when you actually set it to an image, it crashes and I'm really at a loss to why, the error message shown (at design time, in the designer) doesn't help because the Paint event that uses the Image property already checks that it's not a null reference:
    Name:  Paint_Error.png
Views: 339
Size:  24.5 KB
    It has a problem with this block of code:
    Code:
            If Me.Image IsNot Nothing Then
                e.Graphics.DrawImage(Me.Image, Me.GetImageRectangle(), 0, 0, 16, 16, GraphicsUnit.Pixel)
            End If
    I also added the Font, ForeColor and BackColor properties too, though if you change the font (right now) to a larger font then you have to re-size the control on the form yourself to accomodate that. I don't know how to have the control re-size itself vertically like a normal textbox does when you change the font size (and the TB is not allowing multiple lines of course).

    Other than those 2 issues, it's mostly done for you. If I get the chance next week I might try and finish it, but I suspect ForumAccountant will get to it before me anyways.
    Thank you so much JuggaloBrotha for taking your valuable time and coming up with a solution.But unfortunately there is something wrong.When I change the font it displays the changes.But when I build the solution it automatically reverts back to the original font.

    Thanks for your help.

    This is the best forum.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width