all groups > dotnet windows forms designtime > february 2007 >
You're in the

dotnet windows forms designtime

group:

Resize control with Verbs


Resize control with Verbs Tom Juergens
2/16/2007 9:28:10 AM
dotnet windows forms designtime:
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
Re: Resize control with Verbs Sergey M
2/16/2007 3:38:44 PM
Tom,

[quoted text, click to view]

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/

Re: Resize control with Verbs Tom Juergens
2/17/2007 3:08:00 AM
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

[quoted text, click to view]
Re: Resize control with Verbs Tom Juergens
2/17/2007 3:13:00 AM
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


[quoted text, click to view]
Re: Resize control with Verbs Sergey M
2/17/2007 11:00:36 AM
[quoted text, click to view]

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/


Re: Resize control with Verbs jetan NO[at]SPAM online.microsoft.com (
2/19/2007 12:00:00 AM
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.
AddThis Social Bookmark Button