Visualizzazione dei risultati da 1 a 10 su 10
  1. #1
    Utente di HTML.it
    Registrato dal
    Jul 2001
    Messaggi
    452

    [VB6] coordinate X - Y del form

    Sto sviluppando un programma, ed ora mi è sorta la neccesità di sapere le cordinate X e Y di posizionamento di un determinato form, questo xchè inizialmente quando avvierò il programma il form sarà sempre al centro del monitor ma poi uno lo potrebbe anche spostare e allora la mia domanda è la seguente: dove l'ha messo ?

    GRAZIE INFINITE

  2. #2

    Usa queste proprietà...

    Puoi usare le proprietà Left e Top del form.

    Ad Es:

    Label1.caption = Me.Top 'Me indica il form attuale
    Label2.caption = Me.Left

    Spero d'essere stato d'aiuto, fammi sapere...
    Ciao!!
    lupusinfabula

    Programmatore VB, ASP, Delphi.

  3. #3
    Utente di HTML.it L'avatar di Nico
    Registrato dal
    Apr 2002
    Messaggi
    458
    Si le proprietà left e top funzionano.
    Però penso che dia le coordinate in twips...o sbaglio?

  4. #4

    Leggo....

    Leggo su MSDN:
    For a form, the Left and Top properties are always expressed in twips;
    Pare che sia prorpio come dici tu... ma solo per i forms, per gli altri componenti, dipende dalla proprietà ScaleMode del container.

    Ciao!!:quipy:
    lupusinfabula

    Programmatore VB, ASP, Delphi.

  5. #5
    Utente di HTML.it
    Registrato dal
    Jul 2001
    Messaggi
    452

    Per BOLDAN

    Grazie con info che mi hai dato ho risolto il problema tranquillamente anche se il parametro che passa è in tw.

    Non voglio approffitarne ma con VB come posso fare per sapere che risoluzione video sta usando un determinato utente ?

    GRAZIE

  6. #6

    Per la risoluzione dello schermo

    Puoi far così:
    Dividi la larghezza dello schermo espressa in twips per il numerp di twips per pixel.

    Private Sub Command1_Click()
    Label1.Caption = Screen.Height / Screen.TwipsPerPixelY
    Label2.Caption = Screen.Width / Screen.TwipsPerPixelY
    End Sub

    Ciao!!
    lupusinfabula

    Programmatore VB, ASP, Delphi.

  7. #7
    Utente di HTML.it L'avatar di Nico
    Registrato dal
    Apr 2002
    Messaggi
    458
    Se vuoi ti posto il codice di un'API che rileva la risoluzione corrente, poi la imposta come la vuoi tu e alla chiusura del programma la risporta come prima...

  8. #8
    Utente di HTML.it
    Registrato dal
    Jul 2001
    Messaggi
    452

    Per Nico

    Si GRAZIE saresti veramente gentile.

    saluti

  9. #9
    Utente di HTML.it L'avatar di Nico
    Registrato dal
    Apr 2002
    Messaggi
    458
    Allora il codice è lunghetto ma carino :quote:
    Premessa: Me l'aveva dato vonkranz(che ringrazio ancora) il quale l'aveva reperito a sua volta da "www.allapi.net". Io l'ho modificato in modo che imposti la risoluzione a 1024x768.
    Buona fortuna, e fammi sapere se riesci a farlo funzionare!

    codice:
    Const CCDEVICENAME = 32
    Const CCFORMNAME = 32
    Const DM_PELSWIDTH = &H80000
    Const DM_PELSHEIGHT = &H100000
    Const CDS_TEST = &H4
    Private Type DISPLAY_DEVICE
        cb As Long
        DeviceName As String * 32
        DeviceString As String * 128
        StateFlags As Long
        DeviceID As String * 128
        DeviceKey  As String * 128
    End Type
    Private Type DEVMODE
        dmDeviceName As String * CCDEVICENAME
        dmSpecVersion As Integer
        dmDriverVersion As Integer
        dmSize As Integer
        dmDriverExtra As Integer
        dmFields As Long
        dmOrientation As Integer
        dmPaperSize As Integer
        dmPaperLength As Integer
        dmPaperWidth As Integer
        dmScale As Integer
        dmCopies As Integer
        dmDefaultSource As Integer
        dmPrintQuality As Integer
        dmColor As Integer
        dmDuplex As Integer
        dmYResolution As Integer
        dmTTOption As Integer
        dmCollate As Integer
        dmFormName As String * CCFORMNAME
        dmUnusedPadding As Integer
        dmBitsPerPel As Integer
        dmPelsWidth As Long
        dmPelsHeight As Long
        dmDisplayFlags As Long
        dmDisplayFrequency As Long
        dmICMMethod As Long 'NT 4.0
        dmICMIntent As Long 'NT 4.0
        dmMediaType As Long 'NT 4.0
        dmDitherType As Long 'NT 4.0
        dmReserved1 As Long 'NT 4.0
        dmReserved2 As Long 'NT 4.0
        dmPanningWidth As Long 'Win2000
        dmPanningHeight As Long 'Win2000
    End Type
    Private Declare Function ChangeDisplaySettingsEx Lib "user32" Alias "ChangeDisplaySettingsExA" (lpszDeviceName As Any, lpDevMode As Any, ByVal hWnd As Long, ByVal dwFlags As Long, lParam As Any) As Long
    Private Declare Function EnumDisplayDevices Lib "user32" Alias "EnumDisplayDevicesA" (Unused As Any, ByVal iDevNum As Long, lpDisplayDevice As DISPLAY_DEVICE, ByVal dwFlags As Long) As Boolean
    Dim OldX As Long, OldY As Long, T As Long
    Dim DD As DISPLAY_DEVICE, DevM As DEVMODE
    
    
    Private Sub Form_Load()
        'KPD-Team 2000
        'URL: http://www.allapi.net/
        'E-Mail: KPDTeam@Allapi.net
        DD.cb = Len(DD)
        OldX = Screen.Width / Screen.TwipsPerPixelX
        OldY = Screen.Height / Screen.TwipsPerPixelY
        'First retieve some display info
        If EnumDisplayDevices(ByVal 0&, 0, DD, ByVal 0&) Then
            'and show it
            Me.AutoRedraw = True
            Me.Print "Device String:" + Left$(DD.DeviceString, InStr(1, DD.DeviceString, Chr$(0)) - 1)
            Me.Print "Device Name:" + Left$(DD.DeviceName, InStr(1, DD.DeviceName, Chr$(0)) - 1)
            Me.Print "Device Key:" + Left$(DD.DeviceKey, InStr(1, DD.DeviceKey, Chr$(0)) - 1)
            Me.Print "Device ID:" + Left$(DD.DeviceID, InStr(1, DD.DeviceID, Chr$(0)) - 1)
        Else
            Me.Print "Error while retrieving Display Information"
        End If
        DevM.dmSize = Len(DevM)
        'we want to change the horizontal and the vertical resolution
        DevM.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT
        DevM.dmPelsWidth = 1024
        DevM.dmPelsHeight = 768
        'change the display settings
        Call ChangeDisplaySettingsEx(ByVal 0&, DevM, ByVal 0&, CDS_TEST, ByVal 0&)
    '    T = Timer
    '    Do: DoEvents: Loop Until Timer > T + 5
    '    DevM.dmPelsWidth = OldX
    '    DevM.dmPelsHeight = OldY
    '    'change the display settings back to the old settings
    '    Call ChangeDisplaySettingsEx(ByVal 0&, DevM, ByVal 0&, CDS_TEST, ByVal 0&)
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
        DevM.dmPelsWidth = OldX
        DevM.dmPelsHeight = OldY
        'change the display settings back to the old settings
        Call ChangeDisplaySettingsEx(ByVal 0&, DevM, ByVal 0&, CDS_TEST, ByVal 0&)
    End Sub

  10. #10
    Utente di HTML.it L'avatar di Nico
    Registrato dal
    Apr 2002
    Messaggi
    458
    [dimenticavo]
    Il codice ti stampa sul form alcune informazioni riguardo il video e la scheda viedo.
    [/dimenticavo]

    [dimenticavo 2]
    declino ogni responsabilità in caso di malfunzionamento :gren: (cmq a me funziona benissimo)
    [/dimenticavo 2]

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.