苏飞论坛

标题: C#另存为代码怎么写,想要存在本地的硬盘上或者桌面 [打印本页]

作者: 熊淑瑤是我女神    时间: 2014-6-6 15:07
标题: C#另存为代码怎么写,想要存在本地的硬盘上或者桌面
[C#] 纯文本查看 复制代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog open = new OpenFileDialog();
            open.InitialDirectory = "c:\\";

            open.Filter = "图片文件(jpg,jpeg,bmp,gif,ico,pen,tif)|*.jpg;*.jpeg;*.bmp;*.gif;*.ico;*.png;*.tif;*.wmf";

            if (open.ShowDialog()== DialogResult.OK)
            {
                pictureBox1.ImageLocation = open.FileName;
            }
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {


        }

        private void 居中ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;



        }

        private void toolStripMenuItem1_Click(object sender, EventArgs e)
        {
            pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;
        }

        private void 正常ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
        }

        private void toolStripMenuItem2_Click(object sender, EventArgs e)
        {
            pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
        }

        private void 说明ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MessageBox.Show("右击也可以使用功能","信息框",MessageBoxButtons.OK,MessageBoxIcon.None);
        }



        private void 另存为ToolStripMenuItem_Click(object sender, EventArgs e)       //这里的另存为代码怎么写,能够保存在硬盘里或者桌面上?
        {
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                string i = saveFileDialog1.FileName;              


            }

        }


    }
}

作者: 站长苏飞    时间: 2014-6-6 15:12
你想要的这里都有http://www.sufeinet.com/thread-197-1-1.htmlC#Notepad记事本实现
作者: 熊淑瑤是我女神    时间: 2014-6-6 15:29
站长苏飞 发表于 2014-6-6 15:12
你想要的这里都有http://www.sufeinet.com/thread-197-1-1.htmlC#Notepad记事本实现

网站打不开。404
作者: 站长苏飞    时间: 2014-6-6 15:35
http://www.sufeinet.com/thread-197-1-1.html
作者: 熊淑瑤是我女神    时间: 2014-6-6 15:50
站长苏飞 发表于 2014-6-6 15:35
http://www.sufeinet.com/thread-197-1-1.html

SaveFileDialog savefile = new SaveFileDialog();
            savefile.Filter = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*";
            if (savefile.ShowDialog() == DialogResult.OK)
            {
                this.richTextBox1.SaveFile (savefile .FileName ,RichTextBoxStreamType.PlainText );
            }
他的这个是记事本的保存。我运用到我那个图片浏览器里,保存后打开说是空的。 他用的是richTextBox1,我用的是pictureBox1哪里需要修改
SaveFileDialog save = new SaveFileDialog();
            save.Filter = "图片文件(jpg,jpeg,bmp,gif,ico,pen,tif)|*.jpg;*.jpeg;*.bmp;*.gif;*.ico;*.png;*.tif;*.wmf";
            if (save.ShowDialog() == DialogResult.OK)
            {
                this.richTextBox1.SaveFile(save.FileName, RichTextBoxStreamType.PlainText);


            }
作者: 站长苏飞    时间: 2014-6-6 15:52
这只是个一个保存对话框,保存的功能要你自己写的,肯定是修改这里了  this.richTextBox1.SaveFile(save.FileName, RichTextBoxStreamType.PlainText);

作者: 熊淑瑤是我女神    时间: 2014-6-6 16:03
站长苏飞 发表于 2014-6-6 15:52
这只是个一个保存对话框,保存的功能要你自己写的,肯定是修改这里了  this.richTextBox1.SaveFile(save.Fi ...

知道是这里,只不过不知道怎么改,我想把已经打开的图片,保存在桌面,但他这个例子和我的不一样,不知道该怎么改。
作者: 站长苏飞    时间: 2014-6-6 16:19
你在这里写Image.save( )看看这个方法怎么用就行了,save.FileName这是得到的路径
作者: 熊淑瑤是我女神    时间: 2014-6-6 17:24
站长苏飞 发表于 2014-6-6 16:19
你在这里写Image.save( )看看这个方法怎么用就行了,save.FileName这是得到的路径

知道了,谢谢站长~
作者: 学习抓包的    时间: 2014-6-10 09:10
强烈支持楼主ing……




欢迎光临 苏飞论坛 (http://www.sufeinet.com/) Powered by Discuz! X3.4