A Smarter TextBox-VBForums
Results 1 to 14 of 14

Thread: A Smarter TextBox

  1. #1

    Thread Starter
    Hyperactive Member DavesChillaxin's Avatar
    Join Date
    Mar 2011
    Location
    WNY
    Posts
    451

    A Smarter TextBox

    Description: This is a modified Windows TextBox control with some additional functionality, that I think you'll find as useful as I have.

    Update (11/13/2012 10:30PM)
    Removed input types, and replaced them with an 'Exclude' property. '0987654321' will exclude all numeric characters
    Enhanced the watermark.
    Add 'NullValue' that displays when the Text is null.

    enjoy!

    This project demonstrates the following..
    Technique for drawing on controls such as the Windows TextBox control.
    Nothing more than simple control manipulations and the basics in good practice in this one!
    Attached Images Attached Images  
    Attached Files Attached Files
    Last edited by DavesChillaxin; Nov 12th, 2012 at 09:39 PM.
    Please rate if my post was helpful!
    Per favore e grazie!




    Code Bank:
    Advanced Algebra Class *Update | True Gradient Label Control *Dev | A Smarter TextBox *Update | Register Global HotKey *Update
    Media Library Beta *Dev | Mouse Tracker (Available in VB.net and C#.net) *New | On-Screen Numpad (VB.net) *New

  2. #2
    Fanatic Member BenJones's Avatar
    Join Date
    Mar 2010
    Location
    Wales UK
    Posts
    562

    Re: *NEW* SmartTextBox

    Looks usfull thanks for shareing. ps can I ask how do you color the VB.NET in the posts

  3. #3
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,716

    Re: *NEW* SmartTextBox

    Quote Originally Posted by BenJones View Post
    ps can I ask how do you color the VB.NET in the posts
    Just put your code in [HIGHLIGHT="vbnet"]your code here[/HIGHLIGHT] tags

  4. #4
    Fanatic Member BenJones's Avatar
    Join Date
    Mar 2010
    Location
    Wales UK
    Posts
    562

    Re: *NEW* SmartTextBox

    Thanks CVMichael I try it out on one of my next posts.

  5. #5

    Thread Starter
    Hyperactive Member DavesChillaxin's Avatar
    Join Date
    Mar 2011
    Location
    WNY
    Posts
    451

    Re: *NEW* SmartTextBox

    Quote Originally Posted by BenJones View Post
    Looks usfull thanks for shareing. ps can I ask how do you color the VB.NET in the posts
    Yup just as he said, Click the 'VBCode" then whent he input message pops up type "vbnet".

    Also thanks! I feel this is extremely useful. I'm truly surprised Microsoft didn't have anything like this with their own. Especially the input restrictions. Not every textbox in every context takes every input value. Makes things much easier to simply restrict them from the start so you don't have to worry about it later.

    I just updated to some more restrictions. More specifics like currency and my numeric now lets some specific digits through, whereas my new strictly numeric type only allows numerical values.

    EDIT: I'd like to note my title is a little misleading, it is not completely my own. But rather implemented and customized to expand functionality.
    Last edited by DavesChillaxin; Jan 24th, 2012 at 01:54 PM.
    Please rate if my post was helpful!
    Per favore e grazie!




    Code Bank:
    Advanced Algebra Class *Update | True Gradient Label Control *Dev | A Smarter TextBox *Update | Register Global HotKey *Update
    Media Library Beta *Dev | Mouse Tracker (Available in VB.net and C#.net) *New | On-Screen Numpad (VB.net) *New

  6. #6
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    3,811

    Re: *NEW* SmartTextBox

    Though this looks like a great start to an all-in-one textbox control, I do see a few things with it. If you're going to be handling currency you should probably make use of the globalization to determine if the input is valid for currency, rather than hard code $'s, or pound sign (£ or ₤) and so on.

    DavesChillaxin, one of the reasons a control like this isn't natively in the framework is probably because MS developed separate controls for these types of things, really the only thing that your control does that none of the current MS ones do is the watermark. For numeric only input there's the NumericUpDown control, for standard text box there's the TextBox & for anything that needs to be specially formatted (like currency or a phone number, or SSN, etc) there's the MaskedTextBox where you set the input mask to what you need. Separate controls for specific needs instead of 1 control for most (or all) needs.

  7. #7

    Thread Starter
    Hyperactive Member DavesChillaxin's Avatar
    Join Date
    Mar 2011
    Location
    WNY
    Posts
    451

    Re: *NEW* SmartTextBox

    Quote Originally Posted by JuggaloBrotha View Post
    Though this looks like a great start to an all-in-one textbox control, I do see a few things with it. If you're going to be handling currency you should probably make use of the globalization to determine if the input is valid for currency, rather than hard code $'s, or pound sign (£ or ₤) and so on.
    I had already considered this, but for my application I'm sticking with whats local. The program I initially made this for has no intentions of ever handling any currency types other than USD or any type that uses the $ sign. Small business' don't handle more than one type of currency at a time so to have that option would be a flop. Rather I could have another property set aside for when currency has been selected, you can then input the currency sign of your requirements(by default $ would be used)


    DavesChillaxin, one of the reasons a control like this isn't natively in the framework is probably because MS developed separate controls for these types of things, really the only thing that your control does that none of the current MS ones do is the watermark. For numeric only input there's the NumericUpDown control, for standard text box there's the TextBox & for anything that needs to be specially formatted (like currency or a phone number, or SSN, etc) there's the MaskedTextBox where you set the input mask to what you need. Separate controls for specific needs instead of 1 control for most (or all) needs.
    I feel if a company has passwords, such as PINS - then a numericupdown would definitely not be the control to use. So still I would have to create a textbox, and then code under it's respectable events to restrict all characters but numbers. This is a lot more work to do when all I would have to do is add my modified textbox and select it's input type to numeric only. Same for currency and phone input fields. I have multiples of them, and I don't want to have to code them all. My application is a business management and inventory system. I have multiple forms with specific input fields. I'm not about to code every single one of those textboxes when I can add mine, and select a property to specify it's input types.


    Also the decimal point. I have my modified textbox restricting only one to be passed when the input type involve numerics. To have more than one would always cause problems unless dealing with IPs-which I feel like adding as a specific input type.


    So really I'm just controlling the input of characters. I'm not formatting the text to any specific format types. Just restricting specific characters according to what the developers use for that textbox might be. Solves the problem at the source.
    Last edited by DavesChillaxin; Jan 26th, 2012 at 12:43 PM.
    Please rate if my post was helpful!
    Per favore e grazie!




    Code Bank:
    Advanced Algebra Class *Update | True Gradient Label Control *Dev | A Smarter TextBox *Update | Register Global HotKey *Update
    Media Library Beta *Dev | Mouse Tracker (Available in VB.net and C#.net) *New | On-Screen Numpad (VB.net) *New

  8. #8
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    3,811

    Re: *NEW* SmartTextBox

    Quote Originally Posted by DavesChillaxin View Post
    I had already considered this, but for my application I'm sticking with whats local. The program I initially made this for has no intentions of ever handling any currency types other than USD or any type that uses the $ sign. Small business' don't handle more than one type of currency at a time so to have that option would be a flop. Rather I could have another property set aside for when currency has been selected, you can then input the currency sign of your requirements(by default $ would be used)
    Something like that could always be put in later if the situation where to arise. I could see where even a small company could deal with multiple currencies in Europe , but here in the Americas I agree with you.

    Though come to think of it, I have had a situation where I wanted numeric only input (a measurement in inches) and I wanted to show the inch symbol (") on the right of the number, I ended up making my own NumericUpDown control that inherited the one in the framework and had it display the " after the number but still functioned exactly like a NUD (the Value property still returned the numeric value as a Decimal), so the Text property would show 4.3" but the Value property returns 4.3D, You could do something similar for currency and have it get the symbol to show from the language globalization.
    Just something to think about.
    Quote Originally Posted by DavesChillaxin View Post
    I feel if a company has passwords, such as PINS - then a numericupdown would definitely not be the control to use. So still I would have to create a textbox, and then code under it's respectable events to restrict all characters but numbers. This is a lot more work to do when all I would have to do is add my modified textbox and select it's input type to numeric only. Same for currency and phone input fields. I have multiples of them, and I don't want to have to code them all. My application is a business management and inventory system. I have multiple forms with specific input fields. I'm not about to code every single one of those textboxes when I can add mine, and select a property to specify it's input types.
    For entering a PIN, I wouldn't use a NumericUpDown either and because of all the work involved in maintaining the code to restrict a TextBox to only allowing numeric only input and enforcing a number of digits the PIN is (4 digit PIN, 6 digit PIN, etc) I would use a MaskedTextBox control and set it's Mask property to "0000" for a 4 digit PIN or "000000" if it's a 6 digit PIN, the "0" means that character is numeric only not counting a decimal and is required so it can't be blank either. 4 of them together means all 4 of them are required in the same manor.
    Here's more the Mask property: http://msdn.microsoft.com/en-us/libr...tbox.mask.aspx

    Anything that requires a format like this is where I would use a MTB.
    Quote Originally Posted by DavesChillaxin View Post
    Also the decimal point. I have my modified textbox restricting only one to be passed when the input type involve numerics. To have more than one would always cause problems unless dealing with IPs-which I feel like adding as a specific input type.
    Same thing can be done with an MTB and the Mask would be something like "990.990.990.990"
    Quote Originally Posted by DavesChillaxin View Post
    So really I'm just controlling the input of characters. I'm not formatting the text to any specific format types. Just restricting specific characters according to what the developers use for that textbox might be. Solves the problem at the source.
    Like I said, this control you've got started here could easily become an all-in-one control if that's what you're really wanting, but personally I've never felt the need to want to maintain a control like this because situations are going endlessly arise where you're constantly having to go back and revise it because of some requirement you've got with it or maybe even because something in Windows or in the Framework has changed and now your control needs to be updated to accommodate it. I tend to have different controls for the different purposes and I try to use what's in the FW as much as possible so that MS keeps it up to date, not me. I have enough to maintain in my programs as it is. Just saying.

  9. #9

    Thread Starter
    Hyperactive Member DavesChillaxin's Avatar
    Join Date
    Mar 2011
    Location
    WNY
    Posts
    451

    Re: *NEW* SmartTextBox

    Oh well, everyone's a critic online.
    Please rate if my post was helpful!
    Per favore e grazie!




    Code Bank:
    Advanced Algebra Class *Update | True Gradient Label Control *Dev | A Smarter TextBox *Update | Register Global HotKey *Update
    Media Library Beta *Dev | Mouse Tracker (Available in VB.net and C#.net) *New | On-Screen Numpad (VB.net) *New

  10. #10

    Thread Starter
    Hyperactive Member DavesChillaxin's Avatar
    Join Date
    Mar 2011
    Location
    WNY
    Posts
    451

    Re: *NEW* SmartTextBox

    EDIT: Actually I figured one out through some research. Check the original post for the update.

    Does anyone know a better watermark method than the one used here? I'm not sure why but by changing the actual text through certain events can get tricky and seems to have it's hiccups. My first attempt which seemed bullet proof was to selectively overrides the paint event, but I soon realized this is nearly impossible when inheriting the textbox. My researched taught me the textbox draws... differently. So that idea was scratched quickly.

    Also I'd prefer not to change the text for any value returning purposes. I don't want to by accident return the watermark when calling for the Text value. Just seems like a bad idea anyway, but for now it was my only option.

    Thanks in advanced!
    Last edited by DavesChillaxin; Jan 28th, 2012 at 10:06 AM.
    Please rate if my post was helpful!
    Per favore e grazie!




    Code Bank:
    Advanced Algebra Class *Update | True Gradient Label Control *Dev | A Smarter TextBox *Update | Register Global HotKey *Update
    Media Library Beta *Dev | Mouse Tracker (Available in VB.net and C#.net) *New | On-Screen Numpad (VB.net) *New

  11. #11
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    3,412

    Re: *NEW* SmartTextBox

    Quote Originally Posted by DavesChillaxin View Post
    Does anyone know a better watermark method than the one used here?
    You can add watermark to edit box using API,
    SendMessage(handle, EM_SETCUEBANNER, 0, "text")

    I did it for combo box as well, posted here
    Last edited by Edgemeal; Dec 28th, 2012 at 07:03 PM.

  12. #12
    Frenzied Member MattP's Avatar
    Join Date
    Dec 2008
    Location
    WY
    Posts
    1,227

    Re: *NEW* SmartTextBox

    Quote Originally Posted by DavesChillaxin View Post
    Does anyone know a better watermark method than the one used here?
    There are a couple of different ways that I gave here: http://www.vbforums.com/showthread.p...-box-watermark
    This pattern in common to all great programmers I know: they're not experts in something as much as experts in becoming experts in something.

    The best programming advice I ever got was to spend my entire career becoming educable. And I suggest you do the same.

  13. #13
    Member
    Join Date
    Feb 2011
    Posts
    46

    Re: *NEW* SmartTextBox

    is this works with multiline textbox

  14. #14
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    3,412

    Re: *NEW* SmartTextBox

    Quote Originally Posted by rojaldearintok View Post
    is this works with multiline textbox
    Not if you use EM_SETCUEBANNER, when in doubt look it up on MSDN...

    EM_SETCUEBANNER message
    Remarks
    An edit control that is used to begin a search may display "Enter search here" in gray text as a textual cue. When the user clicks the text, the text goes away and the user can type.
    You cannot set a cue banner on a multiline edit control or on a rich edit control.
    Minimum supported client: Windows XP
    Minimum supported server: Windows Server 2003

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
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.