[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


problem with a control

Posted on 2000-03-14
Medium Priority
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 saqibshakil@yifan.net
Question by:sjehanzeb

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 190 total points
ID: 2617391
I've already answered this in a similiar question: http://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=10246157 

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....


Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

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…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month19 days, 22 hours left to enroll

873 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