Locking Box Against Input

Locking Box Against Input

I want to disable a text box without having its text dimmed. I know of one way, which is put the controlinto a picture box and disable the picture box. But I am looking for a solution that maybe uses an APIcall or something that does not involve using another control. Thank you.

For VB4.0 it’s easy, just set the Locked property to True on the control. That will prevent the user from entering text and also prevent the box from showing the text as disabled.For VB3.0 it’s somewhat harder. You need to use the SendMessage API call. The following code should do it for you, as always, make sure each declare is on one line:

‘the main function declareDeclare Function SendMessage Lib “User” (ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, lParam As Any) As LongConst WM_USER = &H400    ‘base constant for API SendMessage function’Const for SendMessage to set/unset a textbox’s read only statusConst EM_SETREADONLY = (WM_USER + 31)’this is called from elsewhere to set/unset the readonly status of a textbox.  Pass it True to set and False’to unset (passed as “flag”)Sub RoSet (flag As Integer)Dim retVal As LongDim i As IntegerDim msg As String’this just sets up the proper string for the message box in the errortrapSelect Case flag  Case True    msg = “Could Not Set One or More Textboxes To Read-Only Status!”  Case False    msg = “Could Not Remove Read-Only Status From One or More Textboxes!”End Select’please note that this code is from a program I wrote where I wanted to set/unset more than one’textbox at a time.  The important line in the next loop is:’retVal = SendMessage(frmMain.Controls(i).hWnd, EM_SETREADONLY, flag, 0&)’simply change “frmMain.Controls(i).hWnd” to reflect the textbox(es) you wish to changeFor i = 0 To frmMain.Controls.Count – 1    If TypeOf frmMain.Controls(i) Is TextBox Then        retVal = SendMessage(frmMain.Controls(i).hWnd, EM_SETREADONLY, flag, 0&)        GoSub TextBoxError    End IfNext i        Exit SubTextBoxError:If retVal = 0 Then    ‘ Check the return value for error    MsgBox msgEnd IfReturnEnd Sub

Share the Post:
XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes

ransomware cyber attack

Why Is Ransomware Such a Major Threat?

One of the most significant cyber threats faced by modern organizations is a ransomware attack. Ransomware attacks have grown in both sophistication and frequency over the past few years, forcing

data dictionary

Tools You Need to Make a Data Dictionary

Data dictionaries are crucial for organizations of all sizes that deal with large amounts of data. they are centralized repositories of all the data in organizations, including metadata such as