„Mérési adatgyűjtés és feldolgozás példák 1” változatai közötti eltérés

A Fizipedia wikiből
("Hello World!" program)
38. sor: 38. sor:
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
== Fájlkezelés ==
 +
 +
=== Fájl mentése ===
 +
[[Fájl:CSharpSaver.png|none]]
 +
 +
A Form tartalma:
 +
* '''Button''' writeButton
 +
* '''SaveFileDialog'''saveFileDialog1
 +
 +
<syntaxhighlight lang=csharp>
 +
using System;
 +
using System.Collections.Generic;
 +
using System.ComponentModel;
 +
using System.Data;
 +
using System.Drawing;
 +
using System.Text;
 +
using System.Windows.Forms;
 +
using System.IO;                //hozzaadni!
 +
 +
namespace proba
 +
{
 +
    public partial class Form1 : Form
 +
    {
 +
        StreamWriter fileWriter; //globalis, hogy tobb fuggvenyben is hasznalhato legyen
 +
        public Form1()
 +
        {
 +
            InitializeComponent();
 +
        }
 +
        //a kattintashoz tartozo esemeny
 +
        private void writeButton_Click(object sender, EventArgs e)
 +
        {
 +
            //Mentes parbeszedablak megnyitasa
 +
            saveFileDialog1.ShowDialog();
 +
            if (saveFileDialog1.FileName != "")
 +
            {
 +
                //file megnyitasa a megadott eleresi uttal, ha az nem ures string
 +
                fileWriter = new StreamWriter(saveFileDialog1.FileName);
 +
                string temp;
 +
                temp="Hello ";
 +
                fileWriter.Write(pelda);  //szoveges valtozo beirasa
 +
                fileWriter.WriteLine("World!");  //szoveg es ujsor karakter beirasa
 +
                fileWriter.WriteLine(temp); //meg egyszer
 +
                fileWriter.Close();  //Fontos: file bezarasa!
 +
            }
 +
        }
 +
       
 +
    }
 +
}
 +
</syntaxhighlight>
 +
 +
Az elmentett fájl tartalma:
 +
 +
Hello World!
 +
 +
Hello

A lap 2011. március 2., 01:20-kori változata

"Hello World!" program

Helloworld.png

A Form tartalma:

  • Button startButton

Kód:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
 
namespace helloworld
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        //a Form elindulasokor lefuto esemeny
        private void Form1_Load(object sender, EventArgs e)
        {
            startButton.Text = "Start!"; //Startbutton felirata
        }
        //a gomb lenyomasahoz tartozo esemeny
        private void StartButton_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Hello World!"); //Felugro ablak
        }
 
    }
}

Fájlkezelés

Fájl mentése

CSharpSaver.png

A Form tartalma:

  • Button writeButton
  • SaveFileDialogsaveFileDialog1
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;                //hozzaadni!
 
namespace proba
{
    public partial class Form1 : Form
    {
        StreamWriter fileWriter; //globalis, hogy tobb fuggvenyben is hasznalhato legyen
        public Form1()
        {
            InitializeComponent();
        }
        //a kattintashoz tartozo esemeny
        private void writeButton_Click(object sender, EventArgs e)
        {
            //Mentes parbeszedablak megnyitasa
            saveFileDialog1.ShowDialog();
            if (saveFileDialog1.FileName != "")
            {
                //file megnyitasa a megadott eleresi uttal, ha az nem ures string
                fileWriter = new StreamWriter(saveFileDialog1.FileName);
                string temp;
                temp="Hello ";
                fileWriter.Write(pelda);   //szoveges valtozo beirasa 
                fileWriter.WriteLine("World!");  //szoveg es ujsor karakter beirasa
                fileWriter.WriteLine(temp); //meg egyszer
                fileWriter.Close();   //Fontos: file bezarasa!
            }
        }
 
    }
}

Az elmentett fájl tartalma:

Hello World!

Hello