Solved

problem with a control

Posted on 2000-03-14
6
157 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
Industry Leaders: 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

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
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…

749 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