C#图片查看器

一、窗体及功能实现

在这里插入图片描述

二、代码

【1】加载窗体

        public 图片()
        {
   
            InitializeComponent();
            this.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.pMouseWheel);
        }

【2】变量

        private List<string> ImagePaths = new List<string>();
        string PicPath;
        string APath;
        string[] AllPath;
        int PicNum = 0;
        private string PicNumber;
        private string PicNow;

【3】打开图片

        private void button1_Click(object sender, EventArgs e)
        {
   
            ImagePaths.Clear();
            OpenFileDialog OpenPic = new OpenFileDialog();
            OpenPic.Title = "请选择要打开的文件";
            OpenPic.InitialDirectory = @"C:\";
            OpenPic.Filter = "所有图片(*.jpg*.jpeg*.bmp*.gif*.png)|*.jpg;*.jpeg;*.bmp;*.gif;*.png|JPG图片(*.jpg)|*.jpg;*.jpeg|位图(*bmp)|*.bmp|GIF文件(*.gif)|*.gif|PNG文件(*.png)|*.png";
            OpenPic.ShowDialog();
            PicPath = OpenPic.FileName;
            if (PicPath == "")
            {
   
                return;
            }
            else
            {
   
                APath = Path.GetDirectoryName(PicPath);
                AllPath = Directory.GetFiles(APath);
                string BPath = PicPath
  • 4
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
要将FTP服务器上的图片下载到计算机的临时文件夹中,并使用系统自带的图片查看器打开,你可以使用C#中的WebClient类来下载图片使用Process.Start方法来启动默认的图片查看器来打开下载的图片。下面是一个示例代码: ```csharp using System; using System.Diagnostics; using System.IO; using System.Net; using System.Windows.Forms; namespace FTPImageDownloader { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void btnDownload_Click(object sender, EventArgs e) { // FTP服务器地址 string ftpServer = "ftp://example.com"; // 图片路径 string imagePath = "/path/to/image.jpg"; // 临时文件夹路径 string tempFolderPath = Path.GetTempPath(); // 下载后保存的文件路径 string saveFilePath = Path.Combine(tempFolderPath, "downloaded_image.jpg"); using (WebClient client = new WebClient()) { // 指定FTP登录凭据(可根据需要更改) client.Credentials = new NetworkCredential("username", "password"); try { // 下载图片到临时文件夹 client.DownloadFile(ftpServer + imagePath, saveFilePath); // 使用默认的图片查看器打开下载的图片 Process.Start(saveFilePath); } catch (WebException ex) { MessageBox.Show("无法连接到FTP服务器:" + ex.Message); } } } } } ``` 在上述示例中,你需要将`ftpServer`变量替换为你的FTP服务器地址,将`imagePath`变量替换为你要下载的图片路径。同时,你还需要提供正确的FTP登录凭据。 这个示例使用了一个按钮(`btnDownload`)。当用户点击下载按钮时,它会从FTP服务器下载图片并保存到计算机的临时文件夹中,然后使用默认的图片查看器打开下载的图片。 请注意,这种方法依赖于操作系统的默认设置和关联程序。不同的操作系统和配置可能会导致不同的行为。同时,下载的图片将保存在计算机的临时文件夹中,可能会被系统清理程序自动删除。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值