Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Table Layout Panel - Drag and Drop effects for a child control

Posted on 2010-01-07
5
Medium Priority
?
2,340 Views
Last Modified: 2012-05-08
I am working with the Table Layout Panel in Visual C#.net. I have a panel control which is inside one of the cells inside the table layout panel. My intention is to perform drag and drop of this panel control from one cell to other. I have achieved the drag and drop functionality.  However instead of having the traditional drag and drop effects including copy, move etc. I want the control to be visible while dragging rather than one of the effects. Really appreciate if any of you can help.

Thanking in advance,

CPM
0
Comment
Question by:virtualmenon
  • 3
  • 2
5 Comments
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 26207247
Couldn't you use the code I provided before?
http://www.experts-exchange.com/Programming/Languages/C_Sharp/Q_24978681.html

...and in the DragOver() event just move the control so it jumps around DURING the drag?
0
 

Author Comment

by:virtualmenon
ID: 26207314
Hello Idle mind,

I had tried that but one problem i am facing is that my whole table layout panel flickers till the time I drop the control. So i thought may be i need to do something else. Do you have any idea what may be causing this.
Once again thanks a lot for your help.

Thanks,

CPM
0
 

Author Comment

by:virtualmenon
ID: 26280581
This is what am doing in the drag_over event of the table layout panel.


        private void tp3_DragOver(object sender, DragEventArgs e)
        {
            Point p2 = tp3.PointToClient(new Point(x, y));
            Control c = tp3.GetChildAtPoint(p2);
           
            Point w = new Point();

            w.X = c.Location.X + (e.X - x);
            w.Y = c.Location.Y + (e.Y - y);

            c.Location = w;
           
        }

When i execute the code table layoutpanel seems to be getting into some loop, giving the flickering effect.

Thanks,

CPM
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 26280830
Starting with my original example cited above, I added this DragOver() event:

        void tableLayoutPanel1_DragOver(object sender, DragEventArgs e)
        {
            Point pt = tableLayoutPanel1.PointToClient(new Point(e.X, e.Y));
            foreach (KeyValuePair<Point, Rectangle> kvp in CellRects)
            {
                if (kvp.Value.Contains(pt))
                {
                    PictureBox pb = (PictureBox)e.Data.GetData("MyData");
                    TableLayoutPanelCellPosition pos = tableLayoutPanel1.GetCellPosition(pb);
                    if (pos.Column != kvp.Key.X || pos.Row != kvp.Key.Y)
                    {
                        Console.WriteLine("New Cell Position");
                        tableLayoutPanel1.SetCellPosition(pb, new TableLayoutPanelCellPosition(kvp.Key.X, kvp.Key.Y));
                    }
                    break;
                }
            }
        }

It does flicker whenever the PictureBox is moved...but not too bad.
0
 

Author Comment

by:virtualmenon
ID: 26282148
Thanks mate.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question