|
Doh!
Yep, another one of those errors.
For some reason I was reading 'parallelogram' as 'polygon' - which meant that the four points I was putting in was causing it to choke. Ugh. After actually reading the documentation on that function, it's working.
Thanks for the help Chris.
|
|
|
|
|
Hi all. I am trying to modify some code that clears other textboxes on a form when the user starts entry in a textbox.
So I'm handling the KeyDown event of each textbox and clearing the others. But I don't want to clear the other boxes when a CTRL or ALT key is pressed (unless something is pasted into the textbox, which is my problem) so that the user can use shortcuts and such when focused on a textbox.
The code I'm using is:
if (((Control.ModifierKeys & Keys.Alt) != Keys.Alt) &&<br />
((Control.ModifierKeys & Keys.Control) != Keys.Control))<br />
{<br />
}
The problem is that it skips over the stuff it needs to do when a CTRL-V is invoked. How can I handle that while still keeping those CTRL and ALT checks in there.
Thanks for any help.
|
|
|
|
|
It's possible to detect if both CTRL and V are pressed at the same time, just extend the if statement. But I think you are better off all together if you use the Change event instead.
|
|
|
|
|
Hello
I'm looking the best Idea to compare a value with an operator <,>,<=,>=,=,!= defined from a combo and a operand defined in a textbox
Of course I can make a switch case but considering I've billion value to compare with the same operator I'm looking if there not another approach to do it !
|
|
|
|
|
Hi,
if the billion operations all take the same operator, use a switch but repeat
the loop inside each of the cases (hence the switch gets executed only once).
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Thank you
But as long I have many other thing to do with my record set your solution will duplicat too many code for for each possible choice
I was thinking about a delegate but I've never defined a delegate !
|
|
|
|
|
delegates are called from of their parameter input signature..
I don't see how it would be of use in this case. Your combo box will have the same data type per each selection, though the value will be different.
|
|
|
|
|
The idea was to define 6 comparaison function
==
<
<=
>=
etc.
and get a delegate on the one needed in the session
Can it be ?
|
|
|
|
|
There isn't anything to distinguish them. Your combo box most likely has a string value of what the user picked such as "==", "<", "<=", ect..
This means that all 6 delegates would have the signature of: <return value=""> <method name="">(string str);
If you need to loop though a method then a recursive function (one that calls itself) with a input parameter would solve the situations based off the value.
This is about the same as looping within a switch statement, just not as much similar code.
To put it bluntly, you are trying to minimize code that is almost at its minimum state
The above is going by your statements about said code, less examples of what you're doing this is about as far as we can go.
|
|
|
|
|
Hello
But I'm not talking about create 6 delegate
I think to define 6 function
And create a delegate for the one needed as a function pointer
public bool cmpEqu(int a, int b)
{
return (a == b);
}
private bool cmpGrtEqu(int a, int b)
{
return (a >= b);
}
private bool cmpLessEqu(int a, int b)
{
return (a <= b);
}
etc..
public delegate bool MyCompare(int a, int b);
MyCompare Comp = new MyCompare(cmpLess);
Can it be ?
|
|
|
|
|
Yes a delegate works like a function pointer.
In your above example you can have
public bool cmpEqu(int a, int b)
{
return (a == b);
}
private bool cmpGrtEqu(int a, int b)
{
return (a >= b);
}
private bool cmpLessEqu(int a, int b)
{
return (a <= b);
}
public delegate bool MyCompare(int a, int b);
MyCompare cmpLess = new MyCompare(cmpLess);
MyCompare cmpLessEqu = new MyCompare(cmpLessEqu);
MyCompare cmpEqu = new MyCompare(cmpEqu);
MyCompare cmpGrtEqu = new MyCompare(cmpGrtEqu);
That is if you wanted to inherit from the class and then associate to an unknown named method...
Maybe I just don't understand what you're asking, but I don't see how this could solve the original problem posted.
|
|
|
|
|
Hello
It solve the problem
When I post the question I had no idea about the way to declare a delegate
In fact BEFORE to run the loop I just have to declare the right delegate that will be used along the loop
So I make a switch case to get the right one
Case ThisCompare:
MyDelegate compare=new MyDelegate(CompareForThis);
And that's it !
|
|
|
|
|
If you solved your problem
|
|
|
|
|
Maybe a recursive method that does the proper calculation based off the correct parameter input. Just be careful not to infinite loop yourself.
|
|
|
|
|
Hi All,
Can anyone tell me what the meaning of '?' in c# is?
Thanx.
|
|
|
|
|
It depends whereabouts it is.
1. In a variable definition, e.g. int? myValue = null; The ? means that the int is nullable (i.e. it can be set to null)
2. In a ternary operator, e.g. bool myVal = (item > 2 ? true : false); This reads, if item is greater than 2, then set myVal to true (otherwise set it to false).
3. As part of something called the null coalescing operator, e.g. int myVal = someValue ?? 1; This means, if someValue is not null, then set myVal to this value otherwise fallback to set it as 1.
|
|
|
|
|
Pete O'Hanlon wrote: bool myVal = (item > 2 ? true : false);
Pete O'Hanlon wrote: int myVal = someValue ?? 1;
the force has gone...
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
OK - and your problem here is?
|
|
|
|
|
After quite some time (> 2 years) of C# programming I still didn't know about the ?? operator, thanks for that
What Luc probably means is that bool myVal = (item > 2 ? true : false); can be simply expressed as bool myVal = item > 2 , so the example for the ternary operator probably wasn't the best.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Greeeg wrote: What Luc probably means is that bool myVal = (item > 2 ? true : false); can be simply expressed as bool myVal = item > 2, so the example for the ternary operator probably wasn't the best.
It was just a simple example. Judging by the level of the OP question, I figured this was about as much as he could handle. I rather suspect that Luc's objection has more to do with the fact that the ternary and coalescing operators actually lead to unclear code.
|
|
|
|
|
I think it's clear as anything else, I mean this operator is in most any C-style language: C#, Java, JavaScript, PHP, Ruby, Verilog, and others..
I have seen the ternary operator abused such as the following:
public bool myMethod()
{
bool myBool;
return (myBool==true)?(true) : ((myBool==false) ? false:true);
}
Greeeg wrote: I still didn't know about the ?? operator, thanks for that
Just so you know, unless you are interacting normal types with nullable types the ?? operator isn't worth much. It doesn't surprise me if you've never seen it before. It is one of those things that you won't know until you need it.
Edited to show I was talking to Greeeg about the ?? operator
modified on Monday, April 21, 2008 4:48 PM
|
|
|
|
|
SpacixOne wrote: Just so you know, unless you are interacting normal types with nullable types the ?? operator isn't worth much. It doesn't surprise me if you've never seen it before. It is one of those things that you won't know until you need it.
I suspect this comment was addressed at Greeg. Perhaps it should be put there.
SpacixOne wrote: I think it's clear as anything else, I mean this operator is in most any C-style language: C#, Java, JavaScript, PHP, Ruby, Verilog, and others..
The problem with the ternary operator is once you start using it, it's just so easy to overuse. I've seen code that has ternary operators nested inside ternary operators - all because somebody couldn't be bothered to type a couple of if/else statements in. Plus - newbies don't tend to know what it means.
|
|
|
|
|
Hi Pete,
there has been a horror thread not so long ago on the redundancy of myBool ? true : false
which just equals myBool
and IMO the other one does not compile, I expect ?? needs references, but your example
starts with int
Hence I must conclude the geordie beer has taken its toll.
After a good night sleep the force may be back though.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
OK - I was trying to put in a simple example for the ternary operator. I'm one of the haters of myBool ..., but it was such a trivial example that it didn't seem an issue here - oh well.
Luc Pattyn wrote: and IMO the other one does not compile, I expect ?? needs references, but your example
starts with int
Errm. It will compile - the ?? tells the compiler to fall through from the first value (if it's null) to the second one. Here's an example:
int? myValue = 2;
int itemVal = myValue ?? 10; The force is still strong with this one youngling.
|
|
|
|
|
Aha, the int? comes to the rescue.
I never got used to nullable types, I lived too long without them.
So I do like the ?? operator but the only usage I have for it is with references,
as in object obj=myObject??myDefaultObject;
I stand corrected by a true jedi
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|