Shape.PointToClient 메서드
특정 화면 지점의 위치를 클라이언트 좌표로 계산합니다.
네임스페이스: Microsoft.VisualBasic.PowerPacks
어셈블리: Microsoft.VisualBasic.PowerPacks.Vs(Microsoft.VisualBasic.PowerPacks.Vs.dll)
구문
‘선언
Public Function PointToClient ( _
position As Point _
) As Point
public Point PointToClient(
Point position
)
public:
Point PointToClient(
Point position
)
member PointToClient :
position:Point -> Point
public function PointToClient(
position : Point
) : Point
매개 변수
- position
형식: System.Drawing.Point
반환 값
형식: System.Drawing.Point
변환된 Point인 p를 클라이언트 좌표로 나타내는 Point입니다.
설명
PointToClient 메서드를 사용 값으로 변환 하는 DragEventArgs 좌표는 폼의 화면 좌표를 클라이언트에 반환 합니다.
예제
다음 예제에서는 PointToClient 이동 하는 메서드는 RectangleShape 이미지 파일 수 놓을 때 끌어서.PointToClient 메서드가 이동의 RectangleShape 클라이언트 폼을 기준으로 합니다.예를 들어, 아래로 10 픽셀, 오른쪽 사각형의 왼쪽 위 모퉁이에 10 픽셀 위치 되 면 사각형 위치 10 픽셀 아래와 폼의 왼쪽 위 모서리의 오른쪽으로 10 픽셀 이동 됩니다.
이 예제에서는 사용자가 있어야는 RectangleShape 고 폼에 RectangleShape1 이라는 컨트롤의 AllowDrop 폼의 속성을 설정 true.
Private Sub Form1_DragDrop(
ByVal sender As Object,
ByVal e As System.Windows.Forms.DragEventArgs
) Handles Me.DragDrop
' Determine whether the drop is within the rectangle.
If RectangleShape1.HitTest(e.X, e.Y) = True Then
' Handle file data.
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
' Assign the file names to a string array, in
' case the user has selected multiple files.
Dim files As String() =
CType(e.Data.GetData(DataFormats.FileDrop), String())
Try
' Assign the first image to the BackGroundImage
' property.
RectangleShape1.BackgroundImage =
Image.FromFile(files(0))
' Set the rectangle location relative to the form.
RectangleShape1.Location =
RectangleShape1.PointToClient(New Point(e.X, e.Y))
Catch ex As Exception
MessageBox.Show(ex.Message)
Return
End Try
End If
End If
End Sub
Private Sub Form1_DragEnter(
ByVal sender As Object,
ByVal e As DragEventArgs
) Handles MyBase.DragEnter
' If the data is a file, display the copy cursor.
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
e.Effect = DragDropEffects.Copy
Else
e.Effect = DragDropEffects.None
End If
End Sub
private void Form1_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
{
// Determine whether the drop is within the rectangle.
if (rectangleShape1.HitTest(e.X, e.Y)==true)
// Handle file data.
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
// Assign the file names to a string array, in
// case the user has selected multiple files.
{
string[] files = (string[]) e.Data.GetData(DataFormats.FileDrop);
try
{
// Assign the first image to the BackGroundImage
// property.
rectangleShape1.BackgroundImage = Image.FromFile(files[0]);
// Set the rectangle location relative to the form.
rectangleShape1.Location =
rectangleShape1.PointToClient(new Point(e.X, e.Y));
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
}
}
}
private void Form1_DragEnter(object sender, DragEventArgs e)
{
// If the data is a file, display the copy cursor.
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
.NET Framework 보안
- 직접 실행 호출자의 경우 완전히 신뢰합니다. 이 멤버는 부분적으로 신뢰할 수 있는 코드에서 사용할 수 없습니다. 자세한 내용은 부분 신뢰 코드에서 라이브러리 사용을 참조하십시오.
참고 항목
참조
Microsoft.VisualBasic.PowerPacks 네임스페이스
기타 리소스
방법: LineShape 컨트롤로 선 그리기(Visual Studio)
방법: OvalShape 및 RectangleShape 컨트롤을 사용하여 도형 그리기(Visual Studio)