■ SystemParametersInfo WIN32 API 함수를 사용해 Form 객체를 트레이 상단에 위치시키는 방법을 보여준다.
▶ 예제 코드 (C#)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
using System.Drawing; using System.Runtime.InteropServices; using System.Windows.Forms; /// <summary> /// 사각형 /// </summary> [StructLayout(LayoutKind.Sequential)] public struct RECT { /// <summary> /// 왼쪽 /// </summary> public int Left; /// <summary> /// 위쪽 /// </summary> public int Top; /// <summary> /// 오른쪽 /// </summary> public int Right; /// <summary> /// 아래쪽 /// </summary> public int Bottom; } /// <summary> /// 시스템 파라미터 정보 구하기 /// </summary> /// <param name="action">작업</param> /// <param name="parameter">파라미터</param> /// <param name="rect">사각형</param> /// <param name="winINI">WIN.INI 업데이트 플래그</param> /// <returns>처리 결과</returns> [DllImport("user32", CharSet=CharSet.Auto, SetLastError=true)] public static extern int SystemParametersInfo(int action, int parameter, out RECT rect, int winINI); /// <summary> /// SPI_GETWORKAREA /// </summary> private const int SPI_GETWORKAREA = 0x0030; #region 위치 설정하기 - SetLocation(form) /// <summary> /// 위치 설정하기 /// </summary> /// <param name="form">Form 객체</param> public void SetLocation(Form form) { RECT rect = new RECT(); SystemParametersInfo(SPI_GETWORKAREA, 0, out rect, 0); Size size = form.Size; Point location = new Point(rect.Right - form.Width, rect.Bottom - size.Height); form.Location = location; } #endregion |