Discussion:
Resize control with Verbs
(too old to reply)
Tom Juergens
2007-02-16 17:28:10 UTC
Permalink
Hi,

I've written a very simple control designer with a few verbs which resize
the control it's assosciated with to a couple of default widths. When I use
the verbs to resize the control at design time the control itself is resized,
but the resize handles in the designer are not updated - they remain stuck at
the old size until I switch focus to another control and back. I can't figure
out how to get the resize handles to adjust immediately.

Can anyone help?

Thanks
Tom

To be specific:

<Designer(GetType(MyControlDesigner), GetType(IDesigner))> _
Public Class MyControl
Inherits TextBox
...
End Class

Public Class MyControlDesigner
Inherits ControlDesigner
...
Public Overrides ReadOnly Property Verbs() As DesignerVerbCollection
Get
If _verbs Is Nothing Then
_verbs = New DesignerVerbCollection()
_verbs.Add(New DesignerVerb("Maxi", New
EventHandler(AddressOf Maxi)))
_verbs.Add(New DesignerVerb("Mini", New
EventHandler(AddressOf Mini)))
End If
Return _verbs
End Get
End Property

Private Sub Maxi(ByVal sender As Object, ByVal args As EventArgs)
Me.Control.Width = 106
' Tried all sorts of things here...
End Sub

Private Sub Mini(ByVal sender As Object, ByVal args As EventArgs)
Me.Control.Width = 42
' Tried all sorts of things here...
End Sub
End Class
Sergey M
2007-02-16 20:38:44 UTC
Permalink
Tom,
Post by Tom Juergens
the old size until I switch focus to another control and back. I can't figure
out how to get the resize handles to adjust immediately.
Try getting IComponentChangeService from component's site via GetService()
and then calling ComponentChanging on it. HTH.
--
Sergey Mishkovskiy
http://www.usysware.com/dpack/ - free VS add-ons
http://www.usysware.com/blog/
Tom Juergens
2007-02-17 11:08:00 UTC
Permalink
Thanks for the tip, Sergey.

In case anyone else ever needs it: After changing the size I now use
IComponentChangeService to inform the designer of the changes, like this:

Private Sub Maxi(ByVal sender As Object, ByVal args As EventArgs)
Me.Control.Width = 140
Dim svc As IComponentChangeService = DirectCast _
(Me.GetService(GetType(IComponentChangeService)), _
IComponentChangeService)
svc.OnComponentChanged(Me.Control, Nothing, Nothing, Nothing)
End Sub

Thanks again.
Tom
Post by Sergey M
Tom,
Post by Tom Juergens
the old size until I switch focus to another control and back. I can't figure
out how to get the resize handles to adjust immediately.
Try getting IComponentChangeService from component's site via GetService()
and then calling ComponentChanging on it. HTH.
--
Sergey Mishkovskiy
http://www.usysware.com/dpack/ - free VS add-ons
http://www.usysware.com/blog/
Tom Juergens
2007-02-17 11:13:00 UTC
Permalink
One more note: Now I see that the documentation for the
IComponentChangeService.OnComponentChanged method recommends first calling
OnComponentChanging, then making the change, then calling
OnComponentChanged, so that's what I'll do.

Tom
Post by Tom Juergens
Thanks for the tip, Sergey.
In case anyone else ever needs it: After changing the size I now use
Private Sub Maxi(ByVal sender As Object, ByVal args As EventArgs)
Me.Control.Width = 140
Dim svc As IComponentChangeService = DirectCast _
(Me.GetService(GetType(IComponentChangeService)), _
IComponentChangeService)
svc.OnComponentChanged(Me.Control, Nothing, Nothing, Nothing)
End Sub
Thanks again.
Tom
Post by Sergey M
Tom,
Post by Tom Juergens
the old size until I switch focus to another control and back. I can't figure
out how to get the resize handles to adjust immediately.
Try getting IComponentChangeService from component's site via GetService()
and then calling ComponentChanging on it. HTH.
--
Sergey Mishkovskiy
http://www.usysware.com/dpack/ - free VS add-ons
http://www.usysware.com/blog/
Jeffrey Tan[MSFT]
2007-02-19 05:48:47 UTC
Permalink
Hi Tom,

Yes, you are right.

Normally, we should fire OnComponentChanging before the component is
actually changed, and gives the designer a chance to abort the change or
perform any pre-change processing. And after making the changes, you may
call OnComponentChanged method.

.Net BCL designer classes also obey this rule. See the code of
Localize(IDesignTimeResourceWriter resourceWriter) method in
System.Web.UI.Design.ControlDesigner:

public void Localize(IDesignTimeResourceWriter resourceWriter)
{
string text1;
this.OnComponentChanging(base.Component, new
ComponentChangingEventArgs(base.Component, null));
string text2 = ControlLocalizer.LocalizeControl((Control)
base.Component, resourceWriter, out text1);
if (!string.IsNullOrEmpty(text2))
{
this.SetTagAttribute("meta:resourcekey", text2, true);
}
if (!string.IsNullOrEmpty(text1))
{
this._localizedInnerContent = text1;
}
this.OnComponentChanged(base.Component, new
ComponentChangedEventArgs(base.Component, null, null, null));
}

Anyway, if you need further help, please feel free to post, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Sergey M
2007-02-17 16:00:36 UTC
Permalink
Post by Sergey M
Try getting IComponentChangeService from component's site via
GetService()
and then calling ComponentChanging on it. HTH.
I meant calling OnComponentChanged as oppose to ComponentChanging, of
course. Sorry about that.
--
Sergey Mishkovskiy
http://www.usysware.com/dpack/ - DPack - free VS add-ons
http://www.usysware.com/blog/
Loading...