2011-09-03 7 views
4

Windows 7 및 Windows Vista에서 클릭 한 알림 아이콘 바로 위에 양식을 배치 할 수있는 방법이 있습니까?클릭 한 알림 아이콘 위의 위치 양식

+1

이 정보가 도움이됩니까? http://codetechnic.blogspot.com/2009/03/set-windows-forms-start-position-to.html – Zenwalker

+0

아니요는 작업 표시 줄의 오른쪽 하단 모서리에 양식을 배치합니다. 알림 아이콘 위에 위치시켜야합니다. – blejzz

+0

가능한 중복 : http://stackoverflow.com/questions/272778/how-to-find-the-location-of-the-icon-in-the-system-tray –

답변

1

귀하의 의견에 관하여 : "어떻게하면 작업 표시 줄의 위치를 ​​알 수 있습니까?"

Rectangle trayRectangle = WinAPI.GetTrayRectangle(); 
: 당신이 그렇게 같은 용지함의 Rectangle Structure를 검색 할 수 있습니다,이 클래스를 사용 [c#] NotifyIcon - Detect MouseOut

: 트레이에 대한 Rectangle Structure를 검색하는 방법을 노출하는 클래스를 포함하는 다음 문서 밖으로

확인

너비와 높이와 함께 트레이의 위쪽, 왼쪽, 오른쪽 및 아래쪽 좌표를 제공합니다.

I 클래스 아래에 포함했다 :이 도움이

using System; 
using System.Runtime.InteropServices; 
using System.Drawing; 
using System.ComponentModel; 

public class WinAPI 
{ 
    public struct RECT 
    { 
     public int left; 
     public int top; 
     public int right; 
     public int bottom; 

     public override string ToString() 
     { 
      return "(" + left + ", " + top + ") --> (" + right + ", " + bottom + ")"; 
     } 
    } 

    [DllImport("user32.dll", CharSet = CharSet.Auto)] 
    public static extern IntPtr FindWindow(string strClassName, string strWindowName); 

    [DllImport("user32.dll", SetLastError = true)] 
    public static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string className, IntPtr windowTitle); 

    [DllImport("user32.dll")] 
    [return: MarshalAs(UnmanagedType.Bool)] 
    static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect); 


    public static IntPtr GetTrayHandle() 
    { 
     IntPtr taskBarHandle = WinAPI.FindWindow("Shell_TrayWnd", null); 
     if (!taskBarHandle.Equals(IntPtr.Zero)) 
     { 
      return WinAPI.FindWindowEx(taskBarHandle, IntPtr.Zero, "TrayNotifyWnd", IntPtr.Zero); 
     } 
     return IntPtr.Zero; 
    } 

    public static Rectangle GetTrayRectangle() 
    { 
     WinAPI.RECT rect; 
     WinAPI.GetWindowRect(WinAPI.GetTrayHandle(), out rect); 
     return new Rectangle(new Point(rect.left, rect.top), new Size((rect.right - rect.left) + 1, (rect.bottom - rect.top) + 1)); 
    } 
} 

희망.

+1

그로테스크 해킹입니다. 왜 마우스 오른쪽 버튼 클릭 이벤트에서 커서 위치를 읽는 대신에 그렇게할까요? 왜 제대로 할 수있을 때 해킹에 의지할까요? –

+0

@David Heffernan 작업 표시 줄의 위치를 ​​파악하는 올바른 방법은 무엇입니까? 나는 그것이 왼쪽/오른쪽/위/아래에 있는지 알아야합니다. – blejzz

+1

@blejzz 한스는 이미 아이콘을 찾을 수 없다고 설명했습니다. 할 수있는 일은 아이콘 컨텍스트 메뉴를 호출 한 이벤트의 커서 위치를 얻는 것입니다. 그걸로 당신은 어떤 구석 밖으로 운동 할 수 있습니다. –

5

쉬운 방법이 있습니다.

OnClick 이벤트가 발생하면 마우스의 X, Y 위치를 가져올 수 있습니다. 또한 이러한 개체 (예 : Screen.PrimaryScreen.Bounds, Screen.PrimaryScreen.WorkingArea)를 사용하여 작업 표시 줄 위치를 확인할 수도 있습니다.

private void OnTrayClick(object sender, EventArgs e) 
    { 
     _frmMain.Left = Cursor.Position.X; 
     _frmMain.Top = Screen.PrimaryScreen.WorkingArea.Bottom -_frmMain.Height; 
     _frmMain.Show();   
    }