Unwanted behaviour, workaround?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Unwanted behaviour, workaround?

  1. #1
    Join Date
    Nov 2009
    Location
    .net 3.5 csharp 2008 developer
    Posts
    36

    Question [SOLVED] Unwanted behaviour, workaround?

    Hi,

    New to the forum, and... yes I have a problem

    The issue I'm having, I'll try to describe it as good as I can.

    Basically, I have two (or more) forms, each having a toolstrip with buttons on them. If I click on a button on a toolstrip that is on a window that doesn't have focus at the moment, the button itself is never pressed, but the window gets focus.
    Simply put, I need to doubleclick on the button for it to trigger the click event, but only if the window itself did not have focus.

    I'm wondering if there is a workaround for this behaviour? Or did I miss some not so obvious property somewhere?
    Last edited by ixilom; November 15th, 2009 at 02:44 AM. Reason: Changed title to contain [SOLVED]

  2. #2
    Join Date
    Jun 2008
    Posts
    2,477

    Re: Unwanted behaviour, workaround?

    That doesn't happen for me. I created two forms with tool strips, set focus to one, hovered over the toolstrip on the other and it was highlighted. I clicked and the menu appeared. So, it likely something that you are doing in your code which is causing the issue.

  3. #3
    Join Date
    Nov 2009
    Location
    .net 3.5 csharp 2008 developer
    Posts
    36

    Re: Unwanted behaviour, workaround?

    Hmm, thats odd... I did a test app with barely any code in it.

    Form1 and Form2, both have a toolstrip with 2 buttons.
    The only code I added was to create the Form2 and to respond to the first button on the toolstrip placed on Form1.

    Yet, it doesn't do what it is supposed to do >:|
    I'm using .NET 3.5 on Vista64 Ultimate with all the latest SP/patches if that helps?

    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    
    namespace WindowsFormsApplication5
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
                Form2 f = new Form2();
                f.Show();
            }
    
            private void toolStripButton1_Click(object sender, EventArgs e)
            {
                MessageBox.Show("hello");
            }
        }
    }

  4. #4
    Join Date
    Nov 2009
    Location
    .net 3.5 csharp 2008 developer
    Posts
    36

    Re: Unwanted behaviour, workaround?

    Oh, forgot to mention that the hovering does however make the button highlight.

    ----
    Today, I tested this on my laptop with XP SP2 and I get the same results... I still need to doubleclick on the button in the toolbar to make it trigger the event... argh!
    Last edited by ixilom; November 13th, 2009 at 06:42 AM. Reason: Completion

  5. #5
    Join Date
    Nov 2009
    Location
    .net 3.5 csharp 2008 developer
    Posts
    36

    Re: Unwanted behaviour, workaround?

    I dunno how BigEd781 managed to get it to work, or perhaps he misunderstood the problem

    The good news is, I found a solution at http://blogs.msdn.com/rickbrew/archi...09/511003.aspx.

    Apparently MS decided that it would be good to "eat" the mouseclick when you activate another window.
    The "hack" mentioned in the article above will re-enable the sane behaviour

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center