Sayı Tahmin Örneği
Sayı Tahmin Örneği
--------------------------------------------------------------------------------
Sayı tahmin örneği profesyonel çalışmlarına örnek teşkil etmesi için sizlerle paylaşıyorum.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace WindowsApplication3
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label5;
private ColorDialog colorDialog1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.colorDialog1 = new System.Windows.Forms.ColorDialog();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.textBox1.Location = new System.Drawing.Point(88 72);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(100 20);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "0";
this.textBox1.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
// label1
//
this.label1.Font = new System.Drawing.Font("Comic Sans MS" 14F System.Drawing.FontStyle.Regular System.Drawing.GraphicsUnit.Point ((byte)(162)));
this.label1.ForeColor = System.Drawing.Color.Brown;
this.label1.Location = new System.Drawing.Point(48 24);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(184 23);
this.label1.TabIndex = 1;
this.label1.Text = "Sayı Tahmin Oyunu";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// button1
//
this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.button1.Location = new System.Drawing.Point(104 120);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75 23);
this.button1.TabIndex = 2;
this.button1.Text = "Kontrol Et";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// label2
//
this.label2.Location = new System.Drawing.Point(48 165);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(56 16);
this.label2.TabIndex = 3;
this.label2.Text = "Durum :";
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// label3
//
this.label3.Location = new System.Drawing.Point(43 186);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(69 16);
this.label3.TabIndex = 4;
this.label3.Text = "Tahmin :";
this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// label4
//
this.label4.Location = new System.Drawing.Point(112 189);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(96 16);
this.label4.TabIndex = 6;
this.label4.Text = "?";
this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// label5
//
this.label5.Location = new System.Drawing.Point(112 165);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(96 16);
this.label5.TabIndex = 5;
this.label5.Text = "?";
this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5 13);
this.BackColor = System.Drawing.Color.LightSteelBlue;
this.ClientSize = new System.Drawing.Size(292 266);
this.Controls.Add(this.label4);
this.Controls.Add(this.label5);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.button1);
this.Controls.Add(this.label1);
this.Controls.Add(this.textBox1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
int sayi_ri;
private void button1_Click(object sender System.EventArgs e)
{
int sayi_t;
i=i+1;
sayi_t=Convert.ToInt16(textBox1.Text);
if (sayi_t>sayi_r)
{
label5.Text="Sayıyı Küçült";
label4.Text=Convert.ToString(i);
}
else if (sayi_t<sayi_r)
{
label5.Text="Sayıyı Büyült";
label4.Text=Convert.ToString(i);
}
else if (sayi_t==sayi_r)
{
label5.Text="Tebrikler";
label4.Text=Convert.ToString(i);
}
}
private void Form1_Load(object sender System.EventArgs e)
{
Random r=new Random();
sayi_r=r.Next(100);
i=0;
}
}
}
__________________
بِسْــــــــــــــــــــــمِ اﷲِارَّحْمَنِ ارَّحِيم
-------------------------------------------------
Bu Soysuzlar Bu Vatansızlar Sarsada Yurdumu Ben Yaratan'dan Alırım Asil Kanı ve Gücü. -------------------------------------------------
|