Click here to Skip to main content
15,889,654 members
Home / Discussions / Windows Forms
   

Windows Forms

 
AnswerRe: why does focus always revert to the desktop? Pin
morglorf24-Jan-12 6:10
morglorf24-Jan-12 6:10 
Questionmdicontainer and child controls overlap Pin
greenbox6424-Jan-12 3:48
greenbox6424-Jan-12 3:48 
AnswerRe: mdicontainer and child controls overlap Pin
Richard MacCutchan24-Jan-12 4:01
mveRichard MacCutchan24-Jan-12 4:01 
GeneralRe: mdicontainer and child controls overlap Pin
greenbox6424-Jan-12 4:07
greenbox6424-Jan-12 4:07 
AnswerRe: mdicontainer and child controls overlap Pin
Simon_Whale24-Jan-12 4:08
Simon_Whale24-Jan-12 4:08 
GeneralRe: mdicontainer and child controls overlap Pin
greenbox6424-Jan-12 4:19
greenbox6424-Jan-12 4:19 
GeneralRe: mdicontainer and child controls overlap Pin
Simon_Whale24-Jan-12 6:04
Simon_Whale24-Jan-12 6:04 
QuestionMouseDown event missed in custom Button class Pin
TyrionTheImp19-Jan-12 18:53
TyrionTheImp19-Jan-12 18:53 
Hi All,

Am facing an issue with getting the MouseDown event for a custom drawn Button class in Dot Net 2.0 framework. This custom class basically listens to the MosueDown,Up,Hover,Enter and Leave events and updates the image shown on it (if we hover or click, an "active/pressed" image is shown else "inactive" image is painted).The code is as below :
C#
class CustomButton : Button 
{
  Bitmap displayimage;
  bool down;
  public CustomButton()
  {
       MouseUp += OnMouseUp
       MouseDown += OnMouseDown  //etc.. for other mouse events
  }

  private void OnMouseDown(object sender, MouseEventArgs e)
  {
    down = true;
    displayimage = new Bitmap("pressedimage.png");
    Invalidate();
  }

  private void OnMouseUp(object sender, MouseEventArgs e)
  {
    down = false;
    displayimage = new Bitmap("inactiveimage.png");
    Invalidate();
  }

  protected override void OnPaint(PaintEventArgs e)
  {
           if (down)
            {
                Matrix matrix = new Matrix();
                matrix.Translate(1, 1, MatrixOrder.Prepend);
                e.Graphics.Transform = matrix;
            }
      e.Graphics.DrawImage(bitmapImage);
      e.Graphics.DrawString(displaystring);
         base.OnPaint(e);   
  }
}

C#
The buttons are created in the main Form class and we also listen to MouseDown event here :

class WinForm1 : Form
{
  CustomImageButton button = new CustomImageButton ();
  
  public WinForm1
  {
    button.MouseDown += OnButtonMosueDown;
  }

  private void OnButtonMosueDown(object sender, MouseEventArgs e)
  {
     //take some action , log the user click action
  }
}

The problem is MouseDown events don`t even get trigerred sporadically, mostly seen in cases where the user is working with some external application and then directly comes over and clicks the custom button on the UI.
Any idea as to what could be the cause/likely solution ?
Is this related to the click through issue seen in dot net 2.0 Toolstrip class (refer http://blogs.msdn.com/b/rickbrew/archive/2006/01/09/511003.aspx ) ?
AnswerRe: MouseDown event missed in custom Button class Pin
ProEnggSoft20-Feb-12 23:04
ProEnggSoft20-Feb-12 23:04 
Questionhi everyone! Pin
rocket421-Jan-12 16:58
rocket421-Jan-12 16:58 
AnswerRe: hi everyone! Pin
Richard MacCutchan1-Jan-12 23:36
mveRichard MacCutchan1-Jan-12 23:36 
GeneralRe: hi everyone! Pin
rocket422-Jan-12 0:06
rocket422-Jan-12 0:06 
AnswerRe: hi everyone! Pin
DaveAuld2-Jan-12 0:23
professionalDaveAuld2-Jan-12 0:23 
GeneralRe: hi everyone! Pin
rocket422-Jan-12 1:37
rocket422-Jan-12 1:37 
AnswerRe: hi everyone! Pin
Eddy Vluggen2-Jan-12 9:01
professionalEddy Vluggen2-Jan-12 9:01 
AnswerRe: hi everyone! Pin
Albert Holguin10-Jan-12 7:41
professionalAlbert Holguin10-Jan-12 7:41 
AnswerRe: hi everyone! Pin
Dave Kreskowiak10-Jan-12 8:43
mveDave Kreskowiak10-Jan-12 8:43 
GeneralRe: hi everyone! Pin
Albert Holguin10-Jan-12 9:27
professionalAlbert Holguin10-Jan-12 9:27 
AnswerRe: hi everyone! Pin
JP_Rocks17-Jan-12 1:03
JP_Rocks17-Jan-12 1:03 
GeneralRe: hi everyone! Pin
Shameel19-Jan-12 19:09
professionalShameel19-Jan-12 19:09 
AnswerRe: hi everyone! Pin
ProEnggSoft18-Feb-12 5:53
ProEnggSoft18-Feb-12 5:53 
Questionc# Winforms with classes. Pin
Cliffordagius29-Dec-11 6:56
Cliffordagius29-Dec-11 6:56 
AnswerRe: c# Winforms with classes. Pin
Eddy Vluggen29-Dec-11 8:57
professionalEddy Vluggen29-Dec-11 8:57 
AnswerRe: c# Winforms with classes. Pin
Luc Pattyn30-Dec-11 0:06
sitebuilderLuc Pattyn30-Dec-11 0:06 
AnswerRe: c# Winforms with classes. Pin
Shameel2-Jan-12 2:12
professionalShameel2-Jan-12 2:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.