How to set a picture at exactly the coordinate I want

shirz
01-07-2005, 02:36 AM
Hi,
I am doing a program that requires me to move the icon to a specific position on screeen. As I had done so for the mouse cursor,
using
X = (Screen.Width / Screen.TwipsPerPixelX) / 2
Y = (Screen.Height / Screen.TwipsPerPixelY) / 2
SetCursorPos X, Y

I hope to do the same thing for the icon, I tried using the
Picture Left = (Screen.Width / Screen.TwipsPerPixelX) / 2
Picture.Top = (Screen.Height / Screen.TwipsPerPixelY) / 2
but it dose not set it correctly


I have no idea how to go about doing it, can someone please advise me on the method, thanks alot

greg85374
01-07-2005, 12:01 PM
http://www.vb-helper.com/howto_let_user_move_controls.html

Gruff
01-07-2005, 01:11 PM
Screen Units are twip units The picture position properties are also twips.
No need to convert to pixels to move your picture. If you are trying to center your picture on the screen then:


Picture.left = (Screen.Width / 2) - (Picture.Width / 2)
Picture.Top = (Screen.Height / 2) - (Picture.Height / 2)


~T

shirz
01-08-2005, 10:15 AM
Hi there,
Tried
Picture1.Left = (Screen.Width / 2) - (Picture.Width / 2)
Picture1.Top = (Screen.Height / 2) - (Picture.Height / 2)
but the picture was not set to the exact position i wanted, in this case, it should be the exact centre...
can u advise me on how to set the coorodinate i want using pixel, as i only known how to do it in twips

for centre:
X = (Screen.Width / Screen.TwipsPerPixelX) / 2
Y = (Screen.Height / Screen.TwipsPerPixelY) / 2

for left:
X = 0
Y = (Screen.Height / Screen.TwipsPerPixelY) / 2

for up:
X = (Screen.Width / Screen.TwipsPerPixelX) / 2
Y = 0

for right:
X = (Screen.Width / Screen.TwipsPerPixelX)
Y = (Screen.Height / Screen.TwipsPerPixelY) / 2

VBJoe
01-08-2005, 01:32 PM
That will only work if your Picture Box fills the entire screen and you're drawing the Icon somewhere inside of it. If you need to move the Icon to an area in the Picture Box according to screen coordinates, you first need to find the screen coordinates of the Picture Box. To do that, you need to find the Coordinates of the Picture Box's Form.

'IN A MODULE:
Option Explicit

Public Type PicCoordinates
X As Long
Y As Long
End Type

Public Function GetCoordinates(frm As Form, PBox As PictureBox) As PicCoordinates
Dim c As PicCoordinates
c.X = frm.Left
c.Y = frm.Top
c.X = c.X + PBox.Left
c.Y = c.Y + PBox.Top
GetCoordinates = c
End Function

'IN A FORM: (Contains Picture1, Text1, Command1)
Option Explicit

Private Sub Command1_Click()
Dim c As PicCoordinates
c = GetCoordinates(Me, Picture1)
Text1.Text = CStr(c.X) & ", " & CStr(c.Y)
End Sub

The Text Box should contain the screen coordinates for the Picture Box, and you can make your determination of where to draw the Icon based on the results of the GetCoordinates function.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum