|
hi
i am a newbie to c#
I hav a string which contains a function name and i hav some arguments for the fuction.Now how do i apply that fuction to those arguments
for example
i hav a string called func
and func="mywriteline" where mywriteline is a fuction. Now is there a way to apply this function
to the arguments which i hav in some other array
|
|
|
|
|
To accomplish this you'll have to use reflection to find the MethodInfo of the method you want to execute.
I'd suggest you read the documentation on the Type class, there are several overloaded GetMethod() methods that can give you a MethodInfo for a method name.
Once you have the correct MethodInfo you call one of it's Invoke() methods to actually execute the target method.
Arguments for this method are supplied in the form of an object array, if any.
One thing you'll have to keep in mind: You can't just "apply a function", you always need an object to execute one of it's methods (it's a parameter for MethodInfo.Invoke() ).
This code fragment should help:
MyObject obj = new MyObject();
MethodInfo mi = obj.GetType().GetMethod(func);
object[] arguments = new object[] { "arg1", 42 };
object result = mi.Invoke(obj, arguments);
Regards,
mav
|
|
|
|
|
hello iam using win xp os. I want to send a message to the user from my c# application before windows shut down how can i ??? plz help me
|
|
|
|
|
You have to register an event handler for the SessionEnding event of Microsoft.Win32.SystemEvents .
Then you'll get a notification when Windows is being shut down and you can pop up a message and cancel the shutdown process or do whatever you need.
Regards,
mav
|
|
|
|
|
Thanks for ur response.
i was doing like this
1.How can i cancel shut down process
private void HookSessionEnding()
{
Microsoft.Win32.SystemEvents.SessionEnding += new Microsoft.Win32.SessionEndingEventHandler(this.OnSessionEnding);
}
private void OnSessionEnding( object sender,Microsoft.Win32.SessionEndingEventArgs e )
{
MessageBox.Show("System Shut Down");
}
|
|
|
|
|
Could any one help me with this, im suppoused to make an application which draws polygons given the radius, center and number of sides. I know that the function polygon does this, but i have to this with out using it, any help with the algorithm which helps me determine the vertices would be greatly appreciated.
|
|
|
|
|
Your dog wants steak wrote:
any help with the algorithm which helps me determine the vertices would be greatly appreciated.
Surely you were given the mathematics behind this in your class? If so then it should be fairly easy to translate that into code. Is there any particular part of the translation you are having trouble with?
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!
|
|
|
|
|
Nope no help with the math part in class, Im stuck with a math teacher in computer aided desing class who thinks we should learn to program in c# little applets that dont do squat. In this case he wants us to program a little program that calculates the vertices of a n sided polygon given the radius and the center. Big big problem even more because we learned to program on c++, only two clases and he thinks this is "easy". Well if you know of some place else where i could find help with my little math project... greatly appreciated
|
|
|
|
|
Okay, my high school maths is a bit shakey these days but I'll give it a go.
The method that draws polygons takes an array of Point objects as each of the points. So for n vertices you need n points (although strictly speaking the first and last point are the same windows will draw the final vertex back to the starting point for you)
A complete rotation is 2*Math.PI. So each step will be:
rotationStep = (2*Math.PI)/numVertices
start the currentRotation at 0.0
for each point the
x = centreX + (sin(currentRotation)*radius)<br />
y = centreY + (cos(currentRotation)*radius)
You should now have a Point array which you can pass to the System.Drawing.Graphics.DrawPolygon() method.
Hopefully this maths should be enough to get you going.
Good luck with your class.
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!
|
|
|
|
|
me thinks u mixed cos and sin:
Colin Angus Mackay wrote:
x = centreX + (sin(currentRotation)*radius)<br />
y = centreY + (cos(currentRotation)*radius)
should be:
x = centreX + (cos(currentRotation)*radius)<br />
y = centreY + (sin(currentRotation)*radius)<br />
there are no facts, only interpretations
|
|
|
|
|
But like I said "my high school maths is a bit shakey these days", so, at least I did warn that the answer might not be completely valid.
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!
|
|
|
|
|
don't get angry, high school sucks anyway. and it doesn't matter for his polygon i think, but a math teacher might get annoyed
there are no facts, only interpretations
|
|
|
|
|
yoaz wrote:
don't get angry
I didn't.
yoaz wrote:
it doesn't matter for his polygon i think
Because it is circular, rather than ellipsoidal I think that's also correct.
yoaz wrote:
but a math teacher might get annoyed
Quite probably.
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!
|
|
|
|
|
I'm having problems enlarging images using the Graphics object. The quality of the enlarged images is bad. I get the best results by setting the interpolation mode to nearest neighbor and pixel offset mode to high quality. Even then, the image is grainy. Here's an example:
protected override void OnPaint(PaintEventArgs e)
{
if(this.image != null)
{
RectangleF source = new RectangleF(0f,0f,0f,0f)
RectangleF dest = new RectangleF(0f,0f,0f,0f)
dest.X = e.ClipRectangle.X;
dest.Y = e.ClipRectangle.Y;
dest.Width = e.ClipRectangle.Width;
dest.Height = e.ClipRectangle.Height;
source.X = dest.X / zoom;
source.Y = dest.Y / zoom;
source.Width = dest.Width / zoom;
source.Height = dest.Height / zoom;
e.Graphics.InterpolationMode =
InterpolationMode.NearestNeighbor;
e.Graphics.PixelOffsetMode =
PixelOffsetMode.HighQuality;
e.Graphics.DrawImage(image, dest, source,
GraphicsUnit.Pixel);
}
if(deleg != null)
deleg(this, e);
base.OnPaint(e);
}
Basically, what I'm looking for is something like a simple pixel resize. I've tried doing this manually, but with bigger images it takes a lot of resources. Any ideas?
|
|
|
|
|
jacal99 wrote:
the application gole is to hook the keyboard when the service starts and create a file on d:\123.txt and save all the pressed keys in this file
It sounds like you are creating spyware. If that is the case, do you really expect much help?
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!
|
|
|
|
|
i never thought how you response ... in my mind this was for only for learning pourpose ... not for a sh*t things
Mazhar Hussain
|
|
|
|
|
jacal99 wrote:
in my mind this was for only for learning pourpose
If you can explain why you would need to learn this, if not for learning to creating spyware, then someone might help.
Perhaps your goal is to learn how to use Windows Services (rather than capturing keys). If that is the case then there are many other things a service could be doing that would teach you how they work.
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!
|
|
|
|
|
hi
i want design setup for my program.but i dont know what i do?
please help me
thanks
|
|
|
|
|
Hi,
You mean that you want to create a setup file for your program.Am i right ?
In VS.Net you can see Setup and Deployment once you start a new project. ie, File -> New Project -> setup and deployement. Form there you can choose setup project template. Once you choose this template then IDE will give you a file system tab with three folder called application folder, user desktop and user program menu.
Once you seen this much information then you can add your project(application ) into this using File ->Add -> projects -> Existing project.
Here you need to mention the directory where you kept your project and select the solution file and press ok once you locate the solution file.
Now you added your project file to the setup project. You can see the project file if you click on the solution explorer.
Now right click the application folder which is listed in the file system tab and choose add then the project output.
Application Folder -> Add -> project output. Hold the ctrl key and select all information except Debug symbol and source files. Then click ok to continue.
Then use ctrl+F5 to build your setup. Now you can view the setup file is there in Debug folder of your setup project. I know that this is not sufficient. But still you need to adjust with this. Better go for microsoft site their you will get step by step explanation with screen shots.
**************************
S r e e j i t h N a i r
**************************
|
|
|
|
|
Can anyone give me a simple example of how to send information (eg the data stored in a Color variable) from an MDIChild to an MDI Parent?
THanks
Finn
|
|
|
|
|
Forms have a property called MdiParent . When the form is being used as an MDI Child it is used to access the parent. You must cast the value returned to the correct class, unless all you are interested in is only the functionality exposed by .NET.
Assuming your parent form class is called MyForm , and the value is accessed through a property called SomeProperty the code might look something like this:
MyForm parent = (MyForm)this.MdiParent;
parent.SomeProperty = someValue;
Does this help?
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!
|
|
|
|
|
yes it does!
thanks!
|
|
|
|
|
i'm looking for e component in c# that in like a textbox but it just accept 0 and 1 input's .
|
|
|
|
|
catch the keypress event and discard all keys that are not 1 and 0 by setting Handled to true. look her for more information: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemWindowsFormsControlClassKeyPressTopic.asp
|
|
|
|
|
hi.
started with a little hyperlink import tool 2 my mysql db ... now i am stocked.
problem :
i have an string[] with paths of the *.url files my prog found in a given directory. now i would like
to read out the title/name of the hyperlink an also its webadress so i can later import those infos. all things i´ve tried didnt really solve my wishes or went completly wrong.
anyone out here, who can give me a hint ? for me, it looks like i didnt find the right class/method to manage the url/bookmark file handling. tried also google and different c# sites but seems no one ever works with urls or its so easy ...
any help or idea very welcome
|
|
|
|