Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / Design Time / February 2007

Tip: Looking for answers? Try searching our database.

Resize control with Verbs

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Tom Juergens - 16 Feb 2007 17:28 GMT
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 - 16 Feb 2007 20:38 GMT
Tom,

> 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.
Signature

Sergey Mishkovskiy
http://www.usysware.com/dpack/ - free VS add-ons
http://www.usysware.com/blog/

Tom Juergens - 17 Feb 2007 11:08 GMT
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

> Tom,
>
[quoted text clipped - 4 lines]
> Try getting IComponentChangeService from component's site via GetService()
> and then calling ComponentChanging on it. HTH.
Tom Juergens - 17 Feb 2007 11:13 GMT
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

> Thanks for the tip, Sergey.
>
[quoted text clipped - 20 lines]
> > Try getting IComponentChangeService from component's site via GetService()
> > and then calling ComponentChanging on it. HTH.
Jeffrey Tan[MSFT] - 19 Feb 2007 05:48 GMT
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 - 17 Feb 2007 16:00 GMT
>> 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.
Signature

Sergey Mishkovskiy
http://www.usysware.com/dpack/ - DPack - free VS add-ons
http://www.usysware.com/blog/


Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.