Windows Develop Bookmark and Share   
 index > Windows Forms Designer > Change Location at design time problem
 

Change Location at design time problem

Hi,

I am implementing a windows form designer that is based upon the designer sample from microsoft (http://support.microsoft.com/?id=813808). The problem that I have is that i would like to change the size and location of a certain control when I drop it on the form.

In the IContainer.Add method of the DesignerHost I am able to change the size of the control that is to be added but I am unable to change the location of it, e.g. set it to the top. I change the properties like this:

if(component is Panel)
{
(component as Panel).Size = new Size(10, 10);
(component as Panel).Locaton = new Point(8, 8);
}

Does anybody know why I am able to change the size but not the location of the control?

cheers, 

gunnar
MigrationUser 1  Thursday, June 16, 2005 10:26 PM
I have same problem? Even I don't know how to move the control. Or how to adjust the location of control. Please tell me how did you do it?
 Regards
MigrationUser 1  Saturday, June 18, 2005 1:22 AM
One thing that I forgot to mention is that I am able to change the location through the propertygrid. 

What I am trying to do is to mimic that functionality.

Any ideas?

cheers, 

gunnar
MigrationUser 1  Monday, June 20, 2005 12:15 PM
this goes deeper into the fact that it plans to draw it where you dropped it.

It's much easier to handle the COmponentAdded event and just do it there.
MigrationUser 1  Wednesday, June 22, 2005 12:18 AM
thanks for the reply.

I put the following code in the OnComponentAdded method of the DesignerHost class:

if(ce.Component is Panel)
{
Panel panel = ce.Component as Panel
panel.Location = new Point(8,8);
}

but there were no changes in the location of the panel. 

I also tried using:

TypeDescriptor.GetProperties(panel)["Location"].SetValue(ce.Component, new Point(7,7));

Do you see what I am doing wrong?

regards,

- gunnar
MigrationUser 1  Wednesday, June 22, 2005 7:04 AM
That's after the fact, you can move the control after it's already been added, hence you just use the componentAdded event of the designerhost and do it there if you need to.
MigrationUser 1  Wednesday, June 22, 2005 9:22 AM
thanks for the tip, I have now solved the problem.

First I subsrcibed to the ComponentAdding event of the DesignerHost and tried to change the location there but that didn't work. Then I subscribed to the ComponentChanged event and there I could change the location. 

The ComponentChanged event is fired after the ComponentAdding event.

thanks again for the tip.

regards, 

- gunnar
MigrationUser 1  Wednesday, June 22, 2005 11:30 AM

You can use google to search for other answers

Custom Search

More Threads

• The UserControl preview does not gets updated on deleting items in CollectionEditor.
• Binding data from a database to a DGV combo box.
• Using interface as a property type?
• Setting DesignerLoader.LoaderHost.RootComponent to an existing Control
• Creating Window Menu..
• Can't hide base class properties
• Defining where 'child' controls can be placed
• Menus
• TextBox classes do not have thie method: set_AutoSize(true)
• user control at design time: a big pain...