CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2009
    (Presently) Bahrah S.A.

    [RESOLVED] UserControl Property Limitations

    My Dilemma:

    I need a Control that is Arrayable for muti-instancing, contains a picture with a stretch property, and can be dynamically positioned at runtime with the mouse. In order to satisfy these conditions it needs the following minimum properties, events and methods:

    Picture Property
    Stretch Property
    Index Property
    hWnd Property
    Left and Top Properties
    Height and Width Properties
    Move Method (or at least movable via the VB Move Command)

    All of these can be satisfied by the PictureBox except for Stretch
    All can be satisfied by the Image Control except for the hWnd Property.

    My objective was to create a UserControl that contained only an Image Control and expose the hWnd of the UserControl so that a ReleaseCapture and SendMessage could dynamically move the control on the form at runtime. However the Move is invalid with the UserControl, and the UserControl has no Left or Top properties.


    The UserControl has CurrentX and CurrentY which can be implemented with the ReleaseCapture and SendMessage without the Move Command as;

    Private Declare Function ReleaseCapture Lib "user32" () As Long
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Const HTCAPTION = 2
    Private Const WM_NCLBUTTONDOWN = &HA1

    Dim bMoveSwitch as Boolean 'For MoveSwitch Property

    Private Sub imgSelectorSwitch(Button As Integer, Shift As Integer, x As Single, y As Single) 'This is an Image Control
    If Button = vbLeftButton And bMoveSwitch Then 'bMoveSwitch is a Bool turned on and off to permit functioning of the imgSelectorSwitch_Click event, and to lock controls on the form.
    SendMessage UserControl.hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&

    'UserControl.Move UserControl.Left, UserControl.Top (Won't work with UserControl)

    UserControl.CurrentX = X 'This works with
    UserControl.CurrentY = Y 'UserControl

    Exit Sub
    ElseIf Button = vbRightButton Then

    ElseIf Button = 4 Then
    End If

    End Sub

    Private Sub imgSelectorSwitch_Click()
    If Not bMoveSwitch then
    RaiseEvent Click
    end if
    End Sub

    Public Property Get MoveSwitch() as Boolean
    MoveSwitch = bMoveSwitch
    End Property

    Public Property Let MoveSwitch(bUser_MoveSwitch as Boolean)
    bMoveSwitch = bUser_MoveSwitch
    End Property

    I hope someone else finds this useful.
    Last edited by arkansascontrols; July 10th, 2009 at 11:13 PM. Reason: By Request of dglienna

  2. #2
    Join Date
    Jan 2006
    Fox Lake, IL

    Re: UserControl Property Limitations

    Put your question back, along with the answer, to help the next person

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.