Help: Using Sendmessage to toggle checkbox into checked state


  • Hi,

    I am using VisualStudio 2017 and I am trying to use the sendmessage function to toggle a checkbox into checked state, but without succeeding.

    My code:

    Imports System.Runtime.InteropServices

    Public Class Form2

        Private Const BST_CHECKED As Int32 = &H1
        ' Checkbox is checked
        Private Const BM_SETCHECK As Int32 = &HF1
        ' Set the check state of the checkbox

        Declare Auto Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As Int32

        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
           SendMessage(Checkbox1.Handle, BM_SETCHECK, BST_CHECKED, 0)
        End Sub

    Thanks for your help in advance!

    Thursday, April 27, 2017 10:10 AM


  • You can do :

    Private Const BM_CLICK As Int32 = &HF5
    SendMessage(CheckBox1.Handle, BM_CLICK, 0, 0)

    • Marked as answer by Joao Silverio Sunday, April 30, 2017 8:28 PM
    Thursday, April 27, 2017 2:55 PM

All replies