.NET/Windows API for .NET
DrawFocusRect - 선택모양의 점선사각형 그리기
클리엘
2019. 8. 5. 17:22
728x90
DrawFocusRect함수는 마치 해당 위치로 Focus가 이동한 듯한 점선모양의 사각형을 그립니다.
Declare Function DrawFocusRect Lib "user32" Alias "DrawFocusRect" (ByVal hdc As Integer, ByRef lpRect As RECT) As Integer
- VB.NET 선언
[DllImport("user32")]
public static extern int DrawFocusRect(int hdc, ref RECT lpRect);
- C# 선언
DrawFocusRect함수의 첫번째 인수는 사각형을 표시할 Device Context를 기술합니다.
[Windows API for .NET] - GetDC - Window및 Control의 Device Context 구하기
[Windows API for .NET] - GetWindowDC - 현재 Windows화면의 Device Context 구하기
DrawFocusRect함수의 두번째 인수는 사각형을 그릴 위치및 크기에 대한 좌표가 지정된 구조체를 전달합니다. 해당 구조체는 예를 들어 왼쪽 10부터 가로 50, 상단 10부터 세로 50만큼의 사각형을 생성하고자 할때 다음과 같이 선언될 수 있습니다.
Public Structure RECT
Public left As Integer
Public top As Integer
Public right As Integer
Public bottom As Integer
End Structure
Dim norRECT As RECT
norRECT.left = 10
norRECT.top = 10
norRECT.right = 50
norRECT.bottom = 50
- VB.NET
public struct RECT
{
public int left;
public int top;
public int right;
public int bottom;
}
RECT norRECT = default(RECT);
norRECT.left = 10;
norRECT.top = 10;
norRECT.right = 50;
norRECT.bottom = 50;
- C#
위 인수내용을 토대로 Form위에 사각형을 그리려면 DrawFocusRect함수를 다음과 같이 호출할 수 있습니다.
DrawFocusRect(GetDC(Me.Handle), norRECT)
- VB.NET 호출
DrawFocusRect(GetDC((int)this.Handle), ref norRECT);
- C# 호출
이 함수는 만일 실행에 실패하면 0을 반환합니다.
728x90