2
画像がロードされた通常の画像ボックスがあるとします。ユーザーが画像をクリックしたときに画像をどのように変更できますか?vb.netの1つの画像を別の画像に変更する
例:海のクリップアートに変更された本のクリップアート。
画像がロードされた通常の画像ボックスがあるとします。ユーザーが画像をクリックしたときに画像をどのように変更できますか?vb.netの1つの画像を別の画像に変更する
例:海のクリップアートに変更された本のクリップアート。
をこれが作業を行う必要があります。
Dim OldImage As Image
Private Sub PictureBox1_Click(sender As System.Object, e As System.EventArgs) Handles PictureBox1.Click
OldImage = PictureBox1.Image 'This will store the image before changing. Set this in Form1_Load() handler
PictureBox1.Image = Image.FromFile("C:\xyz.jpg") 'Method 1 : This will load the image in memory
PictureBox1.ImageLocation = "C:\xyz.jpg" 'Method 2 : This will load the image from the filesystem and other apps won't be able to edit/delete the image
PictureBox1.Image = My.Resources.Image 'Method 3 : This will also load the image in memory from a resource in your appc
PictureBox1.Image = OldImage 'Set the image again to the old one
End Sub
リスト内の画像を保持し、リストからインデックスをspecificyingでのPictureBoxの画像を変更します。PictureBox
と
簡単な例:
Public Class Form1
Private _Images As New List(Of Image)
Private _ImageIndex As Integer
Public Sub New()
InitializeComponent()
For i As Integer = 1 To 3
Dim bmp As New Bitmap(32, 32)
Using g As Graphics = Graphics.FromImage(bmp)
Select Case i
Case 1 : g.Clear(Color.Blue)
Case 2 : g.Clear(Color.Red)
Case 3 : g.Clear(Color.Green)
End Select
End Using
_Images.Add(bmp)
Next
End Sub
Private Sub PictureBox1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles PictureBox1.Click
If _Images.Count > 0 Then
PictureBox1.Image = _Images(_ImageIndex)
_ImageIndex += 1
If _ImageIndex > _Images.Count - 1 Then
_ImageIndex = 0
End If
End If
End Sub
End Class
これらの方法のいずれかを使用して画像を戻す方法はありますか? – HunderingThooves
更新された回答。 – Elmo