PDA

View Full Version : مبتدی: چاپ مقدار متغیر با هر بار کلیک روی PictuteBox



saeedizade
جمعه 28 فروردین 1394, 13:29 عصر
سلام
می خواهم با کلیک بر روی عکس یک واحد به x اضافه شود و در لیبل چاپ شود ولی این کارو نمیکنه چرا




namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
int x = 0;

private void img1_Click(object sender, EventArgs e)
{
Random ran = new Random();
img1.Left = ran.Next(0,536);
img1.Top= ran.Next(0, 330);
x += 1;
}
public Form1()
{
InitializeComponent();
l1.Text = x;
}


}
}

محمد آشتیانی
جمعه 28 فروردین 1394, 14:37 عصر
سلام


namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
int x = 0;

private void img1_Click(object sender, EventArgs e)
{
var ran = new Random();
img1.Location = new Point(ran.Next(0, 536), ran.Next(0, 330));
x++;
l1.Text = x.ToString();
}
}
}


موفق باشید.

saeedizade
جمعه 04 اردیبهشت 1394, 15:46 عصر
مرسی مشکل l1.Text = x.ToString(); بود