Saturday 10 May 2014

Open File Text into TextBox and Rich TextBox in Window application


                                                                                                                                       Previous...
                                                                                                                                           Next...

Here i will explain How to use Open File Text into TextBox and Rich TextBox in Window application.

Step(1) : Form
Drag and down a button and a rich Text box from Tool Box.
Step(2) : Code
Double click on "Open File " button and write this code. Before this we have to add 2 namespace.
using System.Text;
using System.IO;

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

using System.Text;
using System.IO;

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

private void Button1_click(object sender, EventArgs e)
{
Stream mystream;
OpenFileDialog openfile = new OpenFileDialog ();

if(openfile .ShowDialog() ==System.Window.Forms.DialogResult.OK)
{
if((mystream = openfile .OpenFile() ) ! = null)
string strfilename = openfile .FileName;

String filetext = File.ReadAllText(strfilename);
richTextBox1.text  = filetext;
}}
}
Step(3) :Code
Run your application and click on "OpenFile" button and select a file.

                                                                                                                                       Previous...
                                                                                                                                           Next...

No comments:

Post a Comment

C# program Selection Sorting

Selection sort is a straightforward sorting algorithm. This algorithm search for the smallest number in the elements array and then swap i...