2016-12-07 5 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

私の目標は、画像Completedの上にtextbox, labelの上に私のgroupboxの任意のアイデアを描くことですか?

+0

ユーザーがプロセスを完了したときにオーバーレイとして画像を表示し、根本的なコントロールを非表示にしたいですか?グループボックスに画像を描画するのではなく、ステータスが「キャンセル」のときに、Groupboxの代わりに表示されるPictureBoxコントロールを使用する方が簡単だと思います。 – Markus

+0

@マークス私はそれを保持するコントロールに画像をペイントする理由は、透明ではないので、私は画像ボックスを使用する場合。私の場合、txtboxとラベルは画像をカバーしています。私はちょうどそれをペイントし、おそらくグループボックスの中のgropboxと他のコントロールの前にそれを送ろうとします – Muj

+1

私が考えることができる2つの解決策があります。 1.レイヤードウィンドウを作成し、コントロールの上に表示します。2.画像が表示される部分のスクリーンショットを撮り、picboxに描画してから、 –

答えて

0

これが機能するには、bitmapspictureboxの2つが必要です。ピクチャを表示する

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 

サブ

形態負荷イベントに

Private pngImage, picBoxImage As Image 

2つのイメージを初期化:最初のものはpicturebox画像がpng画像および第2ものです

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画像の@Muj Do * width *、* height *、* position *は変わりますか?もちろん、位置は* GroupBox6 *に相対的です。 –

関連する問題