Custom Forms Designer Property Changed Event?

G

Guest

Hi there,

I have created a very simple custom forms designer, using the .NET2.0
DesignSurface. There are no implementations of any of the services.

If I change a property of any of the components on the designer host, for
example the font size of a label, then the design surface does not update.
(Properties are changed using a PropertyGrid).

To make things a little clearer, the font size would change, but the handles
around the label to resize do not. They keep the same shape as the label was
before the font change. I hope this makes sense....

I have captured a PropertyValueChangedEvent for the property grid, but can't
find a way to make the designer refresh.

So, any ideas how I can make the designer surface refresh when a property is
changed?

Many thanks,

David Whitchurch-Bennett
 
L

Linda Liu [MSFT]

Hi David,
Thank you for posting. From your post, my understanding on this issue is:
when you change a property of a control on a Windows form, the design
surface does not update. If I'm off base, please feel free to let me know.

When you change a property of any control on a Windows form, the change
should be shown on the form design surface immediately. You have mentioned
that when you change the font size of a label, the label's font size would
change, but the handle around the label do not. The handle bound around the
label is decided by the label's size. So the handle bound will not change
when you only change the label's font size. To make the handle around the
label change with the font size, you should set the label's AutoSize
property to be true.

Could you tell me what other controls have the same "problem " as label?
I am looking forward to your reply. Thanks.


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.
====================================================
 
G

Guest

Hi Linda,

Thanks for your reply. You are absolutely right about the problem, and you
have it spot on.

However, in this example, the label is set to autosize, and if you change
the font size from 10 to 20, it will be much larger, and the handle should
reflect this (allbeit you can't resize with the handle!). It would be the
same if you had a text box and changed the width in the property grid. Again,
the box would change size, but not the handle about the box.

Many thanks,

David
 
L

Linda Liu [MSFT]

Hi David,

You're welcome!
If you have any other questions or concerns, please don't hesitate to
contact us. It is always our pleasure to be of assistance.


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.
====================================================
 
G

Guest

Hi there,

I still haven't got an answer to the question, and I still have the problem,
so if you can help on this issue, it would be great! Sorry if you thought
that I had solved it.

David
 
L

Linda Liu [MSFT]

Hi David,
I'm sorry that you still have the problem. As for a textbox, if the width
has been changed in the property grid, the handle bound of the textbox
should change as well. You have mentioned that the textbox would change
size, bu not the handle about the box. Could you tell me what you mean by
saying the textbox change size?

Thanks.


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.
====================================================
 
G

Guest

Hi Linda,

What you are describing as 'should be happening' is exactly what is not
happening. If I change the size of the text box control in the property grid,
the text box changes size, but not the handle. The handle stays the same size
as the old text box size. I know the handle should change size, but it
doesn't.

Perhaps I am missing some kind of service registration, or maybe I need to
receive an event that one of the components have changed and pass it to the
designer so the handle can be updated. As a work around, I can deselect all
the components and reselect them in code when the property grid fires a
change event, and this updates the handle size correctly. However, this is
not ideal!

Hopefully you can see the problem there. The designer is in VB.net, and I
haven't really done anything complicated with it. I have drawn the designer's
view onto the form, and added a couple of components, and that's it.

Best Regards,

David.
 
L

Linda Liu [MSFT]

Hi David,

Thank you for your reply.

I am sorry that I don't see the problem you have described about TextBox in
my test project. When I change the size of a textbox in the property grid,
the handle changes in the form designer.

I think the problem may be caused by your IDE. You could reinstall it and
have a try again.

Good luck to you!




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.
====================================================
 
G

Guest

Hi Linda,

Can I just confirm that we are talking about the same thing. I am not
talking about the Visual Studio IDE designer. I have impemented a custom
forms designer, and drawn its surface onto the form. It is my custom forms
designer that does not behave correctly, not the IDE. Did you create a custom
forms designer and get it to work?

David
 
A

Andreas

Hi David,

I had a similar problem with my user control.
After you change the text of the Label you must call Label1.Update() in
the user Control code. This will update your handle when your user
controll will be reloaded but not imadiatly (close the Designer of the
Form where you use your user Control and reload it).

I hope that will help you
 
L

Linda Liu [MSFT]

Hi David,

Thank you for your reply. I have misunderstood your meaning.

I am performing research on this issue and will get back as soon as
possible. I appreciate your patience.


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.
====================================================
 
L

Linda Liu [MSFT]

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.
====================================================
 
G

Guest

Hi Linda,

That's what I did (reselecing all the components). This works, but I though
perhaps something was missing when it didn't do it automatically.

Still, if works OK, albeit there's a flicker while this happens. This is
fine though!

Thanks for you help on this.

David

Linda Liu said:
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.
====================================================
 
L

Linda Liu [MSFT]

Hi David,

You're welcom!
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.
====================================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top