Question

In: Computer Science

Create a new C# project in Visual Studio. The purpose of this application is to allow...

Create a new C# project in Visual Studio. The purpose of this application is to allow the user to open a data file of their choice and your program will retrieve the contents and display them in a ListBox on your Form. Your Form will need an ‘Open’ Button to begin the process, as well as an OpenFileDialog control to allow the user to pick a file of their choice. The OpenFileDialog control should start the user in their ‘C:\’ drive, and should be pre-filtered to only show text files (*.txt). You will also need a ListBox to display the file contents, and the usual Reset and Close Buttons. Be sure to test the application with your own text file. The file you generated in Assessment might be a good choice, but realize I will check it with my own file, which might hold more than just a series of numbers. Since you don’t know the contents of the file, or how many lines there are, make sure that your ListBox is wide enough to handle content as wide as 150 characters per line without horizontal scrolling, and that your file-reading code has the appropriate data validation to determine if the user picked a file or not, and to read *all* the contents of the chosen file, no matter how many lines there are, without going over the end of the file.

Solutions

Expert Solution

//C# code

using System;
using System.IO;
using System.Windows.Forms;

namespace read_filein_listbox
{
public partial class Form1 : Form
{
string fileName = "";
public Form1()
{
InitializeComponent();

}

private void btnOpen_Click(object sender, EventArgs e)
{
//start the user in their ‘C:\’ drive,
openFileDialog1.InitialDirectory = @"C:\";
openFileDialog1.RestoreDirectory = true;
openFileDialog1.Title = "Browse Files";
openFileDialog1.DefaultExt = ".txt";
//should be pre - filtered to only show text files(*.txt).
openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
openFileDialog1.ShowDialog();
fileName = openFileDialog1.FileName;
try
{
StreamReader reader = new StreamReader(fileName);
while(!reader.EndOfStream)
{
listBox1.Items.Add(reader.ReadLine());
}
reader.Close();
}
catch(FileNotFoundException ex)
{
Console.WriteLine("File not found.");
}
}

private void btnClose_Click(object sender, EventArgs e)
{
this.Close();
}

private void btnReset_Click(object sender, EventArgs e)
{
listBox1.Items.Clear();
fileName = "";
}
}
}

//Form design

//Output

//If you need any help regarding this solution ....... please leave a comment ...... thanks


Related Solutions

Create a new “Area” project. Create a new Visual Studio Project and call it “Area”. This...
Create a new “Area” project. Create a new Visual Studio Project and call it “Area”. This project will be used to calculate the area of certain figures, like circles, squares and rectangles. So add a title to the Form. The Form Title should say “Area”. Also add 3 labels, 3 Buttons, 3 Textboxes and 3 RadioButtons. The 3 Buttons should be near the bottom of the Form and say “Calc Area”, “Clear” and “Exit”. Make sure to give all your...
Using Visual Studio in C#; create a grading application for a class of ten students. The...
Using Visual Studio in C#; create a grading application for a class of ten students. The application should request the names of the students in the class. Students take three exams worth 100 points each in the class. The application should receive the grades for each student and calculate the student’s average exam grade. According to the average, the application should display the student’s name and the letter grade for the class using the grading scheme below. Grading Scheme: •...
ONLY USE VISUAL STUDIO (NO JAVA CODING) VISUAL STUDIO -> C# -> CONSOLE APPLICATION In this...
ONLY USE VISUAL STUDIO (NO JAVA CODING) VISUAL STUDIO -> C# -> CONSOLE APPLICATION In this part of the assignment, you are required to create a C# Console Application project. The project name should be A3<FirstName><LastName>P2. For example, a student with first name John and Last name Smith would name the project A1JohnSmithP2. Write a C# (console) program to calculate the number of shipping labels that can be printed on a sheet of paper. This program will use a menu...
Create a C++ project in visual studio. You can use the C++ project that I uploaded...
Create a C++ project in visual studio. You can use the C++ project that I uploaded to complete this project. 1. Write a function that will accept two integer matrices A and B by reference parameters, and two integers i and j as a value parameter. The function will return an integer m, which is the (i,j)-th coefficient of matrix denoted by A*B (multiplication of A and B). For example, if M = A*B, the function will return m, which...
Create a C# .NET Core Console project in Visual Studio. (This is the same kind of...
Create a C# .NET Core Console project in Visual Studio. (This is the same kind of project we have been doing all semester.) Do all of the following in the Program class. You do not need to add any other classes to this project. 2. If it exists, remove the Console.WriteLine(“Hello World!”); line that Visual Studio created in the Program class. 3. At the very top of the Program.cs page you should see using System; On the empty line below...
Create a new website using C# & ASP.Net in Visual Studio: 1. Create a web page...
Create a new website using C# & ASP.Net in Visual Studio: 1. Create a web page to access a database and display the data from a table by providing an SQL statement. Create the page with these requirements:     create label, textbox and button     the textbox will capture the SQL statement     the button will process the statement and display the results 2. Add necessary data access pages to your project. 3. Display the data in Gridview
Create a Visual Studio console project (c++) containing a main() program that declares a const int...
Create a Visual Studio console project (c++) containing a main() program that declares a const int NUM_VALUES denoting the array size. Then declare an int array with NUM_VALUES entries. Using a for loop, prompt for the values that are stored in the array as follows: "Enter NUM_VALUES integers separated by blanks:" , where NUM_VALUES is replaced with the array size. Then use another for loop to print the array entries in reverse order separated by blanks on a single line...
Instructions (No array) (c++) (visual studio) 1. Create a project called Project3B 2. Create 3 String...
Instructions (No array) (c++) (visual studio) 1. Create a project called Project3B 2. Create 3 String variables called name1, name2, name3 3. Create 9 double variables called test1_1, test1_2, test1_3, test2_1, test2_2, test2_3, test3_1, test3_2, test3_3 4. Create 3 double variables called average1, average2, average3 To calculate the average score = (test1 + test2 + test3) / 3.0 5. Run the program with the following data using cin name1 = “Tom”, name2 = “Mary”, name3 = “Ali” test1_1 = 81.4,...
Visual Studio C# Create an application illustrating the following: Class definition Encapsulation Constructor Instantiation Inheritance Suggestions:...
Visual Studio C# Create an application illustrating the following: Class definition Encapsulation Constructor Instantiation Inheritance Suggestions: Simulation Calculation Interface apps
Create a new Visual Studio console project named assignment042, and translate the algorithm you developed in...
Create a new Visual Studio console project named assignment042, and translate the algorithm you developed in Assignment 04.1 to C++ code inside the main() function. Your program should prompt for a single 9-digit routing number without spaces between digits as follows: Enter a 9-digit routing number without any spaces: The program should output one of: Routing number is valid Routing number is invalid A C++ loop and integer array could be used to extract the routing number's 9 digits. However...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT