Solved

problem with a control

Posted on 2000-03-14
6
153 Views
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
0
Comment
Question by:sjehanzeb
6 Comments
 
LVL 4

Expert Comment

by:CoolAss
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.
0
 
LVL 3

Expert Comment

by:paulstamp
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 :

http://www.mvps.org/vbnet/code/neet/drawfocusrect.htm
0
 
LVL 14

Accepted Solution

by:
mcrider earned 95 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" ()
Const WM_NCLBUTTONDOWN = &HA1
Const HTCAPTION = 2
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....



Cheers!®©


0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 14

Expert Comment

by:wsh2
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

<----- End DECLARATIONS SECTION ----->


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

Private Sub UserControl1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = vbLeftButton _
    Then
        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 _
    Then
        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, _
           Form1.Height
        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 _
    Then
        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 = _
    GetSystemMetrics(SM_CYCAPTION)

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


0
 
LVL 14

Expert Comment

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

Expert Comment

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…

863 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now