|
there is no such . you must be unable to handle event properly.elaborate more about your control's desired behaviour and what do you want
|
|
|
|
|
adfgh75 wrote:
My problem is that I want to use UserControls in my application but whenever I add my UserControls to my windows form the form don't recieve any KeyDown events when I press the arrows keys, however it reacts to any other keys being pressed!
The key press is probably being handled by another control. Have you tried setting KeyPreview[^]to true
|
|
|
|
|
Well yes, I have set KeyPreview to true on the form (and breakpoints to trace the event)and it still doesn't throw any KeyDown event when when I press the arrow keys, but it throws it when I press any other key. If I let the class inherit from Panel instead of UserControl or Control it works perfect.
However I've discovered that if I override the ProcessCmdKey() function in the form and process the key pressed there instead it will work.
.NET
|
|
|
|
|
Hi,
Can you please let me know what is wrong with the following if statement?
I believe the following values should make the statement to show the messagebox.
Do you agree?
Thanks
intPosHomeUS= -1
intPosHostUS= 7
intPosHomeUK= 7
intPosHostUK= -1
if (!(intPosHomeUS > 0 && intPosHomeUK > 0) || (intPosHomeUK > 0 && intPosHostUS > 0))
{
//show messagebox...
}
else
{
//print report...
}
|
|
|
|
|
no problem it should work fine
|
|
|
|
|
firstly I think youve made a typo (either in your code or in transposing it to a post)
fmardani wrote: if (!(intPosHomeUS > 0 && intPosHomeUK > 0) || (intPosHomeUK > 0 && intPosHostUS > 0))
should that be
if (!(intPosHomeUS > 0 && intPosHomeUK > 0) || (intPosHostUK > 0 && intPosHostUS > 0))
if not, and its correct, I could break down the code as
if(! (false && true) || (true && true))
breaks down further as
if( ! (false || true) )
and once more as
if(!true)
so
!true == false
so your message box will not show.
|
|
|
|
|
Doesn't it evaluate to:
(!false || true)
rather than
!(false || true)
Which would of course trigger the message box? I tend to go overboard with the parens just to make sure I'm negating the right thing because of stuff like this.
|
|
|
|
|
eggsovereasy wrote: I tend to go overboard with the parens just to make sure I'm negating the right thing because of stuff like this.
me too!
In my post I am assuming (rather than have tested) that it is evaluated as
!(false || true)
rather than
(!false || true)
|
|
|
|
|
The negation operator (!) has a higher precedence than the logical or operator. I think you made a typo yourself when you went from steps:
if(! (false && true) || (true && true))
To:
if( ! (false || true) )
Personally, I would suggest just using the debugger and putting a watch in to see what exactly is going in. Put the full statement "(!(intPosHomeUS > 0 && intPosHomeUK > 0) || (intPosHostUK > 0 && intPosHostUS > 0))" and then break it down into pieces to find the error.
As a side note, I'm not a big fan of putting a negation like that because it always seems to trip me up (may just be me). So, I typically pass the negation through the set...so you'd have something like this instead:
if (intPosHomeUS <= 0 || intPosHomeUK <= 0 || (intPosHostUK > 0 && intPosHostUS > 0))
It's just DeMorgan's Law...you can find more about it here[^].
|
|
|
|
|
Andrew Rissing wrote:
As a side note, I'm not a big fan of putting a negation like that because it always seems to trip me up (may just be me). So, I typically pass the negation through the set...so you'd have something like this instead:
It tends to trip me up as well, but I prefer writing the exression in the intuitive 'as english' format and either using a temp var for the base expression and then notting the temp in the expression or switching the then and else clauses around to avoid the negation all together.
--
Rules of thumb should not be taken for the whole hand.
|
|
|
|
|
fmardani wrote: I believe the following values should make the statement to show the messagebox.
Yes, it should, and it does.
---
b { font-weight: normal; }
|
|
|
|
|
Is this a logic issue? I noticed that you're not checking for a value from intPosHostUK
|
|
|
|
|
Hi,
I need to know how can I create shotcut to myButton on form when I press key F10 independent of current active control on form, without using "ShortcutKey" in "ToolStipMenuItem".
I can do this if myButton is active control on form. I explicitly need to use key F10, so I can't use an & (ampersand) in a button text.
Thanks for help
|
|
|
|
|
handle key down or key up event of the form and then trigger click event by;
if(e.KeyCode == Keys.F10)
button1.PerformClick();
hope it helps.
Regards
Khalid
|
|
|
|
|
Hello,
And dont't forget to set:
this.KeyPreview = true;
All the best,
Martin
|
|
|
|
|
Thanks both, it really works.
|
|
|
|
|
Hi,
I have just one more question. Can I check if ALT+F1 pressed?
Thanks,
Jure
|
|
|
|
|
Hello,
Yes you can!
if (e.Alt && e.KeyCode == Keys.F1)
Hope it's not too late, but I didn't got your post.
All the best,
Martin
|
|
|
|
|
Thanks, it's not too late.
Thanks again,
Jure
|
|
|
|
|
Excuse me for being brief, but it is self explanatory.
So I make a query with linQ, and then try to make a 2nd query on the previous results, but there i get an error.
List<clsHotel> q = from d in dbGet.Hotels()
select d;<br />
<br />
if (chkHalfpension.Checked) {<br />
List<clsHotel> z = from x in q
where x.Naam == "Bon jour" <br />
select x;<br />
}
It returns the following error on that line:
Error 1 Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<hotelmanager.data.clshotel>' to 'System.Collections.Generic.List<hotelmanager.data.clshotel>'. An explicit conversion exists (are you missing a cast?)
If anyone could please help.
Thanks in advance !
-- Edit --
The weird thing is:
This code also doesnt works:
List<clsHotel> q = from d in dbGet.Hotels()
select d;<br />
<br />
List<clsHotel> z = from vx in dbGet.Hotels()
select vx;
It throws the same error, but the code is the same :s
Guess it's an bug in c#3.0 ?
-- modified at 8:18 Thursday 2nd November, 2006
|
|
|
|
|
instead of list, have you tried var?
|
|
|
|
|
Yes, keeps saying the same error.
I guess you can't do 2 of that select things in the same function, wich is to bad
|
|
|
|
|
Have you tried IEnumerable < string > < == remove spaces
|
|
|
|
|
This works ! (except i used clsHotel class, not string)
Thanks alot edboe !
|
|
|
|
|
Another option would be to create each search in a separate function/method.
|
|
|
|