OnPaint is missng between MouseDown and MouseUp (C# Compact framework)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pshilparani
    New Member
    • Dec 2010
    • 2

    OnPaint is missng between MouseDown and MouseUp (C# Compact framework)

    Hello All,

    I am working with Device Application( Compact framework) C#

    I have a class which creates grid with numbers on it some thing like shown below

    ------------
    | 1 | 2 | 3 |
    ------------
    | 4 | 5 | 6 |
    ------------
    | 7 | 8 | 9 |
    ------------
    | 0 |
    ------------

    Each cell is Rectangle object ( Rectangle array drawn on panel)
    I just want to highlight only the key clicked (same effect as in windows calculator - On mouse down color should change and on mouse up normal color should be displayed)

    For this i am doing something like this

    bool pushed;

    OnMouseDown()
    {
    pushed = true;
    Invalidate();
    }

    OnMouseUp()
    {
    pushed = false;
    Invalidate();
    }


    OnPaint(...)
    {
    ....... /// some code
    if(pushed)
    {
    Fill the selected/clicked rectangle with different color
    }

    .........// some code
    }


    Problem facing:
    For some clicks, key highlight don't work in device application( compact frame work). But in windows application it works properly !!!

    Usually when i click on a key, the order should MouseDown -> Onpaint - > MouseUp [ Onpaint calling in middle because of Invalidate in mouse down]

    But some times, this order goes wrong in device application [compact framework] like MouseDown -> MouseUp [ OnPaint is missed] Because of this click highlight doesn't work.

    Any help on this?
  • GaryTexmo
    Recognized Expert Top Contributor
    • Jul 2009
    • 1501

    #2
    Take this with a grain of salt because I've never developed in the compact framework before, but you might be able to manual force a paint on your mouse down and mouse up events.

    I believe you can do with with the Invalidate() method.

    Comment

    • pshilparani
      New Member
      • Dec 2010
      • 2

      #3
      Thanks for your reply GaryTexmo..

      But calling Invalidate() in MouseDown event is not sufficient in WinCe environment [ Atleast in my case where i am trying paint specific region [rect] on a panel control ]. Because call to OnPaint by the Invalidate() will be ignored as soon i get MouseUp event.

      I fixed this issue by forcing the paint by calling Update() in MouseDown event which will force immediate paint of invalidated regions like below.

      OnMouseDown()
      {
      pushed = true;
      Invalidate();
      this.Update();
      }

      Comment

      Working...