PDA

View Full Version : سوال: چگونگی drag and drop کنترل ها



Hkarimi
جمعه 09 فروردین 1392, 19:37 عصر
سلام.

بذارید از اول کار همه چیزو روشن کنم که سوالم مبهم نباشه.
فرض کنید یه برنامه داریم که سوالای 4 گزینه ای رو از بانک میگیره و نمایش میده و کاربر که گزینه رو انتخاب میکنه بهش میگه جواب درست رو انتخاب کرده یا غلط. توی بانک سوال و گزینه ها و شماره گزینه صحیح ذخیره شده. این از این.

حالا فرض کنید که سوالا مثلاً جای خالی هستن که کاربر باید گزینه درست رو بگیره و داخل جای خالی بندازه. در صورتی که جواب انتخابی درست بود OK و در صورتی که غلط بود دمار از روزگارش در بیاره.

این یه نمونه...

نمونه بعدی اینه که سوال جوری مطرح میشه که کاربر باید سوال و پاسخش رو به هم وصل کنه. مثلاً یه سمت فرم اسم استان ها اومده و سمت دیگه اسم مرکز اون استان ها اومده. ناگفته نماند که این اسامی همگی از بانک گرفته شدن. حالا کاربر میتونه اینا رو به هم وصل کنه.

کسی هست که گره از کار یه مسلمون باز کنه که اگه باز کنه سر نماز دعاش میکنم.

Hkarimi
شنبه 10 فروردین 1392, 16:44 عصر
سلام.
هیچکس هیچ ایده ای نداره؟ اگه روش خاصی به ذهنتون میرسه ممنون میشم راهنمایی بفرمایید.

alexmcse
شنبه 10 فروردین 1392, 20:10 عصر
وقتی این کد رو اجرا کردی مثلا یک فایا عکس به صورت درگ و دراپ روی فرم بر نامه بینداز نتیجه را میبینی
private Image picture;
private Point pictureLocation;

public Form1()
{
// Enable drag-and-drop operations and
// add handlers for DragEnter and DragDrop.
this.AllowDrop = true;
this.DragDrop += new DragEventHandler(this.Form1_DragDrop);
this.DragEnter += new DragEventHandler(this.Form1_DragEnter);
}

protected override void OnPaint(PaintEventArgs e)
{
// If there is an image and it has a location,
// paint it when the Form is repainted.
base.OnPaint(e);
if(this.picture != null && this.pictureLocation != Point.Empty)
{
e.Graphics.DrawImage(this.picture, this.pictureLocation);
}
}

private void Form1_DragDrop(object sender, DragEventArgs e)
{
// Handle FileDrop data.
if(e.Data.GetDataPresent(DataFormats.FileDrop) )
{
// Assign the file names to a string array, in
// case the user has selected multiple files.
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
try
{
// Assign the first image to the picture variable.
this.picture = Image.FromFile(files[0]);
// Set the picture location equal to the drop point.
this.pictureLocation = this.PointToClient(new Point(e.X, e.Y) );
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
}

// Handle Bitmap data.
if(e.Data.GetDataPresent(DataFormats.Bitmap) )
{
try
{
// Create an Image and assign it to the picture variable.
this.picture = (Image)e.Data.GetData(DataFormats.Bitmap);
// Set the picture location equal to the drop point.
this.pictureLocation = this.PointToClient(new Point(e.X, e.Y) );
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
}
// Force the form to be redrawn with the image.
this.Invalidate();
}

private void Form1_DragEnter(object sender, DragEventArgs e)
{
// If the data is a file or a bitmap, display the copy cursor.
if (e.Data.GetDataPresent(DataFormats.Bitmap) ||
e.Data.GetDataPresent(DataFormats.FileDrop) )
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}

Hkarimi
شنبه 10 فروردین 1392, 20:56 عصر
سلام.
دستت طلا بابت پاسخ. شرمنده کردی.

من دوباره مختصراً سوالمو مطرح میکنم. یه سری سوالا بودن که قدیما تو درس زبان انگلیسی یا جغرافی و ... بهمون میدادن که 2 تا ستون داشت و میگفت که گزینه های ستون اول رو به گزینه های ستون دوم وصل کنید. یادتونه؟ مثلاً چنتا کلمه انگلیسی میداد و میگفت که اینا رو به مترادفشون تو ستون دوم با خط وصل کنید.

حالا من میخوام یه همچین چیزی رو پیاده سازی کنم. توسط چیزی که شما فرمودید چطور میتونم این کارو انجام بدم؟

این یکی از سوالاییه که تو پست اول پرسیدم.