显示图像的弹出窗口 vb.net
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13231580/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
popup window to display image vb.net
提问by user1800025
I'm trying to do something in VB.net but not succeeding. I have a linklabel on a form which when a user clicks it will need to display a pop up window with an image.
我正在尝试在 VB.net 中做一些事情,但没有成功。我在表单上有一个链接标签,当用户单击它时,它需要显示一个带有图像的弹出窗口。
Can anyone help me with this please?
任何人都可以帮我解决这个问题吗?
I have the following code but it only displays the popup form and the image is displayed on the main form of where the linklabel is and not in the popup form.
我有以下代码,但它只显示弹出窗体,图像显示在链接标签所在的主窗体上,而不显示在弹出窗体中。
Dim Obj As New Form
Obj.Show()
PictureBox1.Image = Image.FromFile("d:\testImage.jpg")
回答by Nianios
What you have to do is to add a pictureBox in the popup form (PictureBox1) Then:
你要做的就是在弹出的窗体(PictureBox1)中添加一个图片框然后:
Dim Obj As New Form
Obj.PictureBox1.Image = Image.FromFile("d:\testImage.jpg")
Obj.Show()
回答by Ahmad
Assuming that you already have designed a form (let's call it Form2) and this form has a picturebox inside it, then:
假设您已经设计了一个表单(我们称之为 Form2)并且这个表单里面有一个图片框,那么:
You need to load the image before loading the pop up window to the user Also make sure the pop-up window shows modaly to avoid confusion that may arise by the window being loaded but behind the parent form that loaded it.
您需要在将弹出窗口加载给用户之前加载图像 还要确保弹出窗口显示模态,以避免由于正在加载的窗口但位于加载它的父窗体后面而可能出现的混淆。
Dim Obj As New Form2 'You need to specify the form name that you have already designed.
Obj.PictureBox1.Image = Image.FromFile("d:\testImage.jpg")
Obj.ShowDialog() 'ShowDialog will force the user to close the form first before
'coming back to the original form
回答by Skindeep2366
right click your project. Then add new form. Name it form2then on that form drop a picture box. Now for simple how-to on your form1 add a button.. Double click the button so you get the click event. In the code you will enter:
右键单击您的项目。然后添加新表格。命名它,form2然后在该表单上放置一个图片框。现在,在您的 form1 上添加一个按钮的简单操作方法。双击该按钮,您将获得单击事件。在代码中,您将输入:
Dim myForm2 As New Form2
myForm2.PictureBox1.Image = Image.FromFile("d:\testImage.jpg")
myForm2.showDialog
'Any actions after the user returns would be here
myForm2.dispose()
myForm2 is a new instance of your Form2. Note Form2 is the namethat you have assigned to form2 under form2 property window.
myForm2 是您的 Form2 的新实例。注意 Form2 是name您在 form2 属性窗口下分配给 form2 的。
To add a new form to your project.. Right click your project name in solution explorer. Then ADD. Then windows form... Name it Form2.vb.
向您的项目添加新表单.. 在解决方案资源管理器中右键单击您的项目名称。然后加。然后windows窗体...将其命名为Form2.vb。
After that go to the design view for form2 and drop a picture box on the form... Then go to form1 and use the above code on a button click event to see it work..
之后转到form2的设计视图并在窗体上放置一个图片框...然后转到form1并在按钮单击事件上使用上面的代码来查看它的工作..

