|
The shortest example? Well I guess that would be...
class T{delegate void D();static void Main(){new D(Main)();}} ...but watch out for the stack overflow.
I suppose you'd like a useful example?
class Example {
delegate void StatusOutput(string text);
static void Main() {
DoSomeWork(new StatusOutput(System.Console.WriteLine));
DoSomeWork(new StatusOutput(Alert));
}
static void Alert(string text) {
System.Windows.Forms.MessageBox.Show(text, "Status Update");
}
static void DoSomeWork(StatusOutput output) {
output("Working...");
System.Threading.Thread.Sleep(2000);
output("Done");
}
}
That was about the shortest meaningful use I could think of. A delegate is an object that wraps a method. You can then pass this object around and use it later to call the method. There are lots of other more advanced uses, like invoking them asynchronously, but that's a start.
--
-Blake (com/bcdev/blake)
|
|
|
|
|
When would be the best time in your own opinion to use the ref in C#?
"To teach is to learn twice"
|
|
|
|
|
When you need to modify the source variable rather than a copy of it.
Example:
void Test()
{
string str="UnModified";
RefTest(ref str);
}
void RefTest(ref string s)
{
s="Modified!";
}
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
How can I add a type derived from DataGridColumnStyle into the list in the DataGridColumnStyle Collection Editor dialog box (of the Properties dialog box)?
|
|
|
|
|
I have a project downloaded from somewhere (I dont remember from where) that demonstrates how to do this.
If you let me know your email id I can send it to you.
Suhas
|
|
|
|
|
I would like to have a combobox that shows bands of color instead of text. Would the best way to accomplish this be to use the OwnerDrawFixed (they're all the same size) style and draw the color bars in the DrawItem event? I don't want to create a custom combobox I simply want to draw colors instead of text.
- monrobot13
|
|
|
|
|
I'm trying to learn how to do Remoting in .Net and I've read a ton of examples on this site, other sites, and books and all of them have the line:
using System.Runtime.Remoting.Channels.Tcp;
But when I try to compile the code while in VS it fails with the following message:
The type or namespace name 'Tcp' does not exist in the class or namespace 'System.Runtime.Remoting.Channels' (are you missing an assembly reference?)
If I compile the code via the command line CSC filename.cs it compiles without problems and it works properly. I just can't seem to compile it in VS.
Any ideas?
Thanks,
Rick
|
|
|
|
|
You need to add a reference to System.Runtime.Remoting.dll
- monrobot13
|
|
|
|
|
Thank you very much! You solved my problem!
|
|
|
|
|
Everyone,
I have a unique problem where I need to perform paging on a datagrid. The catch is that my datasource for the datagrid is a DataView. The datagrid is loaded with a DataView stored in Cache. On a previous page, the user may have sorted or filtered the DataView. It gets stored in cache, now I need to page through the info as it is presented in the Dataview (sorted or filtered). thanks.
Courtney
|
|
|
|
|
I've been making stop and go progress on a test app that creates a .tif file. After fighting other problems (that have already been discussed here and elsewhere), I'm able to generate a .tif file that looks like it should, with the color depth it needs, and the compression scheme that it needs. The problem is that the app that comsumes the .tif requires tag 0x10a (Fill Order), and Bitmap.Save doesn't generate it by default.
At this point, I turned to SetPropertyItem(). I have been through the problems with creating a "new" PropertyItem, and am now opening another .tif file, so I can get a PropertyItem from it, tweak it, and set it in the new Bitmap. Even after this, however, the resulting file still doesn't contain the tag. It only contains the officially "required" tags. Isn't this what SetPropertyItem is for? Is there a better way to get optional tags included in the file?
|
|
|
|
|
I have created a dll to hook onto all keyboard events (WH_KEYBOARD). The dll seems to work fine and captures messages indicating print screen has been pressed. I have checked that it works as intended by using a counter which counts each time the hookprocess gets called, and then printed the value to a file, which showed a correct value. My C# program in turn which of course is a windows application retrives the message correctly, but ONLY when the window has focus. If it's hidden (hide()) or just isn't in focus, it doesn't seem to process the message.
The C# program starts by defining a custom window and from within it's constructor it installs the hook, and retrives a boolean indicating it's all fine. When the window is destroyed it's destructor uninstalls it. I use Windows XP pro SP1a.
Any help appriciated
|
|
|
|
|
I think this is maybe something to do with which thread you hook up to? - If you are importing the SetWindowsHookEx method from user32.dll it takes a parameter for the thread you want to hook into, maybe this is where your problem is?
|
|
|
|
|
|
The message arrives so I don't think it has anything to do with the thread id. But I will take a closer look .
|
|
|
|
|
I had a similair problem with windows hooks and it wasn't actually that the hook wasn't being fired, but in the callback function I was using readfile/writefile which apparently wasn't syncronizing right for multiple processes. So it was more of a process synchronization issue. I solved it using memory mapped files (which was more elegant anyway since it got rid of the need for a file at all for ipc).
|
|
|
|
|
Hi, anyone knows how to translate ASCII value ("int" = say, 53) into a "char"?
Thanks
norm
|
|
|
|
|
char MyChar = (char) someIntValue;
Cheers, Julian
Program Manager, C#
This posting is provided "AS IS" with no warranties, and confers no rights.
|
|
|
|
|
... how about....
char A = (char)65;
int i = 66;
char B = (char)i;
Best of luck - Bernd
|
|
|
|
|
I have a panel in my form which I set its BackColor the same as TransparencyColor of my Form so the contect behind the form is visible now.I want to take screenshot from the things behind panel.How can I get pixels behind it or get content of it as Image? I think I should get pixels inside client area of panel.Any idea?
Mazy
No sig. available now.
|
|
|
|
|
Regards,
I need familiarization with algorithms and methods that script/code parsers use to extract meaningful expressions from a plane text. can anybuddy reference me to some good resaources and examples?
Thanks in advanced,
-nSun
---
"Art happens when you least expect it"
|
|
|
|
|
You should look into Regular Expressions[^].
I passionately hate the idea of being with it, I think an artist has always to be out of step with his time.
-Orson Welles
|
|
|
|
|
nt
---
"Art happens when you least expect it"
|
|
|
|
|
Hi,
I want to know if I create a web service method in C# that returns a Dataset as it's return type, can a Java Client call it and retrieve it's values or do I need to convert it to some other object? Right now we have a Java Client that's calling the webservice, but she is getting null values for the return. I know the call is completed with no errors because I am logging the steps. Thanks in advance.
|
|
|
|
|
DataSet is a .NET framework class, it can't be handled in Java or other non .NET programs.
What you can do is write a new web method that returns a string generated by the data set (hint: the GetXML method of the DataSet class) and make your java code to call this new method.
My articles and software tools
|
|
|
|