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 / .NET Framework / New Users / February 2007

Tip: Looking for answers? Try searching our database.

Custom Form working at runtime but cannot be loaded in designer

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ThunderMusic - 22 Nov 2006 14:43 GMT
Hi,
I have a custom form that works fine when I debug it or run it in release
mode but cannot be loaded in the designer...  Actually, it can be loaded in
the designer when no control is on it, but the resizing tool (in the
designer) is offset both horizontally and vertically and when I put a
control on it, as soon as I save, the designer throws an exception (but
cannot be reproduced everytime) and the form cannot be loaded anymore unless
I remove all the controls from it...  but the major problem is the offset of
the designer...  also, I'm unable to move the newly added controls on my
form... I can resize them when I add them and after that cannot even select
them... this behavior happens when I want to use the custom form (inherit
forms of my projects from this form)...

When I want to see the form in the designer (the CustomForm itself inherited
from system.windows.forms.form) I receive and exception too (here it is)

Events cannot be set on the object passed to the event binding service
because a site associated with the object could not be located.
Hide
at
System.ComponentModel.Design.EventBindingService.EventPropertyDescriptor.SetValue(Object
component, Object value)
at
System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeAttachEventStatement(IDesignerSerializationManager
manager, CodeAttachEventStatement statement)
at
System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeStatement(IDesignerSerializationManager
manager, CodeStatement statement)

Events cannot be set on the object passed to the event binding service
because a site associated with the object could not be located.
Hide
at
System.ComponentModel.Design.EventBindingService.EventPropertyDescriptor.SetValue(Object
component, Object value)
at
System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeAttachEventStatement(IDesignerSerializationManager
manager, CodeAttachEventStatement statement)
at
System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeStatement(IDesignerSerializationManager
manager, CodeStatement statement)

Method 'System.Windows.Forms.Form.SetStyle' not found.
Hide
at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags,
Binder binder, Object target, Object[] providedArgs, ParameterModifier[]
modifiers, CultureInfo culture, String[] namedParams)
at
System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeExpression(IDesignerSerializationManager
manager, String name, CodeExpression expression)
at
System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeStatement(IDesignerSerializationManager
manager, CodeStatement statement)

Does anybody know the solution to this kind of behavior? btw, it may be
relevant to say I'm using a custom message filter (IMessageFilter)

Thanks

ThunderMusic
ThunderMusic - 23 Nov 2006 18:42 GMT
ok...  great I solved most of my problems...  the only thing remaining is
the fact that the form appears offset with the sizing anchors in the
designer when I inherit from it.

So let's say I have my CustomForm, then I create a form like this "public
class MyForm : CustomForm"... Everytime I want to load MyForm in the
designer, the anchors are offset...  the form itself is in the right place,
but the anchors are offset low and right and everything I place on the form
is located at 0,0 and cannot be moved in the designer (cannot even be
selected again after I select anything else at creation)... I can move them
into the MyForm.designer.cs tought, and it works fine, but it's not the
"normal" behavior of things...  does anybody can point me to some possible
causes for this problem?

thanks

ThunderMusic

> Hi,
> I have a custom form that works fine when I debug it or run it in release
[quoted text clipped - 57 lines]
>
> ThunderMusic
Mick Doherty - 23 Nov 2006 23:01 GMT
Sorry for the slow response, but I've been busy.

Because you are using the method on my site, most users may not even have
seen the error without further info. I happen to know what you're doing
because of a previous thread.

When Inheriting the shapedform class you need to make sure that the
CreateParams is not applied in DesignTime, so the CreateParams method should
be modified as below:

protected override System.Windows.Forms.CreateParams CreateParams
{
   get
   {
       CreateParams cp = base.CreateParams;
       if (!this.DesignMode)
       {
           const int WS_CLIPCHILDREN = 0x2000000;
           const int WS_MINIMIZEBOX = 0x20000;
           //const int WS_MAXIMIZEBOX = 0x10000;
           const int WS_SYSMENU = 0x80000;

           const int CS_DBLCLKS = 0x8;
           const int CS_DROPSHADOW = 0x20000;

           int ClassFlags = CS_DBLCLKS;
           int OSVER = Environment.OSVersion.Version.Major * 10;
           OSVER += Environment.OSVersion.Version.Minor;
           if (OSVER >= 51) ClassFlags = CS_DBLCLKS | CS_DROPSHADOW;

           cp.Style = WS_CLIPCHILDREN | WS_MINIMIZEBOX | WS_SYSMENU;

           cp.ClassStyle = ClassFlags;
       }
       return cp;
   }
}

Signature

Mick Doherty
http://dotnetrix.co.uk/nothing.html

> ok...  great I solved most of my problems...  the only thing remaining is
> the fact that the form appears offset with the sizing anchors in the
[quoted text clipped - 75 lines]
>>
>> ThunderMusic
ThunderMusic - 23 Nov 2006 23:52 GMT
Great!!!  everything is solved now...  thanks a bunch... ;) I modified your
solution a bit to remove the border at design time because, anyways, it's
not useful to show it as it will not be visible at runtime... and it does
not cause any problem to remove it at design time (no one I can see right
now, if you think of one, let me know)

Thanks a lot again!!

ThunderMusic

> Sorry for the slow response, but I've been busy.
>
[quoted text clipped - 115 lines]
>>>
>>> ThunderMusic
Geir Sanne - 09 Feb 2007 12:44 GMT
hi!!!

what did you do to get rid of the strange designtime error ?
i got the same problem after upgrading my project from .net 1.1 to 2.0.
all forms that uses my custom usercontrol get this message.

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.