如何节省肯定一个TableLayoutPanel的新位置,拖放在后面板? [英] How can I save definitely the new location of a TableLayoutPanel after a drag and drop in a panel?

查看:592
本文介绍了如何节省肯定一个TableLayoutPanel的新位置,拖放在后面板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想一个拖放使用的WinForms在面板一个TableLayoutPanel / C#中,TableLayoutPanel中的拖放成功的作品,但我怎么能保存使用一个按钮动作TableLayoutPanel中的新位置?任何解决办法吗?

 私人无效Registration_Load(对象发件人,EventArgs的)
{
     panel2.AllowDrop = TRUE;
     tableLayoutPanel1.AllowDrop = TRUE;
     panel2.DragEnter + = panel2_DragEnter;
     panel2.DragDrop + = panel2_DragDrop;
     tableLayoutPanel1.MouseDown + = tableLayoutPanel1_MouseDown;
}

私人无效panel2_DragEnter(对象发件人,DragEventArgs E)
{
    如果(e.Data.GetData present(typeof运算(TableLayoutPanel中)))e.Effect = DragDropEffects.Move;

}

私人无效panel2_DragDrop(对象发件人,DragEventArgs E)
{
     VAR TLP =(TableLayoutPanel中)e.Data.GetData(typeof运算(TableLayoutPanel中));
    tlp.Location = panel2.PointToClient(新点(例如,EY));
    tlp.Parent =是Panel2;
    tlp.BringToFront();
}
私人无效tableLayoutPanel1_MouseDown(对象发件人,发送MouseEventArgs E)
{
     tableLayoutPanel1.DoDragDrop(tableLayoutPanel1,DragDropEffects.Move);
}
 

解决方案

我找到一个解决我的问题。这个想法是保存的物品的位置在数据库(Location.X A,D Location.Y)然后在负载页面我们固定与保存在数据库中的位置被丢弃的物品的位置。

I'm trying a drag and drop for a tablelayoutpanel in a panel using winforms/c#, the drag and drop of the tablelayoutpanel works successfully but how can I save the new location of the tablelayoutpanel using a button action ? Any solution please ?

private void Registration_Load(object sender, EventArgs e)
{   
     panel2.AllowDrop = true;
     tableLayoutPanel1.AllowDrop = true;
     panel2.DragEnter += panel2_DragEnter;   
     panel2.DragDrop += panel2_DragDrop;
     tableLayoutPanel1.MouseDown += tableLayoutPanel1_MouseDown;
}   

private void panel2_DragEnter(object sender, DragEventArgs e)
{
    if (e.Data.GetDataPresent(typeof(TableLayoutPanel))) e.Effect = DragDropEffects.Move;

}

private void panel2_DragDrop(object sender, DragEventArgs e)
{
     var tlp = (TableLayoutPanel)e.Data.GetData(typeof(TableLayoutPanel));
    tlp.Location = panel2.PointToClient(new Point(e.X, e.Y));
    tlp.Parent = panel2;
    tlp.BringToFront();             
}
private void tableLayoutPanel1_MouseDown(object sender, MouseEventArgs e)
{
     tableLayoutPanel1.DoDragDrop(tableLayoutPanel1, DragDropEffects.Move);
}

解决方案

i find a solution to my problem. the idea is to save the location of the items in the database (Location.X a,d Location.Y) then in the load page we fix the location of the dropped item with the location saved in the database.

这篇关于如何节省肯定一个TableLayoutPanel的新位置,拖放在后面板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆