添加和删​​除图像 [英] Adding and Removing Images

查看:62
本文介绍了添加和删​​除图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,感谢Crirus和Fergus几天前帮我发了一张相关的




好​​的,我可以添加图片到我的形式(无论出于什么原因,我不能在同一程序中添加更多

而不是1张图像;而是我不得不一遍又一遍地调用相同的

addimage程序再次让它工作)。


对于任何好奇的人,我使用的代码如下:

-------- -------------------------------------------------- ------------------

-----------------

子交易卡(ByVal值为字符串,ByVal locX为整数,ByVal locY为

整数)


将myCard调暗为新PictureBox()


Me.Controls.Add(myCard)


使用myCard

myCard =新版System.Windows.Forms .PictureBox()


.Visible = True


.Name = CStr(intCardsDealt)


intCardsDealt + = 1


.Size =新System.Drawing.Size(70,90)

.TabStop = False


.Location = New System.Drawing.Point(locX, locy)


.Image = Image.FromFile(" c:\ blackjack \" &安培;价值与价值" .jpg")


.BringToFront()


。显示()


结束


结束子


---------------------- -------------------------------------------------- ----

-------------------------------------- --------------------------------


如果你是的话想知道,是的,我正在创造一个二十一点游戏。 (我正在努力

改善我的记忆,以便我可以数卡。如果有人对

成品感兴趣,会非常乐意分享....只要你没有
期望每次赢得!!!)

无论如何,我试图四处寻找我的下一个问题:如何删除那些动态添加的
图像。


我试过:

Me.Controls。 RemoveAt(mintCount)其中mintCount是

控件的索引值的整数计数。


我甚至命名了新的图片框控件使用cstr(mintCount)值。


谢谢!


First of all, thanks to Crirus and Fergus for helping me with a related
posted a few days ago.

Ok, I can add images to my form (for whatever reason I cannot added more
than 1 image within the same procedure; rather I had to call the same
"addimage" procedure over and over again to get it working).

For anyone that''s curious the code I used is the following:
----------------------------------------------------------------------------
-----------------
Sub dealcards(ByVal value As String, ByVal locX As Integer, ByVal locY As
Integer)

Dim myCard As New PictureBox()

Me.Controls.Add(myCard)

With myCard

myCard = New System.Windows.Forms.PictureBox()

.Visible = True

.Name = CStr(intCardsDealt)

intCardsDealt += 1

.Size = New System.Drawing.Size(70, 90)

.TabStop = False

.Location = New System.Drawing.Point(locX, locY)

.Image = Image.FromFile("c:\blackjack\" & value & ".jpg")

.BringToFront()

.Show()

End With

End Sub

----------------------------------------------------------------------------
----------------------------------------------------------------------

And if you''re wondering, yes, I''m creating a blackjack game. (I''m trying to
improve my memory so that I can count cards. If anyone''s interested in the
finished product, would be more than happy to share....so long as you don''t
expect to win every time!!!)
Anyways, I''ve tried to surf around for my next problem: how to remove those
images I''ve added dynamically.

I tried:
Me.Controls.RemoveAt(mintCount) where mintCount is an integer count of the
control''s index value.

I''ve even named the new picture box controls with the cstr(mintCount) value.

Thanks!


推荐答案

*Andy Chan <一个*********** @ telus.net> scripsit:
* "Andy Chan" <an***********@telus.net> scripsit:
对于任何好奇的人,我使用的代码如下:
--------------------- -------------------------------------------------- -----
-----------------
子交易卡(ByVal值As String,ByVal locX As Integer,ByVal locY As
整数)

昏暗的myCard作为新的PictureBox()

Me.Controls.Add(myCard)


为什么要添加控制_before_设置其属性?

使用myCard

myCard = New System.Windows.Forms.PictureBox()


该行以上没有意义,因为你从不添加这个控件。

你可以删除它。

.Visible = True

.Name = CStr(intCardsDealt)

intCardsDealt + = 1

.Size = New System.Drawing.Size(70,90)

.TabStop = False

。Location = New System.Drawing.Point(locX,locY)

.Image = Image.FromFile(" c:\ blackjack \" &安培;价值与价值" .jpg")

.BringToFront()

。显示()

结束

结束子
[...]无论如何,我试图四处寻找我的下一个问题:如何删除我动态添加的那些图像。

我试过了:
Me.Controls.RemoveAt(mintCount)其中mintCount是
控件的索引值的整数计数。

我甚至命名了新的图片框使用cstr(mintCount)值控制。
For anyone that''s curious the code I used is the following:
----------------------------------------------------------------------------
-----------------
Sub dealcards(ByVal value As String, ByVal locX As Integer, ByVal locY As
Integer)

Dim myCard As New PictureBox()

Me.Controls.Add(myCard)
Why do you add the control _before_ setting its properties?

With myCard

myCard = New System.Windows.Forms.PictureBox()
The line above doesn''t make sense because you never add this control.
You can remove it.
.Visible = True

.Name = CStr(intCardsDealt)

intCardsDealt += 1

.Size = New System.Drawing.Size(70, 90)

.TabStop = False

.Location = New System.Drawing.Point(locX, locY)

.Image = Image.FromFile("c:\blackjack\" & value & ".jpg")

.BringToFront()

.Show()

End With

End Sub [...] Anyways, I''ve tried to surf around for my next problem: how to remove those
images I''ve added dynamically.

I tried:
Me.Controls.RemoveAt(mintCount) where mintCount is an integer count of the
control''s index value.

I''ve even named the new picture box controls with the cstr(mintCount) value.




您可以在表单中添加'Hashtable''(在'Private M_ht
As New Hashtable()'')并将所有控件添加到此表中。作为键你

可以使用控件的名称,值是控件本身。


稍后您可以轻松获得对控件的引用具体名称

通过从Hashtable查询它。然后你可以将这个引用传递给

''Me.Controls.Remove''方法。从

''Controls''集合中删除控件后,您可以将其从''Hashtable''中删除。


-

Herfried K. Wagner

MVP·VB Classic,VB.NET

< http://www.mvps.org/dotnet>



You can add a ''Hashtable'' to your form (on top of the form ''Private m_ht
As New Hashtable()'') and add all the controls to this table. As key you
can use the name of the control, the value is the control itself.

Later you can easily get a reference to the control with a specific name
by querying it from the Hashtable. Then you can pass this reference to
the ''Me.Controls.Remove'' method. After removing the control from the
''Controls'' collection, you can remove it from the ''Hashtable''.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>


哦是的,


很明显,我的表格上会有很多图片盒。我想要做的是b $ b尝试做的是遍历form.controls集合。


如果我使用form.remove(picturebox),我该怎么办?知道哪个图片框是什么?b $ b被删除?我没有运气就看过MSDN。


" Andy Chan" <一个*********** @ telus.net>在留言中写道

新闻:%2 *************** @ TK2MSFTNGP11.phx.gbl ...
Oh yes,

Obviously, I''ll have many pictureboxes on my form after a while. What I''m
trying to do is iterate through the form.controls collection.

If I use form.remove(picturebox), how would I know which picturebox was
being removed? I''ve looked at MSDN without luck.

"Andy Chan" <an***********@telus.net> wrote in message
news:%2***************@TK2MSFTNGP11.phx.gbl...
首先感谢Crirus和Fergus几天前帮我发了一个相关的

好的,我可以在我的表单中添加图片(无论出于什么原因我无法添加更多
在同一程序中超过1张图像;而是我不得不一遍又一遍地调用相同的添加图像程序以使其正常工作。

对于任何好奇的人我使用的代码如下:
-------------------------------------- ------------------------------------
- -------- ---------
子交易卡(ByVal值As String,ByVal locX As Integer,ByVal locY As
整数)

Dim myCard As New PictureBox()

Me.Controls.Add(myCard)

使用myCard

myCard = New System.Windows.Forms.PictureBox()

.Visible = True

。Name = CStr(intCardsDealt)

intCardsDealt + = 1

.Size = New System.Drawing.Size(70,90)

.TabStop = False

.Location =新的System.Drawing.Point(locX,locY)

.Image = Image.FromFile(" c:\ blackjack \" &安培;价值与价值" .jpg")

.BringToFront()

。显示()

结束

结束子

------------------------------------------ --------------------------------
- ------------ -------------------------------------------------- --------

如果你想知道,是的,我正在创造一个二十一点游戏。 (我正在尝试
来改善我的记忆力以便我可以计算卡片。如果有人对
成品感兴趣,那将非常乐意分享....只要你不能期望每次赢得
!!!)

无论如何,我试图四处寻找我的下一个问题:如何删除
那些图像我已经动态添加了。

我试过:
Me.Controls.RemoveAt(mintCount)其中mintCount是
控件的索引值的整数计数。 br />
我甚至用cstr(mintCount)
值命名了新的图片框控件。
谢谢!


First of all, thanks to Crirus and Fergus for helping me with a related
posted a few days ago.

Ok, I can add images to my form (for whatever reason I cannot added more
than 1 image within the same procedure; rather I had to call the same
"addimage" procedure over and over again to get it working).

For anyone that''s curious the code I used is the following:
-------------------------------------------------------------------------- -- -----------------
Sub dealcards(ByVal value As String, ByVal locX As Integer, ByVal locY As
Integer)

Dim myCard As New PictureBox()

Me.Controls.Add(myCard)

With myCard

myCard = New System.Windows.Forms.PictureBox()

.Visible = True

.Name = CStr(intCardsDealt)

intCardsDealt += 1

.Size = New System.Drawing.Size(70, 90)

.TabStop = False

.Location = New System.Drawing.Point(locX, locY)

.Image = Image.FromFile("c:\blackjack\" & value & ".jpg")

.BringToFront()

.Show()

End With

End Sub

-------------------------------------------------------------------------- -- ----------------------------------------------------------------------

And if you''re wondering, yes, I''m creating a blackjack game. (I''m trying to improve my memory so that I can count cards. If anyone''s interested in the
finished product, would be more than happy to share....so long as you don''t expect to win every time!!!)
Anyways, I''ve tried to surf around for my next problem: how to remove those images I''ve added dynamically.

I tried:
Me.Controls.RemoveAt(mintCount) where mintCount is an integer count of the
control''s index value.

I''ve even named the new picture box controls with the cstr(mintCount) value.
Thanks!




好的。一些成功。


无法弄清楚如何从表单中删除图像,但我将

卡添加到面板中,并将其删除从小组。 Tada !!!


我还是宁愿直接在表格上添加和删除卡片,所以

仍然会欣赏一些指导。谢谢!


" Andy Chan" <一个*********** @ telus.net>在留言中写道

新闻:%2 *************** @ TK2MSFTNGP11.phx.gbl ...
OK. Some success.

Couldn''t figure out how to remove the image from the form, but I added the
cards to a panel, and removed it from the panel. Tada!!!

I''d still rather just add and remove the cards directly onto the form, so
would still appreciate some guidance. Thanks!

"Andy Chan" <an***********@telus.net> wrote in message
news:%2***************@TK2MSFTNGP11.phx.gbl...
首先感谢Crirus和Fergus几天前帮我发了一个相关的

好的,我可以在我的表单中添加图片(无论出于什么原因我无法添加更多
在同一程序中超过1张图像;而是我不得不一遍又一遍地调用相同的添加图像程序以使其正常工作。

对于任何好奇的人我使用的代码如下:
-------------------------------------- ------------------------------------
- -------- ---------
子交易卡(ByVal值As String,ByVal locX As Integer,ByVal locY As
整数)

Dim myCard As New PictureBox()

Me.Controls.Add(myCard)

使用myCard

myCard = New System.Windows.Forms.PictureBox()

.Visible = True

。Name = CStr(intCardsDealt)

intCardsDealt + = 1

.Size = New System.Drawing.Size(70,90)

.TabStop = False

.Location =新的System.Drawing.Point(locX,locY)

.Image = Image.FromFile(" c:\ blackjack \" &安培;价值与价值" .jpg")

.BringToFront()

。显示()

结束

结束子

------------------------------------------ --------------------------------
- ------------ -------------------------------------------------- --------

如果你想知道,是的,我正在创造一个二十一点游戏。 (我正在尝试
来改善我的记忆力以便我可以计算卡片。如果有人对
成品感兴趣,那将非常乐意分享....只要你不能期望每次赢得
!!!)

无论如何,我试图四处寻找我的下一个问题:如何删除
那些图像我已经动态添加了。

我试过:
Me.Controls.RemoveAt(mintCount)其中mintCount是
控件的索引值的整数计数。 br />
我甚至用cstr(mintCount)
值命名了新的图片框控件。
谢谢!


First of all, thanks to Crirus and Fergus for helping me with a related
posted a few days ago.

Ok, I can add images to my form (for whatever reason I cannot added more
than 1 image within the same procedure; rather I had to call the same
"addimage" procedure over and over again to get it working).

For anyone that''s curious the code I used is the following:
-------------------------------------------------------------------------- -- -----------------
Sub dealcards(ByVal value As String, ByVal locX As Integer, ByVal locY As
Integer)

Dim myCard As New PictureBox()

Me.Controls.Add(myCard)

With myCard

myCard = New System.Windows.Forms.PictureBox()

.Visible = True

.Name = CStr(intCardsDealt)

intCardsDealt += 1

.Size = New System.Drawing.Size(70, 90)

.TabStop = False

.Location = New System.Drawing.Point(locX, locY)

.Image = Image.FromFile("c:\blackjack\" & value & ".jpg")

.BringToFront()

.Show()

End With

End Sub

-------------------------------------------------------------------------- -- ----------------------------------------------------------------------

And if you''re wondering, yes, I''m creating a blackjack game. (I''m trying to improve my memory so that I can count cards. If anyone''s interested in the
finished product, would be more than happy to share....so long as you don''t expect to win every time!!!)
Anyways, I''ve tried to surf around for my next problem: how to remove those images I''ve added dynamically.

I tried:
Me.Controls.RemoveAt(mintCount) where mintCount is an integer count of the
control''s index value.

I''ve even named the new picture box controls with the cstr(mintCount) value.
Thanks!




这篇关于添加和删​​除图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆