Hi Raeldor,
Can you tell me in which control's paint event you called the menu items
disable/enable code?
Yes, normally, Paint event is only fired when part of that control needs
to
be repainted. Usually, this is triggered when part of this control is
overlayed by other form/control and reappear again. So it is likely that
when you are pressing the shortcut key, the Paint event is not fired yet,
which causes the menu item to be not updated. I assume this is your
problem.
Normally, we should not place the menu items status change code in the
paint event, because this will delay this code logic execution to the
paint
event. So the solution to your problem lies with what program logic you
used to change menu items status. You should execute the status change
code
immediate after certain condition is changed. This is the correct
solution.
For example, your logic may be that: if the focus is in TextBox control,
you should enable the menu item, otherwise, you should disable it, then
you
should execute the status change code in TextBox.Enter and TextBox.Leave
events.
Ok, I see that your concern may be that there are several conditions the
code need to check, so using my suggestion, you have to place the code in
all the condition events/methods.
Yes, I understand this concern. I think you have 2 reasons to this
concern:
1. Executing the methods in several conditions may have performance issue.
2. Place code in multiple places may be hard to maintain.
#1 is not a problem, placing the code in Paint event will have much worse
performance result because Paint event is fired many times.
Regarding #2, I recommand you place the conditions check and status change
code in a single method, then in all the places, you may only change
certain condition flag, and just invoke this single
conditions-check-and-status-change method. This will allow you to
maintain
the code in a single method and get rid of the delay update problem.
Hope this helps.
Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.