name property of controls in .net compact framework

  • Thread starter Thread starter Hari
  • Start date Start date
H

Hari

Hi,
I'm developing a chat application for PPC. In a form i need to
know which button is clicked. i found Name property of the controls is
not accessible at run time. i can't use the text property bcoz many of
the buttons have the same text. So is there any other way to find out
which button is clicked? Plz help
 
Hi,

In the Click handler, try to cast the sender parameter of the method in
button type :
private void myButton_Click(object sender, EventArgs e)
{
Button myButton = (Button)sender;
// then you have access to the name of the button
myButton.Name

BR


Fabien Decret
Windows Embedded Consultant

ADENEO (ADESET)
http://www.adeneo.adetelgroup.com/




Hari a écrit :
 
If you use latest CF2 SP1, I think you will be able to use the name
property at runtime.

Regards,

Sachin Palewar

Palewar Techno Solutions
Pocket PC & Mobile Software Development
Nagpur, India

http://www.palewar.com/
 
Hi Chris,

Thankx for the link. This contains the code, but there is no
explanation of how to use that code. I did'nt understand how to link-up
this code to my application. Plz tell me how to make use of this. Or is
there any other simple way? Plz help.
- Hari
Priya
 
Hi Chris,

Thankx for the link. This contains the code, but there is no
explanation of how to use that code. I did'nt understand how to link-up
this code to my application. Plz tell me how to make use of this. Or is
there any other simple way? Plz help.
- Hari
Priya
 
Hari,

Just do:

class Button2 : Button
{
public readonly string Name;

public Button2 (string text, string name)
{
this.Text = text;
this.Name = name;
}
}
 
Hi Hilton,
Thanks a lot. It helped me. By subclassing from the Button
control we are just adding our own name property. But is it not
possible to access the existing Name property of any control. So if i
want to identify a control do i have to subclass it? But usercontrol is
not available in CF. So i can't just drag and drop the control. I've to
add it in codebehind. So, is there any better way, where i can just
access the existing Name property of the control or create my own
control and just drag and drop it to the form. Plz help.
Thankx,
Hari
 
Look at my code. Call GetControlName, pass it the control instance, it
gives back the string name.

-Chris
 
Hi Chris,
Thanks a lot. Its working. But when i passed "this" as argument to
the method its throwing an unhandled exception instead of showing the
form name. What could be the problem. Sorry, i'm completely unaware of
Reflection. Is it not possible to get the form name using this
function. I would be thankful for any response.
-Hari
 
Back
Top