I have created a UserControl and a designer for it and I am having problems with the adornments drawing incorrectly when resizing the control in design mode. When resizing the control, the adornments are drawn to the original control bounds and not to the resized control bounds. If I select something else, and reselect the control, the adornments draw correctly. Here is how I am declaring the UserControl:
[
Designer(typeof(UserControl1Designer))] public partial class UserControl1 : UserControl { public UserControl1() {InitializeComponent();
}
}
Here is the designer code:
class UserControl1Designer: System.Windows.Forms.Design.ControlDesigner { protected override void PostFilterProperties(System.Collections.IDictionary properties) {//do some filtering
base.PostFilterProperties(properties);
}
}
If I change the DesignerAttribute for the UserControl to the following:
[Designer(typeof(UserControl1Designer), typeof(System.ComponentModel.Design.ComponentDesigner))]
the adornments problem goes away, but the PostFilterProperties of the designer is never called.
Any ideas on how to solve this problem

Resizing a control problem in design mode
RS_Trans
Which is how the glyphs are updated when a resize is done, but no new selection is made.
Martin
Jeff Walsh
Hey,
The PropertyGrid listens to OnTransactionClosed and updates the values then. The PropertyGrid hooks these events when it is sited. The DesignerHosting sample does not site the grid, thus it won't update when the resize/move is done.
If you site your grid, then it will work.
Martin
maxi_byte
djalexd
Martin,
Thank you for your reply. That fixed the problem. Is there anywhere that this is documented It seems like there is a lot of undocumented design-time behavior.
Doug
Najm
Martin,
I have a property grid that displays the properties of the component on the form. When a component is selected, I assign it to the property grid to display the properties to the user. When I make changes to the component on the design form, the property values do not change in the property grid. An example would be resizing or moving the component; the location and size properties do not update in the property grid. The values will update if I select something else and then re-select the component.
I noticed this was a problem in the March MSDN example (http://msdn.microsoft.com/msdnmag/issues/06/03/DesignerHosting/default.aspx -- code is at http://download.microsoft.com/download/f/2/7/f279e71e-efb0-4155-873d-5554a0608523/DesignerHosting.exe ) as well. I'm sure it is something simple I am overlooking.
Thanks,
Doug
tnyx
My designer is derived from ControlDesigner. Here is all the code for my designer and for my user control:
using
System;using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication5 {
[Designer(typeof(UserControl1Designer))]
public partial class UserControl1 : UserControl {
public UserControl1() {
InitializeComponent();
}
}
}
using
System;using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
namespace WindowsApplication5 {
= (PropertyDescriptor)properties[names
];
] = descriptors
;
class UserControl1Designer: System.Windows.Forms.Design.ControlDesigner {
protected override void PostFilterProperties(System.Collections.IDictionary properties) {
string[] names = new string[] { "Location", "Size" };
PropertyDescriptor[] descriptors = new PropertyDescriptor[names.Length];
for (int i = 0; i < names.Length; ++i) {
descriptors
}
properties.Clear();
for (int i = 0; i < names.Length; ++i) {
properties[names
}
base.PostFilterProperties(properties);
}
}
}
Create a new Windows Form project, add these classes to it, build the project, and then use the form design view to add the UserControl1 to the form for the project. Once you have the UserControl on the form, resize it and you will see that the adornments do not redraw to the new control size, they draw to the original size. I think that this is a bug in the .NET code. I should be able to provide my own desinger that is derived from the ControlDesigner and still have the adornments work correctly.
coronaride
Martin,
That fixed my problem. Thank you again for your support. You have been a tremendous help to me.
Doug
snktheone
The key here is the stuff you are doing in PostFilterProperties. The resize logic uses the Width, Height, Top, and Left properties and queries for those through the TypeDescriptor. In this case they aren't there, and things go a little wrong. Without those Undo won't work either.
If you add those 4 properties to you names array, then everything works just fine.
Martin
ebc
Are you setting the values through propertydescriptors If not that might be the cause of you problem. Doing so should ensure that the right valuechanged events are being fired so that the propertygrid can update.
Martin
Shane Gidley
Okay, it wasn't clear to me if you were handling the resize/move or letting the designer doing it.
I will try and take a look at the DesignerHosting sample to see what's going on there. I won't be able to get to it until next week.
Martin
aalford
I don't understand what you mean by setting the values through the property descriptors. I am using the design-time environment to change the properties. If I place a component on the design surface and resize it using the sizing handles, the size property does not update in the property grid. If I move the component on the design surface, the location property does not update in the property grid.
Doug
Johan Delimon
Hey,
No, it is not documented anywhere afaik. I totally understand that completely documenting the design-time behavior would be useful as you point out.
It is tricky to get all possible scenarios right, and in some cases we need to make some assumptions about what information is available on a control and gracefully degrade.
Sorry,
Martin
ShinjisukeSono
Hey Doug,
Glad I could help.
Martin
CarlaOR
Hi,
Are you using the WinForms designer or are you using your own designer
When a control is being resized in the WinForms designer, we do not draw the adornments -- I assume you mean the little squares (glyphs), aka grabhandles.
The size and location of each glyph is based on the control's location and size. When the selection changes the glyphs for the selected control are regenerated. So if the glyphs are being drawn while resizing but before the glyphs have had a chance to regenerate, they will draw in the old location.
To temporarily disable the adorners you can do the following when the resize starts:
foreach (Adorner a in BehaviorService.Adorners) {
a.Enabled = false;
}
Once the resize is done, you know what to do...
Martin