如何删除添加到panel1.controls的所有图片框 [英] How do I remove all picture boxes added to panel1.controls
问题描述
所以,我能够接近程序中的内容,我遇到的问题是当我选择一个新行时,它会将图像与旧图像一起添加。如果我添加一个Me.panel1.controls.clear语句,它将删除图片,但它会留下空格。我试图只显示与我选择的行相关的图片。
以下是我正在使用的代码:
Private Sub Gridview_selectedIndexchenge (ByVal sender As Object,ByVal e As EventArgs)处理DataGridView1.MouseClick
每个DGRS作为DataGridViewRow在DataGridView1.SelectedRows
Dim I As Integer = 0
I = DataGridView1.SelectedRows(0).Index
Dim IC As Integer = 0
IC = DataGridView1.Columns(0).Index
如果DGRS.Selected = True然后
Dim rowpic =(DataGridView1.Rows(I).Cells(0).Value)
PictureBox1.Image = rowpic
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
DGRS.Dispose()
End if
Next
For Each Imgdgvi As DataGridViewImageCell In DataGridView1.SelectedCells
Dim pic As New PictureBox()
pic.I mage = Imgdgvi.Value
pic.SizeMode = PictureBoxSizeMode.StretchImage
pic.SetBounds(wid,20,200,100)
'pic.Location = New Point(10, pic.Height)
AddHandler pic.Click,AddressOf convertPic
Me.Panel1.Controls.Add(pic)
wid + = 205
Next
结束子
有人可以用一种简单的方法来帮助我删除旧的并添加新的一行选择?
我尝试了什么:
我有尝试在panel1.control中为每个img设置一个图片框,然后使用一个不起作用的删除语句。我试过了明显的me.panel1.controls.clear,但它留下了空格。
试试这个
私有 Sub Gridview_selectedIndexchenge( ByVal sender 作为 对象, ByVal e As EventArgs)句柄 DataGridView1.MouseClick
me .panel1.controls.clear()
wid = 0
For 每个 DGRS As DataGridViewRow 在 DataGridView1.SelectedRows
Dim 我正如 整数 = 0
I = DataGridView1.SelectedRows( 0 )。索引
Dim IC As 整数 = 0
IC = DataGridView1.Columns( 0 )。索引
如果 DGRS.Selected = True 然后
Dim rowpic =(DataGridView1.Rows(I )。细胞( 0 )。值)
PictureBox1.Image = rowpic
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
DGRS.Dispose()
结束 I f
下一步
对于 每个 Imgdgvi As DataGridViewImageCell In DataGridView1.SelectedCells
Dim pic 作为 新 PictureBox()
pic.Image = Imgdgvi.Value
pic.SizeMode = PictureBoxSizeMode.StretchImage
pic.SetBounds(wid, 20 , 200 , 100 )
' pic.Location = New Point(10,pic.Height)
AddHandler pic.Click, AddressOf convertPic
我 .Panel1.Controls.Add(pic)
wid + = 205
下一步
结束 Sub 跨度>
So, I am able to do close to what in the program, The problem I am having is when I go to select a new row, it adds the images along with the old one. If I add a Me.panel1.controls.clear statement it removes the picture, but it leaves empty spaces. I am trying to show only the pictures related to the row I pick.
Here is the code I am working with:
Private Sub Gridview_selectedIndexchenge(ByVal sender As Object, ByVal e As EventArgs) Handles DataGridView1.MouseClick For Each DGRS As DataGridViewRow In DataGridView1.SelectedRows Dim I As Integer = 0 I = DataGridView1.SelectedRows(0).Index Dim IC As Integer = 0 IC = DataGridView1.Columns(0).Index If DGRS.Selected = True Then Dim rowpic = (DataGridView1.Rows(I).Cells(0).Value) PictureBox1.Image = rowpic PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage DGRS.Dispose() End If Next For Each Imgdgvi As DataGridViewImageCell In DataGridView1.SelectedCells Dim pic As New PictureBox() pic.Image = Imgdgvi.Value pic.SizeMode = PictureBoxSizeMode.StretchImage pic.SetBounds(wid, 20, 200, 100) ' pic.Location = New Point(10, pic.Height) AddHandler pic.Click, AddressOf convertPic Me.Panel1.Controls.Add(pic) wid += 205 Next End Sub
Could someone help me with a simple way to remove the old and add te new through a row select?
What I have tried:
I have tried to set a for each img as picturebox in panel1.control then using a remove statement, that didn't work. I have tried the obvious me.panel1.controls.clear, but it leaves empty spaces.
Try this
Private Sub Gridview_selectedIndexchenge(ByVal sender As Object, ByVal e As EventArgs) Handles DataGridView1.MouseClick me.panel1.controls.clear() wid = 0 For Each DGRS As DataGridViewRow In DataGridView1.SelectedRows Dim I As Integer = 0 I = DataGridView1.SelectedRows(0).Index Dim IC As Integer = 0 IC = DataGridView1.Columns(0).Index If DGRS.Selected = True Then Dim rowpic = (DataGridView1.Rows(I).Cells(0).Value) PictureBox1.Image = rowpic PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage DGRS.Dispose() End If Next For Each Imgdgvi As DataGridViewImageCell In DataGridView1.SelectedCells Dim pic As New PictureBox() pic.Image = Imgdgvi.Value pic.SizeMode = PictureBoxSizeMode.StretchImage pic.SetBounds(wid, 20, 200, 100) ' pic.Location = New Point(10, pic.Height) AddHandler pic.Click, AddressOf convertPic Me.Panel1.Controls.Add(pic) wid += 205 Next End Sub
这篇关于如何删除添加到panel1.controls的所有图片框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!