Assign a Unique ID to a Win Forms Control

  • Thread starter Thread starter John E Katich
  • Start date Start date
Hi John,
How do I assign a unique Id (like WM_USER+nnn) to a control?

I am not entirely clear about the meaning of "a unique Id on a WinForm
Control", could you please elaborate what do you want to do with that
unique Id?

Generally speaking, the .NET's WinForm controls do not like the traditional
Window 32 controls in an unmanaged application. In a .NET WinFrom
application, they are created as private member variables of their
contained WinForm class and use the "Name" property(the name of the
corresponding member variable) to identify themselves instead of a resource
ID(note: they are not resource items the .NET WinFrom project).


Thanks for your understanding!

Best regards,

Gary Chang
Microsoft Community Support
--------------------
Get Secure! ¡§C www.microsoft.com/security
Register to Access MSDN Managed Newsgroups!
http://support.microsoft.com/default.aspx?scid=/servicedesks/msdn/nospam.asp
&SD=msdn

This posting is provided "AS IS" with no warranties, and confers no rights.
 
I'm a newbie the Managed VC++, after 11+ years of Windows and MFC. so bare
with me..



I have a WinForm that has 6 Buttons that have a lot of commonality between
them. When Clicked, I would like the same Event Handler Function to handle
all 6 Buttons and use a switch statement to handle to specifics for a given
Button. To me this seems like much less code having 6 Event Handler
Functions.



The second part of the issue is, in the Event Handler Function, how do I do
the equivalent of casting the Syetem::Object *s to Button *b so I can get at
the Button's (or any sender's) variables.



Thanks

JEK
 
Hi John!
I have a WinForm that has 6 Buttons that have a lot of commonality between
them. When Clicked, I would like the same Event Handler Function to handle
all 6 Buttons and use a switch statement to handle to specifics for a given
Button. To me this seems like much less code having 6 Event Handler
Functions.

The second part of the issue is, in the Event Handler Function, how do I do
the equivalent of casting the Syetem::Object *s to Button *b so I can get at
the Button's (or any sender's) variables.

The easiest approch is to use one Event handler with using the
sender-object to determine the different buttons:

<code>
private: System::Void buttonX_Click(
System::Object * sender,
System::EventArgs * e)
{
Button *btn = dynamic_cast<Button*>(sender);
if (btn == button1)
{
MessageBox::Show(this, S"Button1");
}
else if (btn == button2)
{
MessageBox::Show(this, S"Button2");
}
else if (btn == button3)
{
MessageBox::Show(this, S"Button3");
}
else if (btn == button4)
{
MessageBox::Show(this, S"Button4");
}
}
</code>


--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
 
Hi John,

I was reviewing the issue thread. Jochen has replied with code samples on
it. Is there any question on it? If yes, please feel free to post here and
we are glad to work with you.

Thanks very much for participating the community.

Best regards,
Yanhong Huang
Microsoft Community Support

Get Secure! ¨C www.microsoft.com/security
Register to Access MSDN Managed Newsgroups!
-http://support.microsoft.com/default.aspx?scid=/servicedesks/msdn/nospam.as
p&SD=msdn

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top