473,386 Members | 1,873 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

C# :how to create a delegate to an anonymous(?) button method

Okay so I have a whole bunch of begininvokes to update my gui. I enable/disable, change the text, and all that beautiful stuff.

This is, unfortunately, how my code looks right now:

Expand|Select|Wrap|Line Numbers
  1.     public abstract class update
  2.     {
  3.         public delegate void button_Callback(object[] pass);        
  4.         public static void button(object[] pass)
  5.         {
  6.             Button button = (Button)pass[0];
  7.             string command = (string)pass[1];
  8.             switch (command)
  9.             {
  10.  
  11.                 case "enable":
  12.                     button.Enabled = (bool)pass[2];
  13.                     break;
  14.                 case "text":
  15.                     button.Text = (string) pass[2];       
  16.                     break;
  17.                 default:
  18.                     break;
  19.             }
  20.         }
  21. }
so when I want to update my gui I type:
Expand|Select|Wrap|Line Numbers
  1.  BeginInvoke(new update.button_Callback(update.button),new object[] { new object[] { btn_startspg, "enable", true}});
As you can see, the problem is passing the method name as a string and going through a switch.... a lot of hard-coding

I thought of these solutions but none enthuse me that much:

1) one method per method I want to invoke (doesn't really cut down on the coding)
2) create a child of a button and add a delegate for each signature (this would involve changing all my buttons to the child button)
3) append the button class with some delegates so I can directly invoke them (I could be happy with this but I'm not sure this will work)

There must be a brilliant way to do this.

Any suggestions??
Sep 8 '08 #1
0 1118

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: BrianDH | last post by:
Hi I would ask this questiopn on the NG ASP but it would be days before anyone might respond. I am using vb.net code behind to create buttons to add to a web form. After the buttons are created...
0
by: ViRi | last post by:
There was an error loading types from assembly 'path to the dll 'Missing definition for required runtime implemented delegate method.' I get this error message when trying to add a custom control...
7
by: Rene | last post by:
We all know that we can't call custom methods or properties form generic type parameters (<T>) by default because the compiler will complain about his. For example, the following won't normally...
7
by: moondaddy | last post by:
I'm reading the book Wrox-Professional C# 2005 and it's trying to demonstrate an anonymous method in an event handler. I would not do this in a real app, but am trying to understand how this...
0
by: RickL | last post by:
Hi, I'm fairly new to web application development and I'm creating an application for camera control, which leads to the question. I want to create a button that can respond to mouse down and...
3
by: William Stacey [C# MVP] | last post by:
It would be handy to be able to ref "this" from inside an AM such as: (string s) { Console.Writeline(s); DoSomething(this); } So treating am like a method of a class (which it is)....
2
by: Bob | last post by:
What name does the compiler give to anonymous methods in the output assembly - or what is the "name pattern"? .... can't imagine it would be relevant to anything I do... just curious.
5
by: =?Utf-8?B?RWl0YW4=?= | last post by:
Hello, I need to create a background thread and two (or more) options are available to me: 1. BackgroundWorker 2. Asynch delegate method and BeginInvoke What are the differences between...
2
by: tshad | last post by:
I can do the following with Find: Racer theRacer2 = racers.Find(delegate(Racer racer) { return racer.Car == "Ferrari"; }); But I can't seem to do the same with BinarySearch, this: int iktr...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.