一个实现小的上位机
一:运行上位机时显示先实现一张图片再显示
打开Visual Studio新建Windows窗体应用程序项目
右键点击WindowsFormsApplication1再添加一个Windows窗体应用程序

添加后可以看到有两个from界面

这是双击右边窗口 解决方案资源管理器中的 Program.cs会出现一个窗口页面,这个页面只有from1的初始化,现在手动添加from2的初始化。


当程序运行时,会先运行form1,待form1关闭后才会运行form2。所以把form1用来做启动时的图片显示效果,form2来做真正的上位机。那么现在要解决的问题就是程序启动后form1执行一段时间后就自己把自己关掉,好让from2开始运行。
在form1中增加定时器,设置两秒触发一次事件,再在触发事件中,关掉form1.当然得先把图片加进去。加入方法有两种,一种用本地定电脑上的。一种先把图片添加到项目,再从项目中添加图片。这里我们选择第二种,因为这种方法在其他电脑上也是可以成功显示的。
双击Resources.resx

得到下面的窗口,并添加现有文件。

这里找到要添加的图片,添加后可以给文件重命名

然后再在form1中,给窗口添加背景图片

如果图片大小跟窗口不匹配可以按下图改窗口属性,根据实际情况,选择属性值。

运行一下可以看到窗口的边框还在。然而这里不需要显示边框,所以要设置窗口属性,使边框不显示。

在窗口属性中设置

这样窗口的边框就不会再显示。

因为一般软件的启动都是在屏幕的中间,所以这里改一下属性,始打开的时候在屏幕的中间显示

然后在form1中添加定时器控件。怎么添加就不说了

双击这个定时器控件就开始写程序。不过得先使定时器使能,应为默认定时器是关闭的。可以用程序打开,也可以直接改属性值。

这里我把时间改为2000ms,即2s进一次事件。双击定时器后得到我们写程序的界面

在再程序写如下代码。

然后运行就有前面要求的效果了。