如何删除添加到panel1.controls的所有图片框

编程入门 行业动态 更新时间:2024-10-20 00:38:12
本文介绍了如何删除添加到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的所有图片框

本文发布于:2023-11-06 13:50:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1563872.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图片   controls

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!