2017-11-05 14 views
0

저는 Pen.Alignment = PenAlignment.Outset을 사용하여 PictureBox (녹색 배경)에 직사각형을 그립니다.PenAlignment.Outset은 효과가 없습니다.

Private Sub PictureBox1_Paint(sender As Object, e As PaintEventArgs) Handles PictureBox1.Paint 

    Dim iTop As Integer = 1 
    Dim iLeft As Integer = 1 
    Dim iRight As Integer = 3 
    Dim iBottom As Integer = 3 

    Dim r As Rectangle = Rectangle.FromLTRB(iLeft, iTop, iRight, iBottom) 

    Using nPen As Pen = New Pen(Color.Black) 
     nPen.Alignment = PenAlignment.Outset 
     e.Graphics.PageUnit = GraphicsUnit.Pixel 
     nPen.Width = 1 
     e.Graphics.DrawRectangle(nPen, r) 
    End Using 

End Sub 

그러나, PenAlignment이 적용되지 않습니다 :

는 코드입니다. 사각형이 어디

enter image description here

대신 "처음"로 사각형을 그리는, 그것은 exactely립니다 이 출력입니다. 검정색 선이 직사각형 주위로 그려지기를 기대합니다.

따라서 첫 번째 검은 점은 1-1이 아니라 0-0에 있어야합니다.

무엇이 잘못 될 수 있습니까?

+0

나는 코드에서 어떤 실수를 볼 수 없습니다. 음, 이상 하네. :/ – AntonioC

+0

펜의 너비가 1보다 큰 경우 펜을 사용한다고 생각합니다. 더 큰 사각형을 그리려면 직접 크기를 조정해야합니다. – LarsTech

+0

MSDN에서 언급 한 내용이 보이지 않습니다. 확실합니까? – tmighty

답변

0

나는 동일한 문제가있어 답변이 없으므로 해결해야합니다.

는 여기에 내가했던 일이야 :

Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint 

    'Main Shape Values 
    Dim x = 100 
    Dim y = 100 
    Dim wdth = 300 
    Dim hght = 200 
    Dim shP = 2 

    'Main Shape 
    Dim ShapePen As New Pen(Color.Black, shP) 
    Dim Shape As New Rectangle(x, y, wdth, hght) 
    e.Graphics.DrawRectangle(ShapePen, Shape) 

    'Values For the Alignment 
    Dim P_Thck = 20 
    Dim R_ThickL = (P_Thck/2) + (shP/2) 
    Dim R_ThickS = R_ThickL * 2 

    Dim AlignmentPen As New Pen(Color.Red, P_Thck) 
    'Dim Align_Outset As New Rectangle(x - R_ThickL, y - R_ThickL, wdth + R_ThickS, hght + R_ThickS) 
    Dim Align_Inset As New Rectangle(x + R_ThickL, y + R_ThickL, wdth - R_ThickS, hght - R_ThickS) 

    'e.Graphics.DrawRectangle(AlignmentPen, Align_Outset) 
    e.Graphics.DrawRectangle(AlignmentPen, Align_Inset) 

End Sub 

내가이 개 모양을 사용합니다. 하나는 제 작업 모양이고 다른 하나는 제 정렬 그래픽에 맞게 조정 한 것입니다.

Inset

Outset