Windows Develop Bookmark and Share   
 index > Windows Forms General > how to move control at runtime
 

how to move control at runtime

Hi. It seems this question was raised several times on this forum. But my question is a little bit different. I have a form and buttons which are added to it dynamically. I want to be able to move them at runtime. I have 2 options:

1. drag and drop
2. move using another controls such as arrow buttons or numeric textboxes specifying coordinates.

I couldn't make it using first method since buttons are created at runtime. I'm trying to use 2nd method. So my question is how to make a button keep moving while mouse button or keyboard key is kept pressed. I know that I must use mousedown or keydown events respectively but I cannot make them move while mousebutton/key is pressed.

Thank you in advance
Emil
Emil
emilh  Monday, October 05, 2009 11:43 AM
Hi,
I hope it will help you little
 protected override bool ProcessDialogKey(Keys keyData)
        {
            if(keyData.Equals(Keys.Right))
            {
                button1.Location = new Point(button1.Location.X + 100, button1.Location.Y);        
                
            }
            return base.ProcessDialogKey(keyData);
        }

Best Regards, C.Gnanadurai ----------------------- Please mark the post as answer if it is helpfull to you
  • Marked As Answer byemilh Tuesday, October 06, 2009 5:26 AM
  •  
Gnanadurai  Monday, October 05, 2009 12:35 PM
Tamer Oz  Monday, October 05, 2009 12:16 PM
Hi,
I hope it will help you little
 protected override bool ProcessDialogKey(Keys keyData)
        {
            if(keyData.Equals(Keys.Right))
            {
                button1.Location = new Point(button1.Location.X + 100, button1.Location.Y);        
                
            }
            return base.ProcessDialogKey(keyData);
        }

Best Regards, C.Gnanadurai ----------------------- Please mark the post as answer if it is helpfull to you
  • Marked As Answer byemilh Tuesday, October 06, 2009 5:26 AM
  •  
Gnanadurai  Monday, October 05, 2009 12:35 PM
Thanks, it worked! It seems this method is not for mouse buttons. Is there such equivalents for mouse?

Emil
emilh  Tuesday, October 06, 2009 5:27 AM

You can use google to search for other answers

Custom Search

More Threads

• Protecting a form document - any help would be great
• Custom DataGridView class
• regarding password protection
• TreeView Scroll Issue
• Differences between mshtml.HTMLDocument and System.Windows.Forms.HTMLDocument
• Change Database Location at runtime?
• Crystal Report using Dataset
• Editing Inherited Properties in the Propertygrid
• Resources(Strings)
• How do I set LVGS_COLLAPSIBLE to the groups of ListView