0

I have a textbox in VB6 Control with some data populated from database. When there is no data, it will be blank. Now my requirement is, that textbox should be Read only and it should have some tooltip text.

I tried to keep Textbox1.Enabled = false But this is not displaying my tooltip. When I keep Textbox1.Locked = True I am getting the tooltip, But I am able to edit the text in the textbox, we should not be able to do that.

Please suggest me any solution.

satyanarayana
  • 379
  • 1
  • 5
  • 19
  • 2
    How come you are able to edit text in `TextBox` when its `Locked` property is set to `True`? How do you achieve it, exactly? – Ilya Kurnosov Feb 13 '14 at 11:09
  • Agree, if its locked it cannot accept input (although you can focus it) – Alex K. Feb 13 '14 at 11:12
  • Yes Ilya Kurnosov. I am able to edit the text even if I set Locked =True. I dont know why it is happening. Am I missing something? Please help me out. – satyanarayana Feb 13 '14 at 11:15
  • 1
    Have you tried typing something? Does it alter the contents of the box or just allow you to highlight and display a blinking cursor? Also, perhaps it would be better to pass the information into a label or alternative control if it's not going to be edited. – Paul Feb 13 '14 at 11:25
  • Yes Westie. I am able to type in the data not only the blinking cursor. If there is no way we can do with the textbox, I have to go with label only. – satyanarayana Feb 13 '14 at 11:32
  • Are any events attached to the box that alter the locked state because if you make it .Locked you most certainly should not be able to type into it at all. – Alex K. Feb 13 '14 at 14:10
  • @satyanarayana: Another thing you could try is `MsgBox`ing the current state of the `Locked` property when you click on it, just to make sure it's set. Chances are another piece of code is altering the state of the text box or possibly you *may* be assigning the `Lock` to the wrong text box. – Paul Feb 13 '14 at 16:36

1 Answers1

0

As the other have pointed out the Locked property should work, You can try using the Windows API.

Option Explicit

Private Const EM_SETREADONLY = &HCF

Private Sub Form_Load()

    Call SendMessage(Text1.hwnd, EM_SETREADONLY, 1, 0)

End Sub
jac
  • 9,666
  • 2
  • 34
  • 63