none
How to disable access to a text box, keeping normal look?

    Question

  • Is there a way in this environment, in a .vb 2005 project, to 'protect' a text box from focus or access in any way, while at the same time keeping it looking like 'normal'?  I tried setting the 'Enabled' property to 'False', and that does indeed prevent the user from focusing on the field.  But the problem is that it no longer shows the BackColor defined for that field; it is defined as 'Orange', and that was what it showed before I changed 'Enabled' to 'False', but now it shows a blah-looking default silver back color.  And, the text in the box is 'washed out' and looks like it is in the background, making it hard to read.

    How can I keep the same colors and boldness, etc., while preventing the user from accessing that text box?  TIA

     

     

    Thursday, June 08, 2006 3:26 AM

Answers

  • I would first question why you want to do this. The reason the disabled box looks different is to provide a visual cue to the user that he can't type anything. Otherwise, he would keep typing and wonder why his keystrokes are not appearing.

    If you still want to do this, just handle one of the KeyPress/Down events and cancel out the character.

    Thursday, June 08, 2006 4:14 AM

All replies

  • I would first question why you want to do this. The reason the disabled box looks different is to provide a visual cue to the user that he can't type anything. Otherwise, he would keep typing and wonder why his keystrokes are not appearing.

    If you still want to do this, just handle one of the KeyPress/Down events and cancel out the character.

    Thursday, June 08, 2006 4:14 AM
  • I don't know of a way to paste a graphic image here, to show what I'm trying to accomplish, but hopefully this link will show it:

    http://www.solutionsforaccounting.com/cotton/Location.html

    I only have one text box ('Current Bale') where data should be entered (or, more typically, scanned in with this barcode device), but I've used colored text boxes to show other information such as counters.  But I recently ran into a problem where the user accidentally pushed on the screen with their thumb while placing the device in it's dock, and the place they pushed happened to be in the 'Grand Total' field, giving it focus, which is not good for several reasons.

    So, I'm trying to find a way to still show that nice orange background for my total fields without the user being able to accidentally focus on that field.  And, when I try using the 'disabled' approach, it does indeed prevent this problem, but it no longer looks good on the screen, as the color changes and is faded.

    Is there any way to keep the total field looking like it does while preventing the user from gaining access to that field?  Or, a there another way in vb to show this data, but disallowing access, by using something other than a text box?  Seems like I tried all kinds of options from the toolbox, but none looked this good--large, colorful, and offset in it's own rectangular box.

     

    Saturday, June 10, 2006 4:04 PM
  • how about setting the textbox's ReadOnly value to true, then setting the textbox's BackColor to orange? i hope this helps
    Friday, June 16, 2006 6:25 AM
  • Well, I can't get that to solve the problem...but if it works for you, I'd sure like to know what you're doing different than I am!  When I change the ReadOnly value to true, that too causes the box to grey out at runtime, yet it still lets me focus in the field (if I try), which I need to avoid being able to do.  Meanwhile, the backcolor is still showing as Orange on the properties for the textbox.

    So, I'm starting to think the solution is to use something other than a textbox to show my totals on the screen, but I don't what would look as good using other tools.  Any idea what other developers are doing to highlight totals or counters on their screens, making them easy to see, yet inaccessible to the user?  (i.e. can't accidentally focus on that 'field').

     

    Tuesday, June 20, 2006 2:04 AM
  • I suggest hiding the textbox and creating a label to display the text. You can hide/unhide the textbox and the label dynamically. To help you understand what I mean allow me to refer to the PPC Contact editor. Notice how controls (text boxes and dropdowns) are replaced with labels (actually, custom controls) and shown/enabled only when activated
    Tuesday, June 20, 2006 4:51 AM
  • hmm, mine doesn't gray out on runtime. you can access it with your mouse cursor right? how about adding code to the event of the mouse clicking on the text box and set focus to the previous one? if by tabs, just make the tabstop value to false.
    OR
    you can use a label instead of a textbox, then format its backcolor and other options so it'll look like your orange textbox. you can't set focus on this thing.

    Tuesday, June 20, 2006 5:08 AM