如何在执行时在WINDOWS FORM APP上插入图片? [英] how do I INSERT A PICTURE ON WINDOWS FORM APP WHILE IT IS EXECUTING?

查看:142
本文介绍了如何在执行时在WINDOWS FORM APP上插入图片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在执行时在WINDOWS FORM APP上插入图片

推荐答案

要插入图片,您可以使用PictureBox。不确定你对它正在执行的意思,如果你在表单打开时有大量工作要做,你可以使用后台工作程序,这样工作就在后台完成,不会阻止/冻结表单。否则你需要使用InvokeRequired,因为从另一个线程访问表单控件会导致异常。
To insert a picture you can use a PictureBox. Not sure what you mean about "it is executing", if you have intensive work to do while the form is open you can use Background Worker so the work is done in the background and does not block/freeze the form. Otherwise you need to use InvokeRequired because accessing the form control from another thread will cause an exception.


除了BacchusBeale的回答:



使用控件 System.Windows.Forms.PictureBox 只是添加图像的方法之一。我只想强调:每个图像或控件总是在正在执行时添加。即使你使用设计师这样做,它实际上是在正在执行时添加的。



这是我的一般建议:如果你知道如何添加任何东西设计师但不确定如何自己编写适当的代码,首先在调试器下进行,然后查看自动生成的代码。如果是Forms,它会被添加到您的项目中,如果是WPF,则不是,因此您必须在项目目录下找到它。



In你的情况,例如

In addition to the answer by BacchusBeale:

Using the control System.Windows.Forms.PictureBox is just one of the way to add an image. I only would like to emphasize: each and every image or control is always added "while it is executing". Even if you do it using the designer, it is actually added "while it is executing".

Here is my general advice: if you know how to add anything using the designer but not sure how to write appropriate code by yourself, first do it under the debugger and then look at the auto-generated code. In case of Forms, it is added to your project, in case of WPF, it is not, so you would have to find it under your project's directory.

In you case, for example
Control parent = // it could be any container control: Panel, TabPage, Form
PictureBox picture = new PictureBox();
picture.Image = // whatever image you want to show
// set position, dock and other required properties...
// add it:
parent.Controls.Add(picture);
// alternative way of doing the same:
//picture.Parent = parent;



一般来说,这是添加任何控件的方式。



-SA


这篇关于如何在执行时在WINDOWS FORM APP上插入图片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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