|
|
Hi all,
Does anyone know how to determine which node of a treeview control the mouse pointer is over when a drop occurs? Maybe I am asking the wrong question: I want to allow the user to drag something from a listbox control onto a particular node of a tree view so that the dragged object can be added as a child node.
Any thoughts?
Thanks,
Bill
|
|
|
|
|
//Gets the point relative to the treeview
Point dragPoint = tv.PointToClient( new Point(e.X, e.Y) );
//Gets the treenode
TreeNode target = tv.GetNodeAt( dragPoint.X, dragPoint.Y );
|
|
|
|
|
It's always so simple once you know what the answer is.
Thanks.
|
|
|
|
|
I have 3 functions. All 3 the functions are identical except for a type and a function.
Now i want to combined all three into one. I assume it would be,
void CombinedFunction(Type type, SomeHandler function);
No the problem i have is, is that not all of the functions share the same parameters. All 3 have common parameters, but one has 2 extra parameters.
Would i HAVE to overload that function to pass any of the functions as a parameter.
Hope that makes sense
Thanx
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
|
O ya I solved this, noted though far down the optional parameter thread
The easier, better way was just to overload the function as the 2 optional parameters had fixed values when used in that context.
And...the function works beautifully
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
I am using regex (regular expressions) in my C# application. I am pulling out the first name like this...
Regex regName = new Regex( @"(?<Last>\S+), (?<First>\S+)" );
Match pMatch = regName.Match( "Doe, John" );
Text strFirst = pMatch.Groups[ "First" ].Value;
Question: If the user changes the name to 'Jane', how can I use regular expressions to replace the first name?
If strFirst = "Jane", then I want a new string to be "Doe, Jane".
Thanks!!
|
|
|
|
|
You'll want to use Regex.Replace, and then create a replacement string. Something like:
Regex regName = new Regex( @"(?<last>S+), (?<first>S+)");
regName.Replace (string, @"\k<last>, Jane");
The \k refers to whatever matched the "Last" capture.
If you're playing with regex, you might like this utility:
http://www.gotdotnet.com/userarea/keywordsrch.aspx?keyword=regular%20expression%20workbench
|
|
|
|
|
Eric, there's a link tool down at the bottom. Very handy. Just highlight and click link[^]
http://www.gotdotnet.com/userarea/keywordsrch.aspx?keyword=regular%20expression%20workbench [^]
David Stone
But Clinton wasn't a predictable, boring, aging, lying, eloquent, maintainer-of-the-status-quo. He was a predictable, boring-but-trying-to-look-hip, aging-and-fat-but-seemingly-oblivious-to-it, lying-but-in-sadly-blatant-ways, not-eloquent-but-trying-to-make-up-for-it-by-talking-even-more, bringer-in-of-scary-and-potentially-dangerous-new-policies. And there was also Al Gore. It just wasn't *right*.
Shog9
|
|
|
|
|
Is it safe to assume that anytime you do some sort of COM Interop with a dll that wasn't written using the .NET Framework that the method call needs to be prefixed with the unsafe marker, or is this only needed when the method deals with pointers that are outside the bounds of .NET to handle directly?
[System.Runtime.InteropServices.DllImport("kernel32.dll")]
unsafe int SomeFunction(....);
Nick Parker
|
|
|
|
|
U only have to specify unsafe if the compiler complains
No, but really unsafe only needs to be declared if you are using pointer notation in C# ( *, &, -> ). It is recommneded though (as far as I am aware) to use the Marshalling class as far as possible, else they wouldnt have called it "unsafe".
Cheers
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
leppie wrote:
U only have to specify unsafe if the compiler complains
Somehow I believe more people than you think use this method.
Nick Parker
|
|
|
|
|
Is it possible to make a method to have options parameters, without defining the function for each valid configuration?
Email: theeclypse@hotmail.com URL: http://www.onyeyiri.co.uk "All programmers are playwrights and all computers are lousy actors."
|
|
|
|
|
Not sure, however you could always overload the function.
Nick Parker
|
|
|
|
|
|
|
If you follow the C++ model, the default value is burned into your client-side code, and you can't update it without forcing the user to recompile.
We've talked a bit about whether you could have the compiler automatically generate the overloads that you would write yourself. Would that work for you?
|
|
|
|
|
|
That would be awesome! Get's my vote...tell Anders that.
David Stone
But Clinton wasn't a predictable, boring, aging, lying, eloquent, maintainer-of-the-status-quo. He was a predictable, boring-but-trying-to-look-hip, aging-and-fat-but-seemingly-oblivious-to-it, lying-but-in-sadly-blatant-ways, not-eloquent-but-trying-to-make-up-for-it-by-talking-even-more, bringer-in-of-scary-and-potentially-dangerous-new-policies. And there was also Al Gore. It just wasn't *right*.
Shog9
|
|
|
|
|
Eric Gunnerson (msft) wrote:
We've talked a bit about whether you could have the compiler automatically generate the overloads that you would write yourself. Would that work for you?
Yes!
You should definitely keep talking about that. This and the lack of (obvious) documentation around Attributes are my two biggest whines about C#/.NET.
There's little more irritating than having a function with 6 optional arguments and having to write 6 one-line overloads which in reality take up 30 lines and give you 6 more paths for testing.
Paul
|
|
|
|
|
Eric Gunnerson (msft) wrote:
We've talked a bit about whether you could have the compiler automatically generate the overloads that you would write yourself. Would that work for you?
Definately.
Nick Parker
|
|
|
|
|
You could always rewrite a function like this:
void Function(string name, int size, Color color, params object[] optionalparams){}
Then u have "infinite" overloads, yet alot of work to do.
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
leppie wrote:
void Function(string name, int size, Color color, params object[] optionalparams){}
Ha! Yeah. 2 minutes to write the function (assuming you dont feel a need to validate the parameters) and then when you want to use it six months down the line you have to go back and figure out what constitutes a valid argument list.
I'd have to be pretty desperate before I resorted to that
What I'm doing now is squeezing the overloads into a region and hiding them away (it's actually the pile of useless code to hunt through that bothers me more than writing it).
Paul
|
|
|
|
|
pdriley wrote:
I'd have to be pretty desperate before I resorted to that
Me too
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|