Thread: Problem located but not sure how to fix MouseWheel problem

  1. #1
    Registered User
    Join Date
    Jun 2006
    Posts
    3

    Problem located but not sure how to fix MouseWheel problem

    I posted yesterday but my post made almost no sense at all. This one should remedy that.

    There is just one element involved. I have an application with a TreeView and then some other controls. I can scroll the other controls fine on start up. However, once I click into the TreeView control, I can no long catch the MouseWheel Events in the other controls. If I click on a button, my MouseWheel Events return to the other controls.

    My guess is the TreeView is capturing the mouse or something. How can I fix this? What I would like to do is scroll the treeview when my mouse is over it and scroll another control like a text box when my mouse is not over the TreeView. I am guessing I will catch the OnMouseEnter and OnMouseLeave events. Nothing I have tried has worked though.

    Please help me.

    Brian

  2. #2
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,110
    One solution would be to use the MouseMove event of the component.

    Then focus the sender of the event ( which should be the component ).

    Just tried it with textBoxes but it should work with every component normally.
    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    
    namespace GUITestC {
    	public partial class Form1 : Form {
    		public Form1() {
    			InitializeComponent();
    			this.fillTxtBoxes(this.txtBoxLeft, this.txtBoxRight);
    		}
    
    		private void fillTxtBoxes(params TextBox [] ar) {
    			foreach (TextBox txtBox in ar) {
    				for (int i = 0; i < 100; i++) {
    					txtBox.AppendText(i + "\r\n");
    				}
    			}
    		}
    
    		private void txtBoxRight_MouseMove(object sender, MouseEventArgs e) {
    			TextBox b = (TextBox)sender;
    			b.Focus();
    		}
    
    		private void txtBoxLeft_MouseMove(object sender, MouseEventArgs e) {
    			TextBox b = (TextBox)sender;
    			b.Focus();
    		}
    
    	}
    }
    Where txtBoxRight and left are multiline textboxes with a vertical scrollbar. When hovered over the textbox it will be focussed, thus enabling you to scroll when you hover over it .

    :edit:

    I guess you could also use the MouseLeave event to focus the main form or whatever you want to give default focus when the mouse is no longer over the component.

    :edit 2:

    Next time you want to clarify your question , please do this in the same thread, or edit your post in that thread. Else this whole board would be flooded with threads that don't make any sense.
    Last edited by GanglyLamb; 07-01-2006 at 03:13 AM.

  3. #3
    Registered User
    Join Date
    Jun 2006
    Posts
    3

    Thank you.

    Thank you very much. That did the trick. I will be certain to just edit my posts in the future. Sorry for that.

    Brian

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. plz help me fix this problem
    By Joe100 in forum C++ Programming
    Replies: 8
    Last Post: 07-13-2003, 01:25 PM
  2. computer problem... me can't fix... internet
    By compjinx in forum Tech Board
    Replies: 2
    Last Post: 03-07-2003, 02:01 PM
  3. mixer to sound card problem, need help ASAP
    By Waldo2k2 in forum Tech Board
    Replies: 0
    Last Post: 12-09-2002, 05:02 PM
  4. Replies: 17
    Last Post: 12-06-2002, 03:13 PM
  5. What may I do to fix this problem? :(
    By marCplusplus in forum C++ Programming
    Replies: 6
    Last Post: 12-15-2001, 12:34 PM