Visual Studio Development Bookmark and Share   
 index > Visual C# Express Edition > hi all .. c# assignment anyone can help me ??
 

hi all .. c# assignment anyone can help me ??

hi all i saw your solution and i have an assignment with the same idea but iam alittle confused about it .. may u can help me
this is the assignment
In this assignment you will required to build a sample form which reads its content from a text file. The format of the text file is as following:

Line1: will contain the Text property of the form

Line 2-to the end of the file: Each line will define a Control to be added to the form in the following format

Control Type, Text Property, X axis Location, Y axis Location

For example if the file contains:

Hello World

Text, Welcome, 10, 10

Button, Go, 100, 100

Label, Hi, 100, 200

Button, Click Here, 100, 100

This will show a form with Title “Hello World�with two buttons, one label, and one text box inside it.

Your code must detect any error in the input file and shows an appropriate message. This can be done by using try/catch and giving appropriate message.

flower89  Sunday, October 18, 2009 10:13 PM
did you try out any code for this assignment? If so show us that and post your specific doubts so we can help.

Below are some pointers for an easy way to do it. Try doing it.

  1. Read the first line and assign the text property of the form with that value. Make use of StreamReader to read the file.
  2. split the next line based on comma and iterate through it.
  3. Compare the first element. If its a button, create a new instance of the button class.
  4. assign the second element with the Text Property of the newly created button.
  5. Assign the coordinates with the next value
  6. Add the newly created controls to the Form.Controls collection.

Ganesh Ranganathan
[Please mark the post as answer if it answers your question]
blog.ganeshzone.net
Ganesh Ranganathan - Bangalore, India  Sunday, October 18, 2009 10:43 PM

public partial class Form1 : Form

{

private TextBox textBox1;

public Form1()

{

InitializeComponent();

OpenFileDialog op =

new OpenFileDialog();

op.ShowDialog();

string path = op.FileName;

FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);

StreamReader r = new StreamReader(fs);

this.textBox1 = this.textBox1 = new System.Windows.Forms.TextBox();

textBox1.Text += r.ReadLine();

string n;

while ((r.Peek () >-1))

{

n = r.ReadLine();

}
this is my trial :)

flower89  Sunday, October 18, 2009 10:45 PM
Your ReadLine is correct. Store all the lines in an array first so that the File which is being read is released.

After you haveallthe lines in an array, go through it one by one to do your functionality.

Ganesh Ranganathan
[Please mark the post as answer if it answers your question]
blog.ganeshzone.net
Ganesh Ranganathan - Bangalore, India  Sunday, October 18, 2009 10:54 PM
could u write a sample code to get clear :)
thank u
flower89  Sunday, October 18, 2009 10:56 PM
 string[] _allLines = File.ReadAllLines(path);
            foreach (string _tempString in _allLines)
            {
                //Check if its the first line. Use a counter variable for it.

                //else for all other lines, split the line with comma,
                //and then iterate through the new array and follow the steps
                //in my above post
            }
Try this above code. Follow the steps in my above post.
Ganesh Ranganathan
[Please mark the post as answer if it answers your question]
blog.ganeshzone.net
Ganesh Ranganathan - Bangalore, India  Monday, October 19, 2009 4:45 AM
just want to ask about some thing text property is same as set & get or other ?
flower89  Monday, October 19, 2009 5:23 PM
any help for this assignment i give up
flower89  Monday, October 19, 2009 8:45 PM

Hi,
This code is justto give a rough idea.Will have to modify this a little bit to make it work.

public Form1()
{
InitializeComponent();
OpenFileDialog op =new OpenFileDialog();
op.ShowDialog();
string path = op.FileName;
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
StreamReader r = new StreamReader(fs);
int linecount = 1;
string linevalue;
// Read the text file line by line.
while((linevalue=r.ReadLine()) != null)
{
//first line in text file(linecount=1)
if(linecount==1)
{
Form1.title=linevalue;
}
else
{ //splitting the 2nd,3rd,4th lines from the text file
string[] words=linevalue.Split(',');
if words[0]=="Text"
{
TextBox tb=new TextBox();
tb.Text=words[1];
//will have to convert word[2] & word[3] to integer
tb.Location=New Point(word[2],word[3])
Form1.Controls.Add(tb);
}
if words[0]=="Button"
{
Button btn=new Button();
btn.Text=words[1];
btn.Location=New Point(word[2],word[3])
Form1.Controls.Add(btn);
}
if words[0]=="Label"
{
Label lbl=new Label();
lbl.Text=words[1];
lbl.Location=New Point(word[2],word[3])
Form1.Controls.Add(lbl);
}
}
linecount++;
}
r.Close();
}

[Please mark this post as 'Answer' if it helps]
Praveena.

Praveena.  5 hours 0 minutes ago

You can use google to search for other answers

Custom Search

More Threads

• Doesn't show any effect by registering a visual Studio 2008 C# Express edition's dll by using Windows command Prompt?
• Unable to update the database
• VS2005E and VS2008E
• datagridview eidting columns
• How to deselect a selected Cell in a DataGridView programmatically?
• Retrieving Dataset Table Entries Into Fields and ComboBoxes?
• Extending Syntax Highlighting in Visual C# Express
• send mail
• Line Numbering in Visual Studio
• Charts?