|
I read a book about c# called<microsoft visual="" c#="" core="" reference="">. I find delegate is harder to master than c++'s pointer... I dont know why everybody say that c# is easier to use than c++. sigh...
|
|
|
|
|
Actually,if c# has pointer instead of delegate. It will be perfect
|
|
|
|
|
What don't you get about delegates in particular?
- Nick Parker My Blog
|
|
|
|
|
A delegate is a managed function pointer, and even offers several advantages. First, when compiled (for compilers that support this, as the C# compiler does) the compiler automatically generates asynchronous invocation methods! You can't beat that!
Take the following declarations in C:
BOOL CALLBACK EnumProc(LPCTSTR s);
BOOL EnumSomething(EnumProc proc); In C#, this would look like:
public delegate bool EnumProc(string s);
public bool EnumSomething(EnumProc proc); When you call EnumSomething , you would do so in a similar manner as with C:
bool val = EnumSomething(new EnumProc(MyEnumProc));
private bool MyEnumProc(string s)
{
Console.WriteLine(s);
} In the implementation for EnumSomething , you could even use BeginInvoke instead of Invoke (or the shorthand way where you just use the delegate parameter like a function) for asynchronous invocation.
See Handling and Raising Events[^] and Including Asynchronous Calls[^] in MSDN for more information, in-depth topics, and plenty of examples.
Also, just so you can see there really isn't much different, when interop'ing methods that require a function pointer or P/Invoke functions that require function pointers, a delegate is what you use in lieu of an IntPtr . When the param is marshaled, it is marshaled as a function pointer.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Wow! Thanks Heath. I seem to learn something new each time I read one of your posts. I never knew that you could do Asynchronous calls on delegates.
--Colin Mackay--
EuroCPian Spring 2004 Get Together[^]
|
|
|
|
|
Yep, just a word of warning, though - if the delegate is declared in the current project, the BeginInvoke and EndInvoke methods don't show up in IntelliSense but they're there! If you read the second article link, you can see the generated signatures of those methods; or, you could always compile your project once and examine the method signatures with ildasm.exe.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Hi,
this might be a bit of a backwards question but
i want to be able to test if an app has a manifest/themes is enabled
the reason is that i want to make my own controls render with xp style only if the app is supposed to be themed
i need to do this in .net 1.0
any pointers on how to accomplish this ??
(i already have my xp painting code in place , i only need to check if i should enable it or not)
//Roger
|
|
|
|
|
P/Invoke the native method IsAppThemed . Since this is only supported in Windows XP and higher, you can either catch the DllNotFoundException that is thrown in earlier platforms, or use the OSFeature class like below:
public class Test
{
[DllImport("uxtheme.dll")]
private static extern bool IsAppThemed();
public bool Themed
{
get
{
try
{
Version v = OSFeature.Feature.GetVersionPresent(OSFeature.Themes);
return v != null;
}
catch { return false; }
}
}
}
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Hi
I am trying to customize by label text by using Graphics.DrawString function. I use it withing the Paint Event Handler of the label (On_Paint() Function in my case). When the form gets loaded, the graphics comes correctly. To update the graphics when the text for label gets changed, i tried calling label1.Invalidate(); and label1.Refresh(); . In both the cases nothing happens...it seems as if the function On_Paint() is not getting executed....
Am I missing an important aspect of GDI Classes or Event Handlers? Please clarify me....
Thanks
Muralidhar
|
|
|
|
|
Is the handler really not getting executed, or does it just seem that way? Put a break point in it or use System.Diagnostics.Debug.WriteLine in your handler and watch your output window when debugging. Control.Refresh will invalidate the client region and force a repaint. So long as you're not removing your PaintEventHandler for the label, it will get called.
Also, if all you're trying to do is modify the text, you might consider encapsulating this into your own class that extends Label . For instance, say you want to prefix the text that's assign the parameter, you could do something like this:
public class MyLabel : Label
{
public override string Text
{
get { return base.Text; }
set { base.Text = string.Concat("Prefix: ", value); }
}
} The default behavior will do the rest, such as painting. If you're trying to control the style of the font, you can use the Label.Font property (inheritted from Control ).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Thanks a lot...
That worked...I have written a class derived from label...
|
|
|
|
|
Hi all,
I have this code that loads-up some plugins(dll files), and I'm having trouble executing them.
Every plugin has a ExecutePlugin(string Commands) method defined.
So when I wan't to execute all of my plugins from my main program I have this code:
foreach ( Type DllType in Plugins )
{
ICowPlugin Plugin = (ICowPlugin) Activator.CreateInstance ( DllType );
Plugin.ExecutePlugin ( "Plugins rox" );
MessageBox.Show ( Plugin.PluginName );
}
and strange is that the MessageBox.Show(Plugin.PluginName); indeed shows the name of the plugin, but code inside of ExecutePlugin() is aparently not executed.
I have a simple MessageBox.Show() inside the plugin's ExecutePlugin and the message box is not shown
Q:What does the derived class in C# tell to it's parent?
A:All your base are belong to us!
|
|
|
|
|
Try debugging your application. Put a breakpoint on the Plugin.ExecutePlugin statement, as well as on the first statement in the implementation of ICowPlugin.ExecutePlugin . As long as all your assemblies are compiled with the DEBUG preproc def (i.e., a Debug build) and loaded into your solution, you should have no problem determining if the method is actually executed (and it should be if no exception is being thrown, which doesn't seem to be the case since the next statement is executed) and if something is going wrong inside the method. An exception might be thrown in the implementation that you're also catching and returning from, so maybe you're not getting the results you want. Debugging this method will help determine the cause of the problem.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Hi, Im relativlly new to C#, so I dont really know what to look for.
THe method aparently works just fine and is "error-less" becouse when I compiled the plugin the compiller didn't return me any warnings or errors.
THe ExecutePlugin inside the plugin looksliek this:
public void ExecutePlugin ( string Commands )
{
MessageBox.Show ( Commands, PluginName );
}
and liek I said I cen get the PluginName property inside my main programm, but the messagebox dosen't show ...
Q:What does the derived class in C# tell to it's parent?
A:All your base are belong to us!
|
|
|
|
|
I am just starting out with C# and want to know how can I tell what kinda of project the code was started from by looking at the code. and by project I mean when you create a new project, from the wizard....
Thanks
Ralph
|
|
|
|
|
Mostly, look at the class that's generated. If it extends System.Windows.Forms.Form , is most likely a Windows Forms property. If it inherits from System.Windows.Forms.UserControl is a user control project. If it just includes a static Main method and not much else, it's probably a console application. If you have a bunch of web forms (.aspx files) then you've got a web project. The best thing you can do is just start playing around with the different types and see what's generated, as well as read some of the articles in the .NET Framework SDK. There's also samples and tutorials out there.
Also, don't forget that CodeProject is a great resource and has many articles that often go in-depth into the technologies they target such as Windows Forms or ASP.NET.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
I have to change my report at runtime
how to I can do it?
(I use CrystalReport 9)
please help me.
|
|
|
|
|
Define "change". If you mean change the layout, the ReportDocument has a property, ReportDefinition , that gets you the collection of sections, etc. I'm not sure how much of this you can change at runtime, but you might be better off asking in the Crystal Reports forums at http://support.businessobjects.com/forums/default.asp?ref=devzone_main[^].
If you mean to change the data source on which to report, see the ReportDocument.SetDataSource method. Designing your reports to use disconnected DataSet objects (especially strongly-typed ones that you can build report defintions from) makes reusing your reports on different systems and with different database easy!
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Hi
We have an MDI application, where we would like to limit the possible locations of the MDI child forms.
Is it possible to set up some kind of borders that limit child location to some part of the client area?
Currently we simply move the form back inside the borders if it dragged outside of the borders. Unfortunately, this has some sideeffects (e.g. client form can be moved far outside the borders before the moved event is raised)
BTW: Is it possible to disable the scroll bars that appears on a MDI parent?
Thanks, Mads
|
|
|
|
|
Yes, you can fix the Child form location MDI form.
You have to set the following properties in Child form
Form Location
Form Border = none
Control box= false
MaxBotton=false
MinBotton=false
Window Startup position=normal
Regards,
Amal
amal_forum@hotmail.com
|
|
|
|
|
Thanks for your reply - but wouldn't that make the form unmoveable? What we want is to be able to move the form around within a limited area.
|
|
|
|
|
You can set the child form boundry in Child form MOVE event.
Regards,
Amal
amal_forum@hotmail.com
|
|
|
|
|
Hi, I want to ask if there is in .NET an similar technology to the Java Applet/Servlet. And if such a thing exists pls help me with some documentation resources.
Thanks a lot.
|
|
|
|
|
refer the following URLs
www.gotdotnet.com/team/compare
http://java.oreilly.com/news/farley_0800.html
Regards,
Amal
amal_forum@hotmail.com
|
|
|
|
|
I wrote an article a long time back on another site that I'm working on porting to CodeProject as a new series. See http://www.devhood.com/Tutorials/tutorial_details.aspx?tutorial_id=388[^] for more information about hosting .NET controls in a web page. If exposed as COM control correctly (which the articles covers), you can even script them and handle events.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|