נשלח בתאריך: 29 December 2005 בשעה 05:28 | | IP רשוּם
|
|
|
|
אני אתחלתי לילמוד C#. ונתקעתי בתרגיל הראשון.
אני מנסה לבנות מחשבון פשוט אבל מה שאני לא מצליח לעשות זה להמיר INT ל STRING או לפחות זה מה שהוא כותב לי זה הקוד הבעיה שורה אחרונה למטה(IA+IB=lbl.text) ת ודה לכל מי שמוכן לעזור.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace WindowsApplication1
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class yochai : System.Windows.Forms.Form
{
private System.Windows.Forms.Button btnPlus;
private System.Windows.Forms.Button btnAnswer;
private System.Windows.Forms.Label lbl;
private System.Windows.Forms.Button btnN4;
private System.Windows.Forms.Button btnN5;
private System.Windows.Forms.Button btnN6;
private System.Windows.Forms.Button btnN7;
private System.Windows.Forms.Button btnN8;
private System.Windows.Forms.Button btnN9;
private System.Windows.Forms.Button btnN10;
private System.Windows.Forms.Button btnN11;
private System.Windows.Forms.Button btnN12;
private System.Windows.Forms.Button btnN13;
private int iA,iB;
private string sA,c;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public yochai()
{
//
// 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.btnPlus = new System.Windows.Forms.Button();
this.btnAnswer = new System.Windows.Forms.Button();
this.lbl = new System.Windows.Forms.Label();
this.btnN4 = new System.Windows.Forms.Button();
this.btnN5 = new System.Windows.Forms.Button();
this.btnN6 = new System.Windows.Forms.Button();
this.btnN7 = new System.Windows.Forms.Button();
this.btnN8 = new System.Windows.Forms.Button();
this.btnN9 = new System.Windows.Forms.Button();
this.btnN10 = new System.Windows.Forms.Button();
this.btnN11 = new System.Windows.Forms.Button();
this.btnN12 = new System.Windows.Forms.Button();
this.btnN13 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// btnPlus
//
this.btnPlus.Location = new System.Drawing.Point(8, 224);
this.btnPlus.Name = "btnPlus";
this.btnPlus.Size = new System.Drawing.Size(224, 32);
this.btnPlus.TabIndex = 0;
this.btnPlus.Text = "+";
this.btnPlus.Click += new System.EventHandler(this.btnPlus_Click);
//
// btnAnswer
//
this.btnAnswer.Location = new System.Drawing.Point(136, 184);
this.btnAnswer.Name = "btnAnswer";
this.btnAnswer.Size = new System.Drawing.Size(96, 32);
this.btnAnswer.TabIndex = 1;
this.btnAnswer.Text = "=";
this.btnAnswer.Click += new System.EventHandler(this.btnAnswer_Click);
//
// lbl
//
this.lbl.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
this.lbl.Location = new System.Drawing.Point(24, 8);
this.lbl.Name = "lbl";
this.lbl.Size = new System.Drawing.Size(248, 24);
this.lbl.TabIndex = 5;
//
// btnN4
//
this.btnN4.Location = new System.Drawing.Point(16, 104);
this.btnN4.Name = "btnN4";
this.btnN4.Size = new System.Drawing.Size(48, 32);
this.btnN4.TabIndex = 6;
this.btnN4.Text = "1";
this.btnN4.Click += new System.EventHandler(this.btnN4_Click);
//
// btnN5
//
this.btnN5.Location = new System.Drawing.Point(72, 104);
this.btnN5.Name = "btnN5";
this.btnN5.Size = new System.Drawing.Size(48, 32);
this.btnN5.TabIndex = 7;
this.btnN5.Text = "2";
this.btnN5.Click += new System.EventHandler(this.btnN5_Click);
//
// btnN6
//
this.btnN6.Location = new System.Drawing.Point(128, 104);
this.btnN6.Name = "btnN6";
this.btnN6.Size = new System.Drawing.Size(48, 32);
this.btnN6.TabIndex = 8;
this.btnN6.Text = "3";
this.btnN6.Click += new System.EventHandler(this.btnN6_Click);
//
// btnN7
//
this.btnN7.Location = new System.Drawing.Point(184, 104);
this.btnN7.Name = "btnN7";
this.btnN7.Size = new System.Drawing.Size(48, 32);
this.btnN7.TabIndex = 9;
this.btnN7.Text = "4";
this.btnN7.Click += new System.EventHandler(this.btnN7_Click);
//
// btnN8
//
this.btnN8.Location = new System.Drawing.Point(16, 144);
this.btnN8.Name = "btnN8";
this.btnN8.Size = new System.Drawing.Size(48, 32);
this.btnN8.TabIndex = 10;
this.btnN8.Text = "5";
this.btnN8.Click += new System.EventHandler(this.btnN8_Click);
//
// btnN9
//
this.btnN9.Location = new System.Drawing.Point(72, 144);
this.btnN9.Name = "btnN9";
this.btnN9.Size = new System.Drawing.Size(48, 32);
this.btnN9.TabIndex = 11;
this.btnN9.Text = "6";
this.btnN9.Click += new System.EventHandler(this.btnN9_Click);
//
// btnN10
//
this.btnN10.Location = new System.Drawing.Point(128, 144);
this.btnN10.Name = "btnN10";
this.btnN10.Size = new System.Drawing.Size(48, 32);
this.btnN10.TabIndex = 12;
this.btnN10.Text = "7";
this.btnN10.Click += new System.EventHandler(this.btnN10_Click);
//
// btnN11
//
this.btnN11.Location = new System.Drawing.Point(184, 144);
this.btnN11.Name = "btnN11";
this.btnN11.Size = new System.Drawing.Size(48, 32);
this.btnN11.TabIndex = 13;
this.btnN11.Text = "8";
this.btnN11.Click += new System.EventHandler(this.btnN11_Click);
//
// btnN12
//
this.btnN12.Location = new System.Drawing.Point(16, 184);
this.btnN12.Name = "btnN12";
this.btnN12.Size = new System.Drawing.Size(48, 32);
this.btnN12.TabIndex = 14;
this.btnN12.Text = "9";
this.btnN12.Click += new System.EventHandler(this.btnN12_Click);
//
// btnN13
//
this.btnN13.Location = new System.Drawing.Point(72, 184);
this.btnN13.Name = "btnN13";
this.btnN13.Size = new System.Drawing.Size(48, 32);
this.btnN13.TabIndex = 15;
this.btnN13.Text = "0";
this.btnN13.Click += new System.EventHandler(this.btnN13_Click);
//
// yochai
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.btnN13);
this.Controls.Add(this.btnN12);
this.Controls.Add(this.btnN11);
this.Controls.Add(this.btnN10);
this.Controls.Add(this.btnN9);
this.Controls.Add(this.btnN8);
this.Controls.Add(this.btnN7);
this.Controls.Add(this.btnN6);
this.Controls.Add(this.btnN5);
this.Controls.Add(this.btnN4);
this.Controls.Add(this.lbl);
this.Controls.Add(this.btnAnswer);
this.Controls.Add(this.btnPlus);
this.Name = "yochai";
this.Text = "c#1";
this.Load += new System.EventHandler(this.yochai_Load);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new yochai());
}
private void yochai_Load(object sender, System.EventArgs e)
{
}
private void btnN4_Click(object sender, System.EventArgs e)
{
sA=sA+"1";
lbl.Text=sA;
}
private void btnN5_Click(object sender, System.EventArgs e)
{
sA=sA+"2";
lbl.Text=sA;
}
private void btnN6_Click(object sender, System.EventArgs e)
{
sA=sA+"3";
lbl.Text=sA;
}
private void btnPlus_Click(object sender, System.EventArgs e)
{
iA=Int32.Parse(sA);
lbl.Text=sA;
sA="";
}
private void btnN7_Click(object sender, System.EventArgs e)
{
sA=sA+"4";
lbl.Text=sA;
}
private void btnN8_Click(object sender, System.EventArgs e)
{
sA=sA+"5";
lbl.Text=sA;
}
private void btnN9_Click(object sender, System.EventArgs e)
{
sA=sA+"6";
lbl.Text=sA;
}
private void btnN10_Click(object sender, System.EventArgs e)
{
sA=sA+"7";
lbl.Text=sA;
}
private void btnN11_Click(object sender, System.EventArgs e)
{
sA=sA+"8";
lbl.Text=sA;
}
private void btnN12_Click(object sender, System.EventArgs e)
{
sA=sA+"9";
lbl.Text=sA;
}
private void btnN13_Click(object sender, System.EventArgs e)
{
sA=sA+"0";
lbl.Text=sA;
}
private void btnAnswer_Click(object sender, System.EventArgs e)
{
iB=Int32.Parse(sA);
lbl.Text=iA+iB;(זה הבעיה) הואVS2003 כותב שאי אפשר להמיר INT לSTRING
}
}//class
}//ns
|