Results 1 to 24 of 24

Thread: [RESOLVED] [2005] Textbox.enabled question

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2006
    Posts
    734

    Resolved [RESOLVED] [2005] Textbox.enabled question

    Hi guys,

    this is probably a really easy question, but is there any way to disable a textbox but still allow the scroll bar to scroll, because i am setting up a simple messaging system.

    Now i am displaying it in a textbox, but have disabled the textbox so that the user cant alter any of the text in the message they are reading. But if the message is longer than what will fit in the textbox then the user cant read the rest of the message because the scrollbar is also disabled.

    So is there any way around this?

    Thanks in advance for any help
    If your problem has been solved then please mark the thread [RESOLVED].
    If i have helped then please Rate my post

  2. #2
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Re: [2005] Textbox.enabled question

    So, if you set the scroll property to vertical and the textbox to read only, the scroll bars still work.
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  3. #3
    Junior Member
    Join Date
    Apr 2007
    Posts
    19

    Re: [2005] Textbox.enabled question

    suppose ur textbox name is text1 then add the following code
    vb Code:
    1. Private sub text1_keypress(byval keyascii as integer)
    2.           Select case chr(keyascii)
    3.                    case else
    4.                          keyascii=0
    5.            end select
    6. end sub

    If your problem has been solved then please mark the thread [RESOLVED].
    If i have helped then please Rate my post

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Textbox.enabled question

    A disabled control is one that accepts no user interaction. Scrolling is user interaction so that's not disabled.

    As I'm sure I've suggested to you before, if you want to do something with or to a class you should look at what members the class provides before doing ANYTHING else. Had you done that you'd have seen the ReadOnly property, which name I would think would suggest to you its use. If not then the description surely would have:
    Controls whether the text in the edit control can be changed or not.
    Presumably you were using the IDE when you decided you need this so the Properties window would have been right there in front of you. Don't ignore the obvious resources at your disposal.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5
    Junior Member
    Join Date
    Apr 2007
    Posts
    19

    Re: [2005] Textbox.enabled question

    u dont have to alter the text box properties

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Textbox.enabled question

    Quote Originally Posted by tarencer
    u dont have to alter the text box properties
    Your code is for VB6 so not relevant to VB.NET. Also, why would you bother writing code when you can set a single property at design time that is specifically designed to perform the desired task?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7
    Frenzied Member Phill64's Avatar
    Join Date
    Jul 2005
    Location
    Queensland, Australia
    Posts
    1,201

    Re: [2005] Textbox.enabled question

    Quote Originally Posted by jmcilhinney
    A disabled control is one that accepts no user interaction. Scrolling is user interaction so that's not disabled.

    As I'm sure I've suggested to you before, if you want to do something with or to a class you should look at what members the class provides before doing ANYTHING else. Had you done that you'd have seen the ReadOnly property, which name I would think would suggest to you its use. If not then the description surely would have:Presumably you were using the IDE when you decided you need this so the Properties window would have been right there in front of you. Don't ignore the obvious resources at your disposal.
    lol, he makes a good point

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2006
    Posts
    734

    Re: [2005] Textbox.enabled question

    I tried the readonly option, but that made the appearance of the form seem worse because the backcolor of the textbox changed to the colour of the panel it was on and also it displayed the caret which i didn't want.
    If your problem has been solved then please mark the thread [RESOLVED].
    If i have helped then please Rate my post

  9. #9
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Re: [2005] Textbox.enabled question

    but that made the appearance of the form seem worse because the backcolor of the textbox changed to the colour of the panel
    Surely the simple solution would be to change its BackColor property again after making it Read Only....
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2006
    Posts
    734

    Re: [2005] Textbox.enabled question

    Nope...it tried that...the backcolor of the textbox is white, then when i make it readonly it changes it to the backcolor of the panel (which is blue).
    If your problem has been solved then please mark the thread [RESOLVED].
    If i have helped then please Rate my post

  11. #11
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Textbox.enabled question

    Quote Originally Posted by Kimmy4
    I tried the readonly option, but that made the appearance of the form seem worse because the backcolor of the textbox changed to the colour of the panel it was on and also it displayed the caret which i didn't want.
    It's always a good idea to provide all relevant information when posting. If you don't like the BackColor then change it. As for the caret, the text is still selectable to facilitate copying to the clipboard but I believe that there's a Windows API function that will hide it.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  12. #12
    Fanatic Member pvbangera's Avatar
    Join Date
    Sep 2001
    Location
    Mumbai, India
    Posts
    961

    Re: [2005] Textbox.enabled question

    then, change the backcolor of ur textbox

    TextBox1.BackColor = Color.White
    Microsoft Techie

  13. #13
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Textbox.enabled question

    Quote Originally Posted by Kimmy4
    Nope...it tried that...the backcolor of the textbox is white, then when i make it readonly it changes it to the backcolor of the panel (which is blue).
    Setting the ReadOnly property to True sets the BackColor property to Control. You then simply set the BackColor rpoperty to Window AFTERWARDS.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  14. #14
    Frenzied Member Phill64's Avatar
    Join Date
    Jul 2005
    Location
    Queensland, Australia
    Posts
    1,201

    Re: [2005] Textbox.enabled question

    Quote Originally Posted by Kimmy4
    I tried the readonly option, but that made the appearance of the form seem worse because the backcolor of the textbox changed to the colour of the panel it was on and also it displayed the caret which i didn't want.
    It just sets the backcolor property, you can change it back with no problem it's not property reliant.

    As for the newline symbols, i dont seem to get that problem, are you using VbNewLine ?

  15. #15
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Textbox.enabled question

    Quote Originally Posted by pvbangera
    then, change the backcolor of ur textbox

    TextBox1.BackColor = Color.White
    Use Window, not White. That way it will be consistent regardless of the current theme.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  16. #16
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Re: [2005] Textbox.enabled question

    edit: I'm too slow
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  17. #17

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2006
    Posts
    734

    Re: [2005] Textbox.enabled question

    As for the caret, the text is still selectable to facilitate copying to the clipboard but I believe that there's a Windows API function that will hide it.
    I found the code to get rid of the caret a while and tried it but couldn't get it to work as i kept getting an error, i found a post with someone else who was getting the same error and nobody had come up with a solution and i couldn't find one when searching the net for one.

    Use Window, not White. That way it will be consistent regardless of the current theme.
    In the code i am writing the lines:

    txtMessage.ReadOnly = True
    txtMessage.BackColor = Color.White

    How do i set it to window in code (not using the properties) as it only gives the color. options? And even using that code it still made the textbox backcolor blue!
    If your problem has been solved then please mark the thread [RESOLVED].
    If i have helped then please Rate my post

  18. #18
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Textbox.enabled question

    Quote Originally Posted by Kimmy4
    In the code i am writing the lines:

    txtMessage.ReadOnly = True
    txtMessage.BackColor = Color.White

    How do i set it to window in code (not using the properties) as it only gives the color. options? And even using that code it still made the textbox backcolor blue!
    That code worked perfectly for me.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  19. #19

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2006
    Posts
    734

    Re: [2005] Textbox.enabled question

    Edit: It seems there is another problem which is causing the text to disappear as my boss has changed the xml file i am getting it from so i've gotta wait until he changes it back before i can test properly whether the color change works.

    I'll let you know.
    Last edited by Kimmy4; May 15th, 2007 at 06:35 AM.
    If your problem has been solved then please mark the thread [RESOLVED].
    If i have helped then please Rate my post

  20. #20
    Frenzied Member Phill64's Avatar
    Join Date
    Jul 2005
    Location
    Queensland, Australia
    Posts
    1,201

    Re: [2005] Textbox.enabled question

    Quote Originally Posted by Kimmy4
    I added the color change code after i added the text to the textbox and it changed the color of the textbox...but now i have lost my text.

    I guess i'm just going to have to leave it as blue!
    Text being lost from a color change im pretty sure is NOT normal behaviour, either you have a problem with your framework, or more likely, there's more code to this issue that you're not telling us about.

  21. #21
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Textbox.enabled question

    Oops! I forgot to post my own code in post #18. Should have been:
    vb.net Code:
    1. txtMessage.ReadOnly = True
    2. txtMessage.BackColor = SystemColors.Window
    The actual Colors returned by the members of the SystemColors class are determine by the current Windows theme. Window will return White in the default theme but may return some other colour in another theme.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  22. #22

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2006
    Posts
    734

    Re: [2005] Textbox.enabled question

    Phill64 -> I editted my post before i got ur reply! There is another problem as explained in post #19.

    jmcilhinney -> Thanks for that, i'll try that out as soon as my earlier problem is fixed by my boss.
    Last edited by Kimmy4; May 15th, 2007 at 07:01 AM.
    If your problem has been solved then please mark the thread [RESOLVED].
    If i have helped then please Rate my post

  23. #23

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2006
    Posts
    734

    Re: [2005] Textbox.enabled question

    Tried it after my boss fixed his problem and it still didn't change the color, but my boss said the blue will do.

    Thanks everyone for their input.

    If your problem has been solved then please mark the thread [RESOLVED].
    If i have helped then please Rate my post

  24. #24
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [RESOLVED] [2005] Textbox.enabled question

    The colour change is supposed to be a visual cue to the user that the field is read-only anyway, so having it so not such a bad idea.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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