„Sznikák példakódok” változatai közötti eltérés
Ugrás a navigációhoz
Ugrás a kereséshez
(rajzolás) |
(DrawString) |
||
155. sor: | 155. sor: | ||
using (brush1 = new SolidBrush(ConsoleColor.FromArgb(grey, grey, grey))) | using (brush1 = new SolidBrush(ConsoleColor.FromArgb(grey, grey, grey))) | ||
{ | { | ||
− | e.Graphics.FillRectrangle(brush1, 10, 20, 20 | + | e.Graphics.FillRectrangle(brush1, 10, 20, 10+10, 20+10); |
} | } | ||
} | } | ||
161. sor: | 161. sor: | ||
− | + | {{Infobox | |
− | + | | cím = String rajzolás | |
+ | | háttérszín = #C0ffee | ||
+ | | keretszín = black | ||
+ | | tartalom = | ||
+ | Írjon olyan C# nyelvű alkalmazásrészletet, ami a (20,20) kokrdinátában megjeleníti, hogy a legutóbbi egérkattintás óta hány másodperc telt el! A megjelenítés GDI-re épüljön. | ||
+ | {{Infobox-táblázat| | ||
+ | {{Infobox-táblázatsor|A kód nyelve|C#}} | ||
+ | }} | ||
+ | }} | ||
+ | DateTime lastClick; | ||
+ | String strDeltaTime; | ||
+ | |||
+ | private void Form1_Load(object sender, EventArgs e) | ||
+ | { | ||
+ | lastClick = DateTime.Now; | ||
+ | strDeltaTime = "0"; | ||
+ | } | ||
+ | |||
+ | private void Form1_MouseClick(object sender, MouseEventArgs e) | ||
+ | { | ||
+ | TimeSpan deltaTime = DateTime.Now.Subtract(lastClick); | ||
+ | lastClick = DateTime.Now; | ||
+ | strDeltaTime = deltaTime.Seconds.ToString(); | ||
+ | Invalidate(); // érvényteleníteni kell az ablak területet, hogy az új érték látszódjon | ||
+ | } | ||
+ | |||
+ | protected override void OnPaint(PaintEventArgs e) { | ||
+ | e.Graphics.DrawString(strDeltaTime, this.Font, new SolidBrush(Color.Black), 20, 20); | ||
+ | base.OnPaint(e); | ||
+ | } | ||
[[Kategória:Infoalap]] | [[Kategória:Infoalap]] |
A lap 2013. május 28., 11:46-kori változata
Hiba a bélyegkép létrehozásakor: Nem lehet a bélyegképet a célhelyre menteni
Az oldal épp egy nagyobb változáson megy keresztül, kérlek nézz vissza kicsit később Hiba a bélyegkép létrehozásakor: Nem lehet a bélyegképet a célhelyre menteni
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()); } }
public partial class Form1 : Form { private Brush brush1; private int grey = 200; public Form1() { InitializeComponent(); } protected override void OnKeyDown(KeyEventArgs e) { base.OnKeyDown(e); if(e.KeyCode == Keys.R) { if(grey == 0) // ha elértük a színtartomány végét grey = 200; grey -= 10; Invalidate(); } } protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); using (brush1 = new SolidBrush(ConsoleColor.FromArgb(grey, grey, grey))) { e.Graphics.FillRectrangle(brush1, 10, 20, 10+10, 20+10); } } }
DateTime lastClick; String strDeltaTime; private void Form1_Load(object sender, EventArgs e) { lastClick = DateTime.Now; strDeltaTime = "0"; } private void Form1_MouseClick(object sender, MouseEventArgs e) { TimeSpan deltaTime = DateTime.Now.Subtract(lastClick); lastClick = DateTime.Now; strDeltaTime = deltaTime.Seconds.ToString(); Invalidate(); // érvényteleníteni kell az ablak területet, hogy az új érték látszódjon } protected override void OnPaint(PaintEventArgs e) { e.Graphics.DrawString(strDeltaTime, this.Font, new SolidBrush(Color.Black), 20, 20); base.OnPaint(e); }