本文介绍了如何从C#中的输入读取url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发记事本项目并部署该项目.安装后选择Windows任何文本文件.右键单击这些文件,然后选择打开并按已安装的文件浏览".
无法读取此文件.如何在不使用openfile dailog()的情况下直接读取此文件 我在项目中使用文本框.我已经在记事本中使用openfile dailod().
我想直接在记事本中打开Windows文本文件.请帮助我如何打开此文件



i am develop notepad project and deploy this project. after install this to select windows any text file .right click those file select openwith browse by installed file.
can''t read this file .how to read this file directly with out using openfile dailog()
i am using textbox in my project.i am already used openfile dailod() in my notepad.
I want directly open windows text files in my notepad. please help me how to open this files



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

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



      }

        private void newToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //textBox1.Clear();
            {

                // check if the text is modified

                if (textBox1.Modified)
                {

                    //if text is modified then ask the user if to save it or not

                    DialogResult ask;

                    ask = MessageBox.Show("Do you want to save the changes", "New Document", MessageBoxButtons.YesNo);

                    {

                        try
                        {

                            //if user clicks No, then notepad will be cleared

                            if (ask == DialogResult.No)

                                textBox1.Clear();

                                // if user clicks yes, save file dialog will appear

                            else if (ask == DialogResult.Yes)

                                saveFileDialog1.ShowDialog();



                            //saving the file process

                            System.IO.StreamWriter file = new System.IO.StreamWriter(saveFileDialog1.FileName, true);

                            string text = textBox1.Text;

                            file.WriteLine(text);

                            file.Close();

                            textBox1.Clear();

                        }

                        catch
                        {

                            MessageBox.Show("you loss the data");

                        }







                    }



                }
            }




        }

        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            openFileDialog1.ShowDialog();
            System.IO.StreamReader openFile = new System.IO.StreamReader(openFileDialog1.FileName);
            textBox1.Text = openFile.ReadToEnd();
            openFile.Close();
        }

        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            System.IO.StreamWriter saveFile = new System.IO.StreamWriter(openFileDialog1.FileName);
            saveFile.WriteLine(textBox1.Text);
            saveFile.Close();
        }

        private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
        {


            saveFileDialog1.ShowDialog();
            System.IO.StreamWriter saveFile = new System.IO.StreamWriter(saveFileDialog1.FileName);
            saveFile.WriteLine(textBox1.Text);
            saveFile.Close();
        }

        private void printToolStripMenuItem_Click(object sender, EventArgs e)
        {
            System.Drawing.Printing.PrintDocument prntDoc = new System.Drawing.Printing.PrintDocument();
        }

        private void printPreviewToolStripMenuItem_Click(object sender, EventArgs e)
        {
            System.Drawing.Printing.PrintDocument prntDoc = new System.Drawing.Printing.PrintDocument();


            //Declare preview as a new PrintPreviewDialog
            PrintPreviewDialog preview = new PrintPreviewDialog();
            //Declare prntDoc_PrintPage as a new EventHandler for prntDoc's Print Page
           // prntDoc.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(PrintPreviw);
            //Set the PrintPreview's Document equal to prntDoc
            preview.Document = prntDoc;
            //Show the PrintPreview Dialog
            if (preview.ShowDialog(this) == DialogResult.OK)
            {
                //Generate the PrintPreview
                prntDoc.Print();
            }


        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
           // Application.Exit();


            if (textBox1.Modified)
            {

                // if file is modified, then ask if the user want to save the changes

                DialogResult ask;

                ask = MessageBox.Show("Do you want to save the changes", "Exit", MessageBoxButtons.YesNo);

                {

                    try
                    {

                        // if user clicks no, program exits

                        if (ask == DialogResult.No)

                            Application.Exit();

                            // if user clicks yes, program save file

                        else if (ask == DialogResult.Yes)

                            saveFileDialog1.ShowDialog();



                        System.IO.StreamWriter file = new System.IO.StreamWriter(saveFileDialog1.FileName, true);

                        string text = textBox1.Text;

                        file.WriteLine(text);

                        file.Close();

                        Application.Exit();

                    }

                    catch
                    {

                        MessageBox.Show("you loss the data");

                    }



                }

            }

            else

                Application.Exit();













        }

        private void undoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox1.Undo();
        }

        private void redoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox1.Undo();
        }

        private void cutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox1.Cut();
        }

        private void copyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox1.Copy();
        }

        private void pasteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox1.Paste();
        }

        private void selectAllToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox1.SelectAll();
        }

        private void fontToolStripMenuItem_Click(object sender, EventArgs e)
        {
            fontDialog1.ShowDialog();

            textBox1.Font = fontDialog1.Font;
        }

        private void fontColourToolStripMenuItem_Click(object sender, EventArgs e)
        {
            colorDialog1.ShowDialog();

            textBox1.ForeColor = colorDialog1.Color;
        }

        private void leftToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox1.TextAlign = HorizontalAlignment.Left;
        }

        private void centerToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox1.TextAlign = HorizontalAlignment.Center;
        }

        private void rightToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox1.TextAlign = HorizontalAlignment.Right;
        }

        private void backgroundColourToolStripMenuItem_Click(object sender, EventArgs e)
        {
            colorDialog1.ShowDialog();

            textBox1.BackColor = colorDialog1.Color;
        }



    }
}



框架初始化后的上述程序.它不接受输入.因此,如果有任何Windows文本文件,请双击以将其打开到我的记事本中,以帮助进行输入.请帮助我


[edit]已添加代码块-OriginalGriff [/edit]



the above program after initialization of frame. It is does not take input. so help this to take input if any windows text file double click to open this file into a my notepad. please help me


[edit]Code block added - OriginalGriff[/edit]

推荐答案


这篇关于如何从C#中的输入读取url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 22:10