16,006,006 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View .NET questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by grcook00 (Top 3 by date)
grcook00
27-Jan-11 20:43pm
View
I guess I may have answered my own question. What I need to do is add the control programmatically in the constructor (rather than dropping it via the designer); then all seems to work as expected (at least in the bare-bones version). I hope that this also works once the bones have been filled in; it would also be nice to be able to use the GUI for property value modification, which I cannot do with this workaround (the designer does not show a property grid for late-added controls...). If anyone else has a workaround, please let me know!
grcook00
27-Jan-11 20:21pm
View
Thank you, Manfred, for your suggestion. Although I cannot refute that this may be by design, there must certainly be a workaround. As I am unable to edit the Designer-Generated Code, could I, perhaps, create a Form class that the designer would properly interpret? Or is there some other way that I can perform my original task (that is, to allow my Class to only be instantiated against certain controls of varying types (derived from Form and Panel), and defining methods and properties that the implementing controls must have)?
Thanks again for any and all suggestions!
grcook00
27-Jan-11 20:16pm
View
SA -
I appreciate your comment on my technique. However, I do not know what the "suspect" part of code would be that I have not presented. To that end, I created a virgin VB Express project and modified the code for class Form1 as follows:
Public Class Form1
Implements IMyControlInterface
'...
End Class
Public Interface IMyControlInterface
End Interface
Public Class MyControl
Inherits Control
Private MyParentControl As IMyControlInterface
Protected Overrides Sub OnParentChanged(ByVal e As System.EventArgs)
If MyBase.Parent IsNot Nothing Then
Me.MyParentControl = TryCast(MyBase.Parent, IMyControlInterface)
If Me.MyParentControl Is Nothing Then
Throw New Exception("Control can only be added to an object that implements IMyControlInterface.")
End If
End If
MyBase.OnParentChanged(e)
End Sub
End Class
Public Class MyControlPanel
Inherits Panel
Implements IMyControlInterface
'...
End Class
This is basically the same as the original code snippets above, except that I added inheritance for class MyControl (as Control) and included a blank implementation of IMyControlInterface (as it is, so far, in my own code). I still get the same results: dragging MyControl to Form1 invokes the exception, and dragging it to MyControlPanel1 on Form1 does not.
Perhaps Manfred's answer is correct, although I do not pretend to understand its reasoning. I have also responded to that answer, to see if Manfred (or anyone else) can offer an alternative...