Advertisement

05.15.2008 at 06:17AM PDT, ID: 23404942
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

Need Help Passing Double_Click Event Handler to Sub [Delegates?]

Tags: Microsoft, Visual Studio 2005, 2K5, Delegate, Pass Sub/Function handler
I have this great Main-Menu that populates itself with various PictureBox/Icons allowing different Users to perform different Functions, depending on their Role in the System.  As I was hard-coding each Icon's Double-Click Handler (and other attributes), it occurred to me that I might be able to use Delegates, and create a single Sub Add_Menu_Icon(...) that would allow each "menu bar" to be populated using a check-verify-add-icon type of procedure, instead of hand-coding each and every icon.  Code simplification, if you will, is what I'm after.  Less repetitive coding.  Easier code maintenance, later.  that sort of thing.

After studying several different web pages (that are vague rip-offs of each other), and looking at not a few solutions her, I am still confused as to how to apply Delegates to accomplish my task.  I keep getting definition errors and the like - and the app won't fly.  It also won't compile, and that's an even bigger problem.  :D

What I'm attempting to do is create a Subroutine "Add_Menu_Icon", that will allow me to pass the PanelName, various info on the Icon (Name, Image/Picture, Text, [Double-Click Handler] for starters) but I cannot seem to get the three phases together.

In C++ I would pass the pointer to the sub/function, and that would be all I needed, with full transparency and as many levels of pass-through as I needed.  Naturally, VB.Net wants that functionality, but cannot have it unless it is over-complicated.  I'm trying to pass an Event-Handler *through* a sub/function, to attach to a particular control within the passed sub/function.  Is that possible?  Or am I trying to push VB.Net too far (again)?
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
[ Used In >other< Sub: ]
...
   Add_Menu_Icon(nuPanel, "ExitIcon", New Bitmap(Me.GetType, "EDM_Generic.ico"), "Exit", AddressOf icon_Exit_DoubleClick)
...
 
 
[ Definitions, Offending Code: ]
 
   Private Delegate Sub iconDoubleClickHandler(ByVal sender As Object, ByVal e As System.EventArgs)
 
 
   Private Sub Add_Menu_Icon(ByRef thisPanel As Panel, ByVal iconName As String, ByRef iconPicture As Image, ByVal iconText As String, ByRef iconDblClk As iconDoubleClickHandler)
 
      Dim iconFX As PictureBox
      Dim iconTX As Label
 
      iconFX = New PictureBox
      iconFX.BackgroundImage = iconPicture
      iconFX.BackgroundImageLayout = ImageLayout.Stretch
      iconFX.Size = New Size(60, 60)
      iconFX.Name = iconName
      iconFX.Location = New Point(10, 10)	' TODO: Change to reflect positions...
      iconFX.BorderStyle = BorderStyle.FixedSingle
 
      AddHandler iconFX.MouseDown, AddressOf specMouseDown
      AddHandler iconFX.MouseMove, AddressOf specMouseMove
      AddHandler iconFX.LocationChanged, AddressOf specMsgMove
      AddHandler iconFX.DoubleClick, iconDblClk
 
      iconTX = New Label
      iconTX.Name = iconName & "Text"
      iconTX.BackColor = Color.Transparent
      iconTX.AutoSize = False
      iconTX.Font = New Font("Arial", 8.5, FontStyle.Regular, GraphicsUnit.Point)
      iconTX.Width = iconFX.Width
      iconTX.TextAlign = ContentAlignment.TopCenter
      iconTX.BorderStyle = BorderStyle.None
      iconTX.Text = iconText
      iconTX.Location = New Point(iconFX.Location.X, (iconFX.Location.Y + iconFX.Size.Height))
      iconFX.Tag = iconTX
 
      thisPanel.Controls.Add(iconFX)
      thisPanel.Controls.Add(iconTX)
 
   End Sub
Start your free trial to view this solution
Question Stats
Zone: Programming
Question Asked By: LongFist
Solution Provided By: jcoehoorn
Participating Experts: 2
Solution Grade: A
Views: 8
Translate:
Loading Advertisement...
05.15.2008 at 06:39AM PDT, ID: 21573474

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.15.2008 at 07:34AM PDT, ID: 21574060

Rank: Wizard

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.15.2008 at 07:47AM PDT, ID: 21574221

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.15.2008 at 08:19AM PDT, ID: 21574610

Rank: Wizard

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.15.2008 at 08:22AM PDT, ID: 21574642

Rank: Wizard

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.15.2008 at 08:36AM PDT, ID: 21574797

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.15.2008 at 08:39AM PDT, ID: 21574843

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.15.2008 at 08:40AM PDT, ID: 21574869

Rank: Wizard

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.15.2008 at 08:41AM PDT, ID: 21574874

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.15.2008 at 08:51AM PDT, ID: 21574981

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.15.2008 at 09:00AM PDT, ID: 21575069

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.15.2008 at 09:03AM PDT, ID: 21575103

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.15.2008 at 09:42AM PDT, ID: 21575623

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.15.2008 at 10:16AM PDT, ID: 21576006

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
20080236-EE-VQP-29 / EE_QW_2_20070628