bsturg21 wrote:
Hello,
I have a windows form that has a series of linklabels on it, and I
need to have each linklabel, when clicked, open a separate windows
form that has a single paramter passed into it. The form that has the
System.Windows.Forms.LinkLabel controls on it is in a different
project and under a different namespace from the file where the
LinkLabel_LinkClicked events are, so I can't just do frm.ShowDialog
under the LinkClicked method.
Why not? What is the definition of the variable "frm"? Is it a type
declared in the same namespace with the form containing the LinkLabel
instances?
And what do you mean by "...from the file where the
LinkLabel_LinkClicked events are"? The events themselves are in the
LinkLabel instances. Do you actually mean "...where the
LinkLabel_LinkClicked event handlers are"?
All you've said so far is that in one project/namespace you have a form
containing the LinkLabels, and in another project/namespace you have (I
am guessing you mean) the event handlers.
But as long as the event handlers are in the same project/namespace
where the dialog forms you want to show are, I don't see the problem.
Can I assume that the dialog forms are also in a different
project/namespace from where the event handlers are? If not, you should
clarify what you mean.
I've tried using eventhandlers, but the
controls are System.Windows.Forms controls and it will not let me pass
in that type of control to a custom eventhandler.
I also don't know what you mean here. What did you try to do? What
didn't work about it?
Your event handlers are, by definition, custom event handlers. That is,
you have to write them explicitly, and they do whatever you want them to
do. In addition, if you subscribe to an event on the LinkLabel control,
then that control should automatically be passed as the sender parameter
to the event handler method.
So, is there some other control that you are trying to pass to the event
handler instead? If so, what control is that? The only controls you
mentioned in your post are LinkLabel controls.
Is the eventhandler
the best way to go about doing this, or is there something else I am
missing that would be simpler? Thanks.
Your post isn't very clear about what you're actually trying to do and
what isn't working for you. Generally speaking, it's not a problem to
use classes from one project in another project, other than the need to
reference the project that has the class you want to use.
If you can't reference the project (for example, the project that needs
to use the class somehow is actually a general-purpose project that's
supposed to work with a variety of other projects), then you need to
delegate the creation of the forms to the referencing project somehow.
This could be done in a variety of ways.
One method might involve defining an event to which the referencing
project subscribes, and then when the event is raised, that referencing
project (the one that contains the dialog forms you want to instantiate)
creates the dialog form, and possibly even shows it (if you want the
referenced project -- that is, the one where the LinkClicked handlers
exist -- to actually show the dialog, then you'll instead want to define
an EventArgs-derived class that the referencing project can use to pass
the dialog back.
Another method might involve the referencing class simply instantiating
the dialog form class from the outset, and somehow passing that to the
event-handling class. Then the event-handling class can simply call the
ShowDialog() method on the form at the appropriate time.
There are probably a number of other mechanisms you can use, but without
a more clear explanation from you about what it is exactly you're trying
to do, it's hard to say. For best results, you should post a
concise-but-complete example of code that demonstrates what you're
trying to do, and what problem you're having with it.
Pete