473,549 Members | 2,733 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Best way to have linklabel open a windows form

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_LinkC licked events are, so I can't just do frm.ShowDialog
under the LinkClicked method. 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. Is the eventhandler
the best way to go about doing this, or is there something else I am
missing that would be simpler? Thanks.

Aug 17 '07 #1
3 4669
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_LinkC licked 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_LinkC licked events are"? The events themselves are in the
LinkLabel instances. Do you actually mean "...where the
LinkLabel_LinkC licked 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
Aug 17 '07 #2
Yes. The LinkClicked eventhandlers are in a different namespace from
the form that I am trying to show. I tried making an eventhandler
with the following code:

private void lnkName_LinkCli cked(object sender,
Peracon.Client. Application.Con trols.LinkLabel LinkClickedEven tArgs e)
{
this.AssetClick ed(sender, e);
}

but when the code to assign the eventhandler to the link label is
called, it complains because the linklabel is a System.Windows. Forms
control and the eventhandler takes in
Peracon.Client. Application.Con trols.LinkLabel LinkClickedEven tArgs.
Here is the code where it is assigning the eventhandler to the
linklabel. The AssetClick is the delegate:

this.lnkName.Li nkClicked += new
Peracon.Client. Application.Con trols.AssetClic k(this.lnkName_ LinkClicked);

So that is the problem. I think I actually want the ShowDialog() to
be called from the form that contains all the linklabels, and not from
the eventhandler, which is in a separate namespace, because I will
want that form to be passed as the parent to the form that is brought
up, which will be a dialog.

On Aug 17, 1:18 am, Peter Duniho <NpOeStPe...@Nn OwSlPiAnMk.comw rote:
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_LinkC licked 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_LinkC licked events are"? The events themselves are in the
LinkLabel instances. Do you actually mean "...where the
LinkLabel_LinkC licked 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

Aug 17 '07 #3
bsturg21 wrote:
Yes. The LinkClicked eventhandlers are in a different namespace from
the form that I am trying to show. I tried making an eventhandler
with the following code:

private void lnkName_LinkCli cked(object sender,
Peracon.Client. Application.Con trols.LinkLabel LinkClickedEven tArgs e)
{
this.AssetClick ed(sender, e);
}

but when the code to assign the eventhandler to the link label is
called, it complains because the linklabel is a System.Windows. Forms
control and the eventhandler takes in
Peracon.Client. Application.Con trols.LinkLabel LinkClickedEven tArgs.
Can you please explain what it is you expect the above code to do? You
seem to have defined your own EventArgs class, but the LinkLabel control
doesn't know anything about it, nor could it. Its event requires a
delegate that uses the
System.Windows. Forms.LinkLabel LinkClickedEven tArgs class. Even if you
could somehow convince the compiler to compile your delegate that
declares a different type, the LinkLabel class is still only going to
pass the class it knows: its own LinkLabelLinkCl ickedEventArgs.

If you want to write a delegate that takes some other kind of EventArgs
parameter, where is it that you are expecting the instance of that class
to be created?
Here is the code where it is assigning the eventhandler to the
linklabel. The AssetClick is the delegate:

this.lnkName.Li nkClicked += new
Peracon.Client. Application.Con trols.AssetClic k(this.lnkName_ LinkClicked);

So that is the problem.
Why are you using a different delegate type than the one required by the
event? That is, the LinkLabelLinkCl ickedEventHandl er type?

And finally, how is the above related to the last part of your message?
That is:
I think I actually want the ShowDialog() to
be called from the form that contains all the linklabels, and not from
the eventhandler, which is in a separate namespace, because I will
want that form to be passed as the parent to the form that is brought
up, which will be a dialog.
The two are not mutual requirements. That is, if you want the form with
the LinkLabel instances (I'll call it the "main form") to be the parent
of the dialog forms, all you need is for that parent to be used when
calling ShowDialog() on the dialog forms. The event handler does not
need to be in the same namespace as the main form to have this
reference; it just needs a way to get the reference.

As an example: if you have the event handler for a LinkClicked event,
that event handler is going to get the LinkLabel instance reference as
the "sender" argument. You can follow the Control.Parent property from
that argument up to the main form; if the LinkLabel instances are
top-level children of that form, you can just look at the Parent
property of the sender. Otherwise, you'll have to have a loop that
keeps getting the Parent property of the previous Parent until you reach
the top of the chain (Parent is null).

Of course, you need to cast the "sender" argument to a Control before
getting the Parent property.

So in the event handler, just get the parent form from the Parent
property of the sender and use that as your parent when calling
ShowDialog().

Now, you may have other reasons for wanting to call ShowDialog() from
the main form. But if the only reason you want to call ShowDialog()
from the main form is because of the parent issue, that's not actually a
reason you have to do that.

And all that said, I still don't see how this issue is related to the
first. That is, what does the need to set the parent when calling
ShowDialog() have to do with your apparent desire to use a class other
than the proper LinkLabelLinkCl ickedEventArgs class as the second event
handler argument?

Pete
Aug 17 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2105
by: Nick P | last post by:
Is it possible to use javascript within a link label link in C#? I want to call up a web page from a link label but without any scroll bars and have it a certain size. I am trying to use the javascript:window.open this.lbtnArrangeColumns.Links.LinkData =...
0
1881
by: tota | last post by:
i'm using windowsApplication to connect to DB made by SQL i need to Display the Data of the first table in the DB as links when click it it openes a table and i navigte between them using buttons my problem is that i need to make the retrieved data as links (similar to objectList in Mobile application) i used LinkLabel to make an array of...
1
5313
by: gabe | last post by:
I am looking for a way to mimic some of the functionality of a web page without writing html (or I am looking to someone to point out something really obvious that I am over looking) Currently I read out some data into a dataset then appending it to a richtextbox. So far so good. Some of the fields that I append are paths to documents. I...
3
12011
by: vince | last post by:
Hello, I have a ListBox filled with many lines of simply text I want to make few lines be a LinkLabel How can I do this Thanks
0
1260
by: Suz | last post by:
I am stumped! I can't seem to figure out how to put a linklabel in a datagrid on a windows form. I have working code that displays a linklabel in edit mode but need the linklabel to display during the initial datagrid load. I am working with datagridcolumnstyles. I have looked at combobox examples, etc but can't seem to extrapolate. Any...
1
1738
by: Marcus Kwok | last post by:
I am having problems getting my LinkLabel hyperlink to work properly. Every time I click on it, I get the following exception: System.ComponentModel.Win32Exception: The requested lookup key was not found in any active activation context at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo) at...
4
6551
by: David Veeneman | last post by:
I'm creating a UserControl that uses a LinkLabel. For reasons that I won't bore everyone with, I don't want the LinkLable to show the default hand cursor when the mouse enters the control. Should be a simple setting on the LinkLabel.Cursor property, right? Not so simple. I set the property, but still got the default 'hand' cursor. To debug,...
0
2356
by: kirk | last post by:
I started with a System.Windows.Forms.Form and subscribed to its LostFocus event. The event fires perfect. I added a System.Windows.Forms.LinkLabel to the aforementioned Form and tested the same LostFocus event again. It does not fire any longer. If I remove the LinkLabel, LostFocus fires again. Why does this fail and how can I get...
2
2128
by: prokopis | last post by:
am using c# for windows applications. am using dynamic linklayer array to print some labels in the form.i get some data from the database i add them in the linklabel array and i print it on the screen. my problem is how to make that linklabel to work when i select the label.am using the code below but is not working:) public class Form1 :...
0
7720
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7475
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7812
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6048
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5372
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5089
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3501
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3483
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1061
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.