Jump to content
Software FX Community

Y Value in any Event


User (Legacy)

Recommended Posts

Hi,

I am trying to position a vb control (picturebox) at the same location as

the mouse.

In your mousemoving event, I assign the picture box's x to the event's x

value multiplied by Screen.TwipsPerPixelX which works perfectly; however,

when I use the same technique on your Y value (picbox.top = y *

Screen.TwipsPerPixelY) the picture box seems to hover about 750 pixels above

where the mouse actually is! I get the same type of result when using the

retrurn Y value from your ValueToPixel method.

If you could please define for me where I can pull that offset value from

(as it changes when a financial study is applied) or tell me what I am doing

wrong, it woulkd be greatly appreciated.

Thanking you in advance,

Chase Gale

Link to comment
Share on other sites

x and y are relative to the chart area. If you have a toolbar, menus, a

legend or the data editor located on top part of the chart you need to

convert these coordinates to screen coordinates and then Form coordinates

for your control.

To get a hold of the Drawing area you will need to use the Windows API as

follows:

chart1.Capture = True

hWnd = GetCapture()

chart1.Capture = False

hWnd will then contain the Window handle for the Drawing area, you can use

ClienToScreen and ScreenToClient functions (Windows API) to transform these

coordinates to the appropriate system.

Note: GetCapture is located in USER32.EXE

--

FP

Software FX, Inc.

Link to comment
Share on other sites

Hi,

There is no "Capture" method of ChartFX, I am using the control not the DLL.

Is thier another approach or am I missing something?

Thanking you in advance,

Chase Gale

"SoftwareFX Support" <support@softwarefx.com> wrote in message

news:DaiKTuO3CHA.3004@webserver1.softwarefx.com...

> x and y are relative to the chart area. If you have a toolbar, menus, a

> legend or the data editor located on top part of the chart you need to

> convert these coordinates to screen coordinates and then Form coordinates

> for your control.

>

> To get a hold of the Drawing area you will need to use the Windows API as

> follows:

>

> chart1.Capture = True

> hWnd = GetCapture()

> chart1.Capture = False

>

> hWnd will then contain the Window handle for the Drawing area, you can use

> ClienToScreen and ScreenToClient functions (Windows API) to transform

these

> coordinates to the appropriate system.

>

> Note: GetCapture is located in USER32.EXE

>

> --

> FP

> Software FX, Inc.

>

>

Link to comment
Share on other sites

Ok, I have followed your instructions and I am still coming up with offset

values.

Here is an example:

Open a new VB project, add a chartfx1 control, add a picturebox. Paste the

following code in yuor form

Option Explicit

Private Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long,

lpPoint As POINTAPI) As Long

Private Declare Function GetCapture Lib "user32" () As Long

Dim ghwnd As Long

Private Type POINTAPI

x As Long

y As Long

End Type

Dim papi As POINTAPI

Private Sub ChartFX1_MouseMoving(ByVal x As Integer, ByVal y As Integer,

nRes As Integer)

'

dim lreturn as long

'

papi.x = x

papi.y = y

lreturn = ClientToScreen(ghwnd, papi)

Picture1.Top = (papi.y * Screen.TwipsPerPixelY)

Picture1.Left = (papi.x * Screen.TwipsPerPixelX)

'

End Sub

Private Sub Form_Load()

'

ChartFX1.TypeMask = ChartFX1.TypeMask Or CT_TRACKMOUSE

'

ChartFX1.MouseCapture = True

ghwnd = GetCapture()

ChartFX1.MouseCapture = False

'

End Sub

You'll see that the numbers are still offset.

Any help you could provide would be greatly appreciated,

Chase Gale

"SoftwareFX Support" <support@softwarefx.com> wrote in message

news:JnrMwQQ3CHA.1844@webserver1.softwarefx.com...

> That I told you, this is a Windows API function located in USER32.EXE

>

> --

> FP

> Software FX, Inc.

>

>

Link to comment
Share on other sites

Yes but you forgot to convert from Screen coordinates to Form coordinates

(The picture box is a child of the form). To do this add:

Private Declare Function ScreenToClient Lib "user32" (ByVal hwnd As Long,

lpPoint As POINTAPI) As Long

And call it as follows right after ClientToScreen

lreturn = ScreenToClient(Form1.hwnd, papi)

--

FP

Software FX, Inc.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...