2016-12-07 7 views
-1

짧은 문제가 있습니다. 내가 등 textbox여러 컨트롤 위에 페인트 수행

원하는 controls의 상단에 이미지의이 종류를 칠 수있는 방법 이 내 코드입니다 :

Private Sub GroupBox6_Paint(sender As Object, e As PaintEventArgs) Handles GroupBox6.Paint 
    If txtStatus.Text = "Cancelled" Then 
     Try 
      Dim newImage As Image = Image.FromFile(FOLDER_PATH & "\completed.png") 
      Dim x As Single = ((GroupBox6.Width/2) - (463/4)) 
      Dim y As Single = 10 
      Dim width As Single = 463/2 
      Dim height As Single = 242/2 
      e.Graphics.DrawImage(newImage, x, y, width, height) 
     Catch ex As Exception 
     End Try 
    End If 
End Sub 

그리고 이것은 내 출력입니다 : 그래서

enter image description here

내 목표는 내 내 안에 textbox, label 위에 이미지 Completed을 페인트하는 것입니다.

+0

당신은 사용자가 프로세스를 완료 할 때 오버레이로 이미지를 표시하고 기본 컨트롤을 숨기시겠습니까? 그룹 박스에서 이미지를 그리는 대신 상태가 "취소됨"일 때 Groupbox 대신 표시되는 PictureBox 컨트롤을 사용하는 것이 더 쉽다고 생각합니다. – Markus

+0

@ Markus 그림 상자를 사용하면 투명하지 않기 때문에 이미지를 컨트롤에 붙이면됩니다. 하지만 제 경우에는 txtbox와 레이블이 이미지를 덮고 있습니다. 나는 페인트 칠을하고 그룹 박스 안의 gropbox와 다른 컨트롤의 앞쪽으로 보내고 싶습니다. – Muj

+1

제가 생각할 수있는 두 가지 해결책이 있습니다. 1. 레이어 된 윈도우를 만들고 컨트롤 위에 표시합니다. 2. 이미지가 나타날 부분의 스크린 샷을 찍은 다음 picbox에 그려넣고 png 이미지 –

답변

0

이 작업을 수행하려면 bitmapspicturebox이 필요합니다.

다음 PictureBox를 보여

Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load 
    pngImage = Image.FromFile(FOLDER_PATH & "\completed.png") //load it once 
    picBoxImage = CType(pngImage.Clone, Image) 

    PictureBox1.Size = New Size(CInt(463/2), CInt(242/2)) 
    PictureBox1.Parent = GroupBox6 
    PictureBox1.Image = picBoxImage 
    PictureBox1.Visible = False //you dont want it at the beggining 
End Sub 

서브 :

형태 Load 이벤트
Private pngImage, picBoxImage As Image 

두 이미지를 초기화 : 첫 번째는 png 이미지와 상기 제 하나 picturebox 이미지

Private Sub ShowCompletedMessage() 
    Dim screenLocation As Point 
    Dim gr As Graphics 
    //you can pass these values as parameters in the sub if you want to make the code more generic 
    Dim x As Integer = CInt(((GroupBox6.Width/2) - (463/4))) 
    Dim y As Integer = 10 
    Dim width As Integer = CInt(463/2) 
    Dim height As Integer = CInt(242/2) 

    //Ensure that picturebox is not visible. If it is you don't need to take a screenshot 
    If PictureBox1.Visible = True Then 
     Return 
    End If 

    gr = Graphics.FromImage(picBoxImage) 

    //you need to transform the coordinates to screen ones 
    screenLocation = GroupBox6.PointToScreen(New Point(x, y)) 

    //draw the portion of the screen to your bitmap 
    gr.CopyFromScreen(screenLocation.X, screenLocation.Y, 0, 0, New Size(width, height), CopyPixelOperation.SourceCopy) 

    //draw the png image on top 
    gr.DrawImage(pngImage, 0, 0, width, height) 

    PictureBox1.Location = New Point(x, y) 
    PictureBox1.BringToFront() 
    PictureBox1.Visible = True 

    gr.Dispose() 
    gr = Nothing 


    Return 

End Sub 

메시지를 표시하고 싶을 때마다 위의 하위 메뉴를 호출하십시오. 당신은 언제 어디에서 결정합니다. 당신은 당신이 더 이상 필요하지 않은 경우 picturebox을 숨길 필요가

PictureBox1.Visible = False 
+0

아래쪽 투표에는 어떤 이유가 있습니다. –

+0

이런 종류의 코드를 어디에 넣어야합니까? 그룹 박스 페인트 이벤트 내에서? 그래서 그것을 시도하고 그 결과를 볼 수 – Muj

+0

PNG 이미지의 @ * * * * * * * * 높이 *와 * 위치 * 변경합니까? 물론 위치는 * GroupBox6 *에 상대적입니다. –