弹出窗口显示图像vb.net



我正在尝试在vb.net中做某事,但不成功。我在表单上有一个linkLabel,当用户单击时,它将需要显示带有图像的弹出窗口。

有人可以帮我吗?

i具有以下代码,但它仅显示弹出式形式,图像显示在linklabel所在位置的主要形式,而不是以弹出形式显示。

Dim Obj As New Form
Obj.Show()
PictureBox1.Image = Image.FromFile("d:testImage.jpg")

您要做的是在弹出式表单中添加一个picturebox(picturebox1)然后:

Dim Obj As New Form
Obj.PictureBox1.Image = Image.FromFile("d:testImage.jpg")
Obj.Show()

假设您已经设计了一个表单(我们称其为form2),并且该表单中有一个picturebox,则:

您需要在将弹出窗口加载到用户之前加载图像还要确保弹出窗口显示Modaly,以避免被加载的窗口可能引起的混淆,但在加载它的父级形式后面。

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

右键单击您的项目。然后添加新表单。将其命名为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是您的Form2的新实例。Note Form2是您在Form2属性窗口下分配给Form2的name

要在您的项目中添加新表格。.右键单击"解决方案资源管理器"中的项目名称。然后加。然后Windows表单...将其命名为form2.vb。

之后,请转到Form2的设计视图,然后在表单上放置图片框...然后转到Form1并在按钮单击事件上使用上述代码以查看其工作。

最新更新