problem with a control

Posted on 2000-03-14
Last Modified: 2010-05-19
i have an activex control like the
caption bar which i want to replace
by the orignal one
 prablem is it wont change the position of the form when mouse is clicked and dragged

if you want the coding of the active x tool email me at
Question by:sjehanzeb
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 2617029
I am guessing you are talking about a status bar at the bottom of the dialog you are working on.

These can't be moved from their location at the bottom of the window.

If this isn't what you're talking about, post some code and the names of the controls you are using.

Expert Comment

ID: 2617230
I guess you mean you are creating your own control which you want to use to replace the window's caption bar. You want to allow the user to move the form by clicking and dragging on this control - right ?

This article on vbnet should be exactly waht you need :
LVL 14

Accepted Solution

mcrider earned 95 total points
ID: 2617391
I've already answered this in a similiar question: 

Here is the answer from that question. It talks about using a picturebox to do what you want... Instead of doing the picturebox, use the MouseMove event in your control:

From: raya70  Title: "Drag a form with mousepointer?"    
Points: 5  Date: Monday, December 13 1999 - 07:46AM EST    
I've turned the ordinary titlebar off in my app (borderstyle = None) and I've made my own more graphical layout. Now I want to make it possible for the user to click my own titlebar and drag the whole form just like they could before. I'm having problem with the mousemove event. I know there is very little code to solve this but my brain doesn't function right now! The control to use for the bar could be a picture, Image or some control that can be invisible (background sees through) but still work.


Accepted Answer  
From: mcrider
 Date: Monday, December 13 1999 - 09:15AM EST  

Put a picturebox on the form called "Picture1" then add the following code to the DECLARATIONS SECTION of the form.

You can put the picture box a the top of the form and size it as if it were a title bar...  Color it if you want...

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 Declare Sub ReleaseCapture Lib "User32" ()
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
   Dim lngReturnValue As Long
   If Button = 1 Then
      Call ReleaseCapture
      lngReturnValue = SendMessage(Form1.hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&)
   End If
End Sub

Run the program... When you put your mouse over the picturebox, click and hold the left mouse button and drag the form....


Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

LVL 14

Expert Comment

ID: 2617500
Another API Solution.. (not as pretty as mcrider's tho.. <sigh>).. Followed by a TIP.. <smile>.

<----- Begin DECLARATIONS SECTION ----->

Private Type PointApi
    X As Long
    Y As Long
End Type

Private Declare Function ClientToScreen Lib "user32" _
    (ByVal hwnd As Long, lpPoint As PointApi) _
    As Long

Private Declare Function ReleaseCapture Lib "user32" _
    () _
    As Long

Private Declare Function SetCapture Lib "user32" _
    (ByVal hwnd As Long) _
    As Long

Private msngLastX As Single
Private msngLastY As Single
Private msngThisX As Single
Private msngThisY As Single
Private mudtPoint As PointApi


<----- Begin CODE SECTION ----->

Private Sub UserControl1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = vbLeftButton _
        Dim lngReturn As Long
        lngReturn = SetCapture(UserControl1.hwnd)
        mudtPoint.X = X / Screen.TwipsPerPixelX
        mudtPoint.Y = Y / Screen.TwipsPerPixelY
        lngReturn = ClientToScreen(UserControl1.hwnd, mudtPoint)
        msngLastX = mudtPoint.X * Screen.TwipsPerPixelX
        msngLastY = mudtPoint.Y * Screen.TwipsPerPixelY
    End If
End Sub

Private Sub UserControl1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = vbLeftButton _
        Dim lngReturn As Long
        mudtPoint.X = X / Screen.TwipsPerPixelX
        mudtPoint.Y = Y / Screen.TwipsPerPixelY
        lngReturn = ClientToScreen(UserControl1.hwnd, mudtPoint)
        msngThisX = mudtPoint.X * Screen.TwipsPerPixelX
        msngThisY = mudtPoint.Y * Screen.TwipsPerPixelY
        Form1.Move _
           Form1.Left + (msngThisX - msngLastX), _
           Form1.Top + (msngThisY - msngLastY), _
           Form1.Width, _
        msngLastX = msngThisX
        msngLastY = msngThisY
    End If
End Sub

Private Sub UserControl1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = vbLeftButton _
        Dim lngReturn As Long
        lngReturn = ReleaseCapture
    End If
End Sub

<----- End CODE SECTION ----->

TIP: To get the Height of a standard Caption use the GetSystemMetricsInfo API..

Private Declare Function GetSystemMetrics Lib "user32" _
(ByVal nIndex As Long) _
As Long
Private Const SM_CYCAPTION = 4          ' Height of caption or title

lngCaptionHeightExpressedInPixels = _

When you are not pretty.. you hasta work harder.. <smile> and a <wink>.. LOL.

LVL 14

Expert Comment

ID: 2617739
wsh2,  That's ok... You've caught me more than once in my insomniac stupor ;-)
LVL 14

Expert Comment

ID: 2629860
Can I ask why you graded this a "C"???

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question