Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / May 2005

Tip: Looking for answers? Try searching our database.

Assign a Unique ID to a Win Forms Control

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John E Katich - 06 May 2005 23:49 GMT
How do I assign a unique Id (like WM_USER+nnn) to a control?
Gary Chang[MSFT] - 07 May 2005 07:22 GMT
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.
John E Katich - 07 May 2005 11:24 GMT
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,
>
[quoted text clipped - 27 lines]
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
Jochen Kalmbach [MVP] - 07 May 2005 12:02 GMT
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
[quoted text clipped - 5 lines]
> 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>

Signature

Greetings
  Jochen

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

Yan-Hong Huang[MSFT] - 11 May 2005 03:16 GMT
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.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.