Hi David,
I have created a simple custom form designer project using .NET2.0
DesignSurface. I can't reproduce the problem of the form designer not
refreshing immediately after the properties are changed in the PropertyGrid
in my test project. You could compare my project with yours and find out
the difference.
My test project contains a main form and a HostSurface class derived form
DesignSurface class. The main form is going to display a Form designer and
a PropertyGrid. In the HostSurface there¡¯s an event handler for the
ISelectionService's SelectionChanged event so as to refresh the
PropertyGrid when the selected objects on the form designer changed.
When the program is running, a form designer with a TextBox on the form
will appear on the main form. When I select the TextBox on the form
designer, the properties of the TextBox will display in the PropertyGrid on
the main form. After I change a property of the TextBox in the
PropertyGrid, for example Width property, the TextBox's width and handle
bound will change immediately in the form designer.
The following code is picked out from my test project.
// the definition of HostSurface
public class HostSurface : DesignSurface
{
private ISelectionService _selectionService;
public HostSurface() : base()
{
// Set SelectionService - SelectionChanged event handler
_selectionService =
(ISelectionService)(this.ServiceContainer.GetService(typeof(ISelectionServic
e)));
_selectionService.SelectionChanged += new
EventHandler(selectionService_SelectionChanged);
}
// When the selection changes this sets the PropertyGrid's
selected component
private void selectionService_SelectionChanged(object sender,
EventArgs e)
{
if (_selectionService != null)
{
ICollection selectedComponents =
_selectionService.GetSelectedComponents();
PropertyGrid propertyGrid =
(PropertyGrid)this.GetService(typeof(PropertyGrid));
if (propertyGrid != null)
{
object[] comps = new
object[selectedComponents.Count];
int i = 0;
foreach (Object o in selectedComponents)
{
comps = o;
i++;
}
propertyGrid.SelectedObjects = comps;
}
}
}
public void AddService(Type type, object serviceInstance)
{
this.ServiceContainer.AddService(type, serviceInstance);
}
}
// the event handler for the main form's load event
private void Form1_Load(object sender, EventArgs e)
{
// add a custom form designer on the main form
HostSurface surface = new HostSurface();
surface.BeginLoad(typeof(Form));
Control view = (Control)surface.View;
view.Dock = DockStyle.Fill;
view.Parent = this;
surface.AddService(typeof(PropertyGrid), this.propertyGrid1);
// add a TextBox on the form designer
IDesignerHost idh =
(IDesignerHost)surface.GetService(typeof(IDesignerHost));
IToolboxUser tbu = idh.GetDesigner(idh.RootComponent as
IComponent) as IToolboxUser;
if (tbu != null)
{
ToolboxItem toolboxitem = new
ToolboxItem(typeof(TextBox));
tbu.ToolPicked((System.Drawing.Design.ToolboxItem)toolboxitem);
}
}
There's no need to handle the PropertyValueChanged event of the
PropertyGrid to refresh the form designer when the properties is changed in
the PropertyGrid.
Hope this is helpful to you. If you have any other concerns or need
anything else, please don't hesitate to let me know.
Sincerely,
Linda Liu
Microsoft Online Community Support
====================================================
When responding to posts,please "Reply to Group" via
your newsreader so that others may learn and benefit
from your issue.
====================================================