2

画面の右端に配置し、高さを伸ばして作業領域の高さ全体を埋めるフォームがあります。

それについてはそれほど奇妙なことはないので、Screen.WorkingArea.Heightローカルで実行している限り問題なく機能する、を使用してソリューションを作成しました。問題は、本番環境ではフォームがCitrix環境で実行され、タスクバーの高さを完全に無視しているように見えることです。Citrixでは、-Screen.WorkingArea.Heightとまったく同じ値が返されるScreen.Bounds.Heightため、タスクバーの下に表示されます。

私の考えは、Screen.Bounds.Height(正しく返されるように見えるので)自分でタスクバーの高さを差し引くことです。唯一の問題は、これを行う方法について私が見つけることができる唯一の例ですScreen.Bounds.Height - Screen.WorkingArea.Height

では、どうすればタスクバーの高さに直接アクセスできますか?(もちろん、この問題を回避する方法について他のアドバイスを喜んで聞きます!)

4

1 に答える 1

1

タスクバーのプロパティにアクセスするには、いくつかのネイティブ メソッドを使用する必要があります。

使用法:

TaskbarInfo.Height

クラス:

Public NotInheritable Class TaskbarInfo

    <DllImport("user32.dll", SetLastError:=True)> _
    Private Shared Function FindWindow(ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
    End Function

    <DllImport("shell32.dll", SetLastError:=True)> _
    Public Shared Function SHAppBarMessage(ByVal dwMessage As ABM, <[In]()> ByRef pData As APPBARDATA) As IntPtr
    End Function

    Enum ABM As UInteger
        [New] = &H0
        Remove = &H1
        QueryPos = &H2
        SetPos = &H3
        GetState = &H4
        GetTaskbarPos = &H5
        Activate = &H6
        GetAutoHideBar = &H7
        SetAutoHideBar = &H8
        WindowPosChanged = &H9
        SetState = &HA
    End Enum

    Enum ABE As UInteger
        Left = 0
        Top = 1
        Right = 2
        Bottom = 3
    End Enum

    <StructLayout(LayoutKind.Sequential)> _
    Structure APPBARDATA
        Public cbSize As UInteger
        Public hWnd As IntPtr
        Public uCallbackMessage As UInteger
        Public uEdge As ABE
        Public rc As RECT
        Public lParam As Integer
    End Structure

    <StructLayout(LayoutKind.Sequential)> _
    Structure RECT
        Public left As Integer
        Public top As Integer
        Public right As Integer
        Public bottom As Integer
    End Structure

    Public Shared Function Height() As Integer
        Dim taskbarHandle As IntPtr = FindWindow("Shell_TrayWnd", Nothing)

        Dim data As New APPBARDATA()
        data.cbSize = CUInt(Marshal.SizeOf(GetType(APPBARDATA)))
        data.hWnd = taskbarHandle
        Dim result As IntPtr = SHAppBarMessage(ABM.GetTaskbarPos, data)

        If result = IntPtr.Zero Then
            Throw New InvalidOperationException()
        End If

        Return Rectangle.FromLTRB(data.rc.left, data.rc.top, data.rc.right, data.rc.bottom).Height
    End Function

End Class

ソース: http://winsharp93.wordpress.com/2009/06/29/find-out-size-and-position-of-the-taskbar/

于 2011-09-10T04:52:30.027 に答える