„Sznikák példakódok” változatai közötti eltérés
A VIK Wikiből
kapcsolatalapú hozzáférés |
Eseménykezelés |
||
| 39. sor: | 39. sor: | ||
} | } | ||
} | } | ||
{{Infobox | {{Infobox | ||
| 86. sor: | 87. sor: | ||
{{Infobox | |||
| cím = Eseménykezelés | |||
| háttérszín = #C0ffee | |||
| keretszín = black | |||
| tartalom = | |||
Írj egy Form alapú programot, ami MessageBox-ban megjeleníti a leütött billentyűt! | |||
{{Infobox-táblázat| | |||
{{Infobox-táblázatsor|A kód nyelve|C#}} | |||
}} | |||
}} | |||
public partial class MainForm : Form | |||
{ | |||
public MainForm() | |||
{ | |||
InitializeComponent(); | |||
this.KeyDown += new KeyEventHandler(this.MainForm_KeyDown); | |||
} | |||
protected override void OnKeyDown(KeyEventArgs e) | |||
{ | |||
// Meghívjuk az eredeti függvényt is | |||
base.OnKeyDown(e); | |||
MessageBox.Show("A billentyű (virt. fv.): " + e.KeyCode.ToString()); | |||
} | |||
private void MainForm_KeyDown(object sender, KeyEventArgs e) | |||
{ | |||
MessageBox.Show("A billentyű (eseménykez.): " + e.KeyCode.ToString()); | |||
} | |||
} | |||
A lap 2013. május 28., 12:34-kori változata
class ThreadTestClass
{
public static void Main(string[] args)
{
Thread t = null;
if (args.Length == 0)
{
t = new Thread(new ThreadStart(ThreadMethod1));
t.Start();
}
else
{
t = new Thread(new ParameterizedThreadStart(ThreadMethod2));
t.Start(args[0]);
}
}
public static void ThreadMethod1()
{
Console.WriteLine("Thread without parameter.");
}
public static void ThreadMethod2(object param)
{
Console.WriteLine("Thread with parameter: {0}", param.ToString());
}
}
SqlConnection conn = null;
try
{
// Kapcsolódás azadatbázishoz
conn = new SqlConnection(@"Data Source=LAPTOP\SQLEXPRESS;InitialCatalog=Northwind;Integrated Security=True");
// A kapcsolat megnyitása
conn.Open();
// Az adatbázis parancs létrehozása
SqlCommand command = new SqlCommand("SELECT ShipperID, CompanyName, Phone FROM Shippers");
// Adatbázis kapcsolat megadása
command.Connection = conn;
Console.WriteLine("{0,0}{1,15}{2,15}", "ShipperID", "CompanyName", "Phone");
Console.WriteLine("-----------------------------------------------------------------");
// Az adatok lekérdezése és kiiratása
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
Console.WriteLine("{0,4}{1,20}{2,20}",
reader["ShipperID"].ToString(),
reader["CompanyName"].ToString(),
reader["Phone"].ToString());
}
}
catch (Exception ex)
{
// Kivétel szövegének kiiratása
Console.WriteLine(ex.Message);
}
finally
{
// Az adatbázis kapcsolat lezárása, ha meg lett nyitva
if((conn!=null)&&(conn.State==System.Data.ConnectionState.Open))
conn.Close();
}
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
this.KeyDown += new KeyEventHandler(this.MainForm_KeyDown);
}
protected override void OnKeyDown(KeyEventArgs e)
{
// Meghívjuk az eredeti függvényt is
base.OnKeyDown(e);
MessageBox.Show("A billentyű (virt. fv.): " + e.KeyCode.ToString());
}
private void MainForm_KeyDown(object sender, KeyEventArgs e)
{
MessageBox.Show("A billentyű (eseménykez.): " + e.KeyCode.ToString());
}
}
