.NET

Reply
*Jon Rizzo
Message 1 of 11 (142 Views)

problem with user defined control

142 Views, 10 Replies
05-23-2005 06:13 AM
Has anybody here ever created a user defined control and then used that
control on a form in the same project? Whenever I do this, for some reason
the form will not display in Design mode. I can view the code, and the
project runs successfully, but the Designer throws an exception and says
that there is a problem with the code (but doesn't say anything else about
the problem). If I build the project, start a NEW project and set a
reference to the first project, I can use the user defined control without
any problems. The error only happens if I try to use the control in the
same project where the control is defined.

Has anybody else seen this problem or know how to fix it? I am using VS.NET
7.0 (2002) without the service pack (for compatability reasons).

Jon
Contributor
KrishnaK
Posts: 17
Registered: ‎05-24-2005
Message 2 of 11 (142 Views)

Re: problem with user defined control

05-24-2005 01:06 PM in reply to: *Jon Rizzo
Hi Jon,

I have seen this problem with dockingPalette SDK sample. I thought I messed up VS generated code, which I could have because I was trying to add a custom combo box on the palette. I found a blog that talks about this - http://weblogs.asp.net/rweigelt/archive/2003/09/04/26262.aspx
I didn't try to fix this, so if you found a way, please let me know!

Krishna Kalvai
DevTech
Autodesk
*Jon Rizzo
Message 3 of 11 (142 Views)

Re: problem with user defined control

05-25-2005 05:31 AM in reply to: *Jon Rizzo
Hi Krishna,

Thanks for replying. That link provides some useful information. I think
the problem goes a little deeper than the solutions offered by that blog,
however. I don't believe the error is in my code - I think it has something
to do with the AutoCAD managed dll's. I did a little experimentation, and I
think I tracked down the problem (but not the solution). To reproduce this
issue reliably, do this:

Create a brand new VB class library project.
Create a blank form in this project
Create a user control in this project (but don't add or change any code)
Build the project.
Add the user control to the form.
Close the form and re-open it. It should open without a problem.
Close the form again.
Add a reference to acmgd.dll (2006)
Open the form again.
The designer throws an exception.
Remove the reference to acmgd.dll
Close the form and reopen it again.
Everything is back to normal.

If you'd prefer, I can submit a DHO ticket on this...

Jon



wrote in message news:4855100@discussion.autodesk.com...
Hi Jon,

I have seen this problem with dockingPalette SDK sample. I thought I messed
up VS generated code, which I could have because I was trying to add a
custom combo box on the palette. I found a blog that talks about this -
http://weblogs.asp.net/rweigelt/archive/2003/09/04/26262.aspx
I didn't try to fix this, so if you found a way, please let me know!

Krishna Kalvai
DevTech
Autodesk
Contributor
KrishnaK
Posts: 17
Registered: ‎05-24-2005
Message 4 of 11 (142 Views)

Re: problem with user defined control

05-25-2005 09:27 AM in reply to: *Jon Rizzo
Jon,
I was able to reproduce the error - thanks for the steps. However I don't think this is an acad bug. It is a visual studio bug (haven't checked to see if this is fixed in VS 2003). If for example you set the "Copy Local" property of acmgd.dll to False you can see the form in design mode. I think VS wrongly looks at acmgd for some reason when it loads the UserControl. I found this problem is common among apps that derive their own forms. VS instantiates the controls in order to display them.

Krishna Kalvai
DevTech
Autodesk
*Jon Rizzo
Message 5 of 11 (142 Views)

Re: problem with user defined control

05-25-2005 10:35 AM in reply to: *Jon Rizzo
Excellent! Thank you so much for figuring this out - it was driving me
crazy!!

Jon


wrote in message news:4856154@discussion.autodesk.com...
Jon,
I was able to reproduce the error - thanks for the steps. However I don't
think this is an acad bug. It is a visual studio bug (haven't checked to see
if this is fixed in VS 2003). If for example you set the "Copy Local"
property of acmgd.dll to False you can see the form in design mode. I think
VS wrongly looks at acmgd for some reason when it loads the UserControl. I
found this problem is common among apps that derive their own forms. VS
instantiates the controls in order to display them.

Krishna Kalvai
DevTech
Autodesk
Contributor
KrishnaK
Posts: 17
Registered: ‎05-24-2005
Message 6 of 11 (142 Views)

Re: problem with user defined control

05-25-2005 11:49 AM in reply to: *Jon Rizzo
Glad to be of help!

Krishna
Active Member
dickinson.fred
Posts: 9
Registered: ‎09-21-2007
Message 7 of 11 (142 Views)

Re: problem with user defined control

05-26-2010 09:40 AM in reply to: *Jon Rizzo
I tried your suggestion to set the "Copy Local" property of acmgd.dll to False (I also did it for acdbmgd.dll). When I try to add my user defined control to a form I get an error "Failed to load toolbox item 'conGetPoint'. It will be removed from the toolbox.".

I have narrowed down the problem to the following line in the user control "Dim cPoint As Geometry.Point3d". Without the line the control can be added, with the line I get the error.

I am using VS2005 and AutoCAD2008.

Your help would be appreciated.
*Tony Tanzillo
Message 8 of 11 (142 Views)

Re: problem with user defined control

05-26-2010 11:29 AM in reply to: *Jon Rizzo
The problem is that your control is trying to create an
instance of an AutoCAD type inside of Visual Studio's
designer.

A designable-control cannot use types from AutoCAD's
assemblies in code that runs in the designer/IDE.

Without seeing your control's source, or the relevant
parts of it, I can't tell you how to resolve that.

You can use a test that tells if your control's code is
running in the designer, or in AutoCAD, by reading
the value of the DesignMode property (true means
that the control is instantiated in the designer).

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2011

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message
news:6397745@discussion.autodesk.com...
I tried your suggestion to set the "Copy Local" property of acmgd.dll to False
(I also did it for acdbmgd.dll). When I try to add my user defined control to a
form I get an error "Failed to load toolbox item 'conGetPoint'. It will be
removed from the toolbox.".

I have narrowed down the problem to the following line in the user control "Dim
cPoint As Geometry.Point3d". Without the line the control can be added, with
the line I get the error.

I am using VS2005 and AutoCAD2008.

Your help would be appreciated.
Active Member
dickinson.fred
Posts: 9
Registered: ‎09-21-2007
Message 9 of 11 (142 Views)

Re: problem with user defined control

05-26-2010 12:21 PM in reply to: *Jon Rizzo
Thanks. It's good to know that its a VS / AutoCAD issue.

Here is a stripped down version of the control code which resides in the same project as the form where I'm trying to insert the control. The error happens when I try to add the control to the form. I have a similar control for getting a distance but it uses a "Double" type. Maybe I can return the 3 coordinates back as 3 doubles by getting them individually from pPromptPointResult.Value.X, Y, Z.

The offending line is "Dim cMyPoint As Geometry.Point3d".

{code

Imports Autodesk.AutoCAD
Imports Autodesk.AutoCAD.EditorInput

Public Class conGetPointX

Dim cMyPoint As Geometry.Point3d
Public Property MYPoint() As Geometry.Point3d
Get
Return cMyPoint
End Get
Set(ByVal Value As Geometry.Point3d)
cMyPoint = Value
End Set
End Property

Private Sub PickBTN_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs _
) Handles PickBTN.Click

GetPoint()

XTXT.Text = cMyPoint.X
YTXT.Text = cMyPoint.Y
ZTXT.Text = cMyPoint.Z

End Sub

Private Sub GetPoint()

Dim pDrawing As ApplicationServices.Document
pDrawing = ApplicationServices.Application.DocumentManager.MdiActiveDocument

Dim pEditor As Editor
pEditor = pDrawing.Editor

Dim pPromptPointOptions As New EditorInput.PromptPointOptions("")
With pPromptPointOptions
.Message = vbCrLf & "Enter coordinates or select a point:"
.AllowArbitraryInput = False
.AllowNone = False
.UseDashedLine = True
End With

Dim pPromptPointResult As EditorInput.PromptPointResult = Nothing
pPromptPointResult = pEditor.GetPoint(pPromptPointOptions)

Select Case pPromptPointResult.Status
Case PromptStatus.OK
cMyPoint = pPromptPointResult.Value
End Select

End Sub

End Class

/code}
*Tony Tanzillo
Message 10 of 11 (142 Views)

Re: problem with user defined control

05-26-2010 03:00 PM in reply to: *Jon Rizzo
That's not going to work as you have it.

Change your member variable and public
property to double(3) (array of 3 doubles).

You can still use Point3d in your class, but
not in code that executes in the IDE.

You should also apply these attributes to
the public MyPoint property:

[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]

You don't want that property to appear in
the Properties window in the designer, and
you don't want the designer to serialize its
value either, which is what both of the above
attributes will prevent.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2011

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message
news:6397891@discussion.autodesk.com...
Thanks. It's good to know that its a VS / AutoCAD issue.

Here is a stripped down version of the control code which resides in the same
project as the form where I'm trying to insert the control. The error happens
when I try to add the control to the form. I have a similar control for getting
a distance but it uses a "Double" type. Maybe I can return the 3 coordinates
back as 3 doubles by getting them individually from pPromptPointResult.Value.X,
Y, Z.

The offending line is "Dim cMyPoint As Geometry.Point3d".

{code

Imports Autodesk.AutoCAD
Imports Autodesk.AutoCAD.EditorInput

Public Class conGetPointX

Dim cMyPoint As Geometry.Point3d
Public Property MYPoint() As Geometry.Point3d
Get
Return cMyPoint
End Get
Set(ByVal Value As Geometry.Point3d)
cMyPoint = Value
End Set
End Property

Private Sub PickBTN_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs _
) Handles PickBTN.Click

GetPoint()

XTXT.Text = cMyPoint.X
YTXT.Text = cMyPoint.Y
ZTXT.Text = cMyPoint.Z

End Sub

Private Sub GetPoint()

Dim pDrawing As ApplicationServices.Document
pDrawing =
ApplicationServices.Application.DocumentManager.MdiActiveDocument

Dim pEditor As Editor
pEditor = pDrawing.Editor

Dim pPromptPointOptions As New EditorInput.PromptPointOptions("")
With pPromptPointOptions
.Message = vbCrLf & "Enter coordinates or select a point:"
.AllowArbitraryInput = False
.AllowNone = False
.UseDashedLine = True
End With

Dim pPromptPointResult As EditorInput.PromptPointResult = Nothing
pPromptPointResult = pEditor.GetPoint(pPromptPointOptions)

Select Case pPromptPointResult.Status
Case PromptStatus.OK
cMyPoint = pPromptPointResult.Value
End Select

End Sub

End Class

/code}
Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.