[WinForm]动态显示本地目录图片与悬浮窗

时间:2023-12-14 22:18:38

加载显示:

            if (File.Exists(@"D:\产品图片\" + item + ".jpg"))
            {
                //需要判断是否存在图片
                Image img = Image.FromFile(@"D:\产品图片\" + item + ".jpg");//双引号里是图片的路径
                picProduct.Image = img;
            }
            else
            {
                //需要判断是否存在图片
                Image img = Image.FromFile(@"D:\产品图片\LOGO.jpg");//双引号里是图片的路径
                picProduct.Image = img;
            }

悬浮窗口显示大图:

private void btnShowBig_Click(object sender, EventArgs e)
        {
            if (fp == null)
            {
                fp = new FrmPic();
                fp.Item = this.txtItem.Text.Trim();
                fp.Width = 600;
                fp.Height = 600;
                fp.Show();
            }
            else
            {
                if (fp.IsDisposed)
                {
                    fp = new FrmPic();
                    fp.Item = this.txtItem.Text.Trim();
                    fp.Width = 600;
                    fp.Height = 600;
                    fp.Show();
                }
                else
                {
                    fp.WindowState = FormWindowState.Normal;
                    fp.TopMost = true;
                }
            }
        }

[WinForm]动态显示本地目录图片与悬浮窗