|
As title really, i have an app with the ability to drag an item from a list box onto another grid type control, i can drag and drop no problem, i can also get the x,y coords of the mouse within the control when not dragging, but i need to get them when i have dropped the item onto the grid control. the problem is, the coords i am getting are not the withing the control but the screen ( i think ) any ideas how i can covert to the controls coords or how to get the coords from the control ??
Thanks in advance
Lee
|
|
|
|
|
hi
Point point = MyControl.ScreenToPoint(new Point(e.X, e.Y));
regards
|
|
|
|
|
i cannot see a function ScreenToPoint i have PointToScreen and PointToClient but not the otherway round ?? am i missing something here ??
Thanks
|
|
|
|
|
you want PointToClient
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
thanks, i finally sussed it after reading the first response... i just used
Point pt = Control.PointToClient( new Point( e.X,e.Y ) );
Thanks for the responses..
|
|
|
|
|
Hi All,
I have some block that occur in my catch ( try...catch ), this block is repeats a lot of time ( with different message but beside this message all the rest are the same ).
In C++ i would replace this block with some #define - but in C# i cant use ( of course ) this define.
My question is is there is something else that i can use to save line code in my project ?
Can i use something else beside writing all those 4 line in the block again and again and .... again....
I know that i can write some method and call it all the time - but i looking some other way.
Thanks for any help
|
|
|
|
|
No there is not.
"#define IDENTIFIER" is available for conditional stuff, there is no DEFINE
for code substitution.
go with the method !
And if you want to show the exception, show it in its entirity, that is
with ToString(), everything else sucks.
What's in those four lines anyway ?
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Yanshof wrote: I know that i can write some method and call it all the time
Well, why not?
Yanshof wrote: but i looking some other way
Why? What advantage do you think you will get?
Upcoming events:
* Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ...
"I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless."
My website
|
|
|
|
|
Colin Angus Mackay wrote: Why? What advantage do you think you will get?
#define in C/C++ is a code obfuscater. Obfuscated code is job security.
--
You have to explain to them [VB coders] what you mean by "typed". their first response is likely to be something like, "Of course my code is typed. Do you think i magically project it onto the screen with the power of my mind?" --- John Simmons / outlaw programmer
|
|
|
|
|
You can use #if, #else if #else inside the code, and you can #define some constants either at the very beginning of the file or in the project properties
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Use a method and/or derive your own type of Exception.
On the other hand... The "C preprocessor" can be used with any type of text file, not just C/C++ source files. I do use it with C#, but only to prove the point.
|
|
|
|
|
Hi All,
I am developing an application where a vehicle's route will be tracked by Microsoft MapPoint. Recently, it gives me an error message box - "Server Busy" and it has 2 option buttons "Switch to" and "Retry".
I have searched in Google and they say that it occurs when - the COM object(here MSMapControl) is not responding within a time period. They all suggest to set
"app.OleRequestPendingTimeout" to a higher value. But this is in Visual Basic and this object is not supported in C#.
Can anyone tell me how can i do this in C# ?
Thanks
Chayan
|
|
|
|
|
Hi everyone,
I'm looking for a nicer way to invoke methods. The following code is called by:
Fetch(someObject, "GetCustomer", 1) .
The ugly thing about this is that the name of the method is passed as a string. Is there a way to support something like:
Fetch(someObject.GetCustomer, 1) ?
I tried to use generic delegates, but had trouble with params object[] args as parameter and with the encapsulation inside the Fetch method...
Thanks in advance
glFrustum
<br />
public object Fetch(object target, string methodName, params object[] args)<br />
{<br />
return target.GetType().InvokeMember(<br />
methodName, BindingFlags.InvokeMethod, <br />
null, target, args);<br />
}<br />
|
|
|
|
|
|
Thanks, but this article describes what I'm trying to avoid
(Passing methods as string)
|
|
|
|
|
You can dynamically load an assemble and then invoke a method in it.
Step one. Create an interface that defines the methods you want to call.
Step two. Create an static readonly variable of that interface.
Step three. Use the variable to call methods.
Microsoft calls this a strategy.
If you want to be totally dynamic. There is a methodinfo class that you can get all the methods from a type.
Hope that helps.
Ben
|
|
|
|
|
I was looking for a solution that doesn't affect the called methods;
something like a generic delegate that 'eats' everything would be fine!
Don't you have to use the method name as string to get the MethodInfo?
I tried to avoid this.
|
|
|
|
|
glFrustum wrote: I'm looking for a nicer way to invoke methods. The following code is called by:
Fetch(someObject, "GetCustomer", 1).
The ugly thing about this is that the name of the method is passed as a string. Is there a way to support something like:
Fetch(someObject.GetCustomer, 1)?
Im still searching for the reason why you think the latter is preferable to the former. In answer to your question, if all the methods you want to call from your Fetch method have the same signature you could use delegates insstead of reflection (which identifies methods/properties the same way you do - by name).
eg. Say this is a data layer you are writing and the Fetch method is responsible for getting data from a vasiety of methods which follow this signature:
DataSet SomeGetDataMethod(object [] parameters)
you would define a delegate along the lines of
public delegate DataSet GetDataDelegate(object[] parameters);
You would then define your Fetch method as follows
public DataSet Fetch(GetDataDelegate method, object[] parameters)
{
method.Invoke(parameters);
}
Then to call this method you could have:
object[] parameters = new object{ 1 };<br />
Fetch( new GetDataDelegate(someObject.GetCustomer), parameters)
you could then pass a delegate to any of your data methods into this fetch method without using reflection.
Personally id stick with reflection!
|
|
|
|
|
Thanks for the feedback. I'd prefer the latter, because the string could cause troubles (renaming of methods etc.).
Also, using
someDelegate.DynamicInvoke(args)
could be faster than
target.GetType().InvokeMember(methodName, BindingFlags.InvokeMethod, null, target, args); .
The problem is that the methods do not have similar signatures and I don't know how to implement a generic delegate that can handle all types of signatures (if this is even possible...).
Please let me know if you have any idea...
thx
|
|
|
|
|
glFrustum wrote: I don't know how to implement a generic delegate that can handle all types of signatures (if this is even possible...).
Its not.
|
|
|
|
|
One step into the right direction, at least for one argument:
<br />
public delegate object GenDel<T>(T t);<br />
...<br />
GetCustomerRequest args = new GetCustomerRequest(1, 2, 3);<br />
GenDel<GetCustomerRequest> del = new GenDel<GetCustomerRequest>(repository.GetCustomer);<br />
Customer c = (Customer)Fetch(del, args);<br />
...<br />
public object Fetch(Delegate del, params object[] args)<br />
{<br />
return del.DynamicInvoke(args);<br />
}<br />
<br />
Thanks a lot for the tips so far...
|
|
|
|
|
Hi..
I am developing one console application in C#.net, in which i want to split one big excel file having more than 50000 records in to 10 smaller files. Can you guide me to perform this task?
Waiting for reply.
Thanks.
Gurudatta B. Shelke
|
|
|
|
|
Use the OLEDB provider to read all the data into a datatable. Then, split the total rows how you want them, use the office interop to write the first set of rows to the specified file, and move on to the next.
user != use
I get all the news I need from the weather report - Paul Simon (from "The Only Living Boy in New York")
|
|
|
|
|
thanks for giving me the solution.
I have read the excel sheet into dataset using OLEDB provider. Now i m not getting how can i split into multiple excel files.
Do u have sample code regarding this?
Gurudatta B. Shelke
|
|
|
|
|
I don't have any code to give you, as I have never done that.
What I would do is:
1)get the total number of rows from your main table(the table you load all of your data into)
2)then create a worktable for storing rows to be written to a file.
3)create an integer(lets call this IHAVETOPEE), and divide the number of total rows by 10, and drop the remainder.
4)do a for loop to the number of total rows.
5)create a counter(iCounter) to record how many rows have been copied to the worktable, and written to file.
6)loop through, adding the current row to the worktable, and when the loop becomes == to IHAVETOPEE, write the worktable to file, and clear the worktable.
7)create an if statement for when the for loop is on it's last round
8)subtract the counter from totalRows
9) Inside the if statement, have another for loop, that will loop from the current row, to the total rows, and when the loop reaches the # from step 8, write to file
All of that will write to 10 files, evenly over all, plus a couple on the last file, because surely you will end up with a number of rows like 1983 some time
Hope that was clear
I get all the news I need from the weather report - Paul Simon (from "The Only Living Boy in New York")
|
|
|
|