• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 308
  • Last Modified:

On Hover event for label - Mouse Position?

I have an OnHover event for the mouse while it is over a label control.

How do I find out if the mouse pointer is located at the bottom of the label "rectangle"  ??

private void labelDescription_MouseHover(object sender, System.EventArgs e)
{

}
0
Tom Knowlton
Asked:
Tom Knowlton
4 Solutions
 
YurichCommented:
Hello Tom,

it's a bit hard to say what you're meaning by the "bottom of the label", but let's presume that the last thrird of the height of the label is your bottom. You can re-define it as it suits you more...

your hover event handler should be looking something like that:

private void labelDescription_MouseHover(object sender, System.EventArgs e)
{
      Point point = this.labelDescription.PointToClient( Control.MousePosition );
      Rectangle rect = new Rectangle( 0, 0, labelDescription.Bounds.Width, labelDescription.Bounds.Height );

      if( point.Y > ( int )( rect.Height / 3 * 2 ))
               // do whatever you want to do
// if you want the exact bottom of you label, the very pixel of it, it will be:

                if( point.Y == rect.Height )
                       // do whatever you want to do
}


regards,
yurich
0
 
RoninTheCommented:
I don't have a direct solution to this one...can think of a workaround using MouseMove eventhandler, as  no other mouse  related event is passed with MouseEventArgs

private void labelDescription_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
      if ( e.Y >= labelDescription.Size.Height-2   &&   e.Y <= labelDescription.Size.Height)
      {
            MessageBox.Show("Mouse at Bottom");
      }
}
0
 
Tom KnowltonWeb developerAuthor Commented:
One very important thing I neglected to mention...which turns out to impact this problem I have posed.


This is a custom control that contains two label controls, one above the other.  labelDescription is the top label control.


Here is the source for the custom control if that helps:


using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;

namespace RigWatchClient
{
      /// <summary>
      /// Summary description for NumDisplay.
      /// </summary>
      public class NumDisplay : System.Windows.Forms.UserControl
      {
            public System.Windows.Forms.Label labelDescription;
            public System.Windows.Forms.Label labelValueFOund;
            /// <summary>
            /// Required designer variable.
            /// </summary>
            private System.ComponentModel.Container components = null;

            public NumDisplay()
            {
                  // This call is required by the Windows.Forms Form Designer.
                  InitializeComponent();

                  // TODO: Add any initialization after the InitializeComponent call

            }

            /// <summary>
            /// Clean up any resources being used.
            /// </summary>
            protected override void Dispose( bool disposing )
            {
                  if( disposing )
                  {
                        if(components != null)
                        {
                              components.Dispose();
                        }
                  }
                  base.Dispose( disposing );
            }

            #region Component Designer generated code
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InitializeComponent()
            {
                  this.labelDescription = new System.Windows.Forms.Label();
                  this.labelValueFOund = new System.Windows.Forms.Label();
                  this.SuspendLayout();
                  //
                  // labelDescription
                  //
                  this.labelDescription.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
                  this.labelDescription.Dock = System.Windows.Forms.DockStyle.Top;
                  this.labelDescription.Location = new System.Drawing.Point(0, 0);
                  this.labelDescription.Name = "labelDescription";
                  this.labelDescription.Size = new System.Drawing.Size(136, 56);
                  this.labelDescription.TabIndex = 0;
                  this.labelDescription.Text = "Description";
                  this.labelDescription.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
                  this.labelDescription.MouseHover += new System.EventHandler(this.labelDescription_MouseHover);
                  //
                  // labelValueFOund
                  //
                  this.labelValueFOund.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
                  this.labelValueFOund.Dock = System.Windows.Forms.DockStyle.Fill;
                  this.labelValueFOund.Font = new System.Drawing.Font("Microsoft Sans Serif", 16F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
                  this.labelValueFOund.Location = new System.Drawing.Point(0, 56);
                  this.labelValueFOund.Name = "labelValueFOund";
                  this.labelValueFOund.Size = new System.Drawing.Size(136, 56);
                  this.labelValueFOund.TabIndex = 1;
                  this.labelValueFOund.Text = "ValueFound";
                  this.labelValueFOund.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
                  this.labelValueFOund.Click += new System.EventHandler(this.labelValueFOund_Click);
                  //
                  // NumDisplay
                  //
                  this.Controls.Add(this.labelValueFOund);
                  this.Controls.Add(this.labelDescription);
                  this.Name = "NumDisplay";
                  this.Size = new System.Drawing.Size(136, 112);
                  this.Load += new System.EventHandler(this.NumDisplay_Load);
                  this.ResumeLayout(false);

            }
            #endregion

            private void labelValueFOund_Click(object sender, System.EventArgs e)
            {
            
            }

            private void NumDisplay_Load(object sender, System.EventArgs e)
            {
            
            }

            private void labelDescription_MouseHover(object sender, System.EventArgs e)
            {
                  //MessageBox.Show("hovering");

                  
                  Point point = labelDescription.PointToClient( Control.MousePosition );
                  Rectangle rect = new Rectangle( 0, 0, labelDescription.Bounds.Width, labelDescription.Bounds.Height );

                  if( point.Y > ( int )( rect.Height / 3 * 2 ))
                  {
                        System.Diagnostics.Debug.WriteLine("bottom");
                  }
                  // do whatever you want to do
                  // if you want the exact bottom of you label, the very pixel of it, it will be:

                  if( point.Y == rect.Height )
                  {
                  
                        System.Diagnostics.Debug.WriteLine("bottom");
                  
                  }
                  // do whatever you want to do

            }
      }
}
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Tom KnowltonWeb developerAuthor Commented:
My goal here is to adjust the HEIGHT of the labelDescription label control at either design time or runtime.  Let's shoot for doing it at runtime first.
0
 
Tom KnowltonWeb developerAuthor Commented:
Here is a diagram that shows what I want:

http://www.knowltonsoftware.com/junk/controleffect.gif
0
 
jatinderalaghCommented:
Why not to Use two panels and splitter control. And you will be saved from custom drawing.
0
 
YurichCommented:
i'll have a look at your code tomorrow morning, meanwhile, have a look at this link:

http://www.experts-exchange.com/Programming/Programming_Languages/C_Sharp/Q_21395686.html

i have answered a question in regard to how create user-resizable components during the run-time... might not be exactly what you're after, but again can be worth lookingg...

regards,
yurich
0
 
Bob LearnedCommented:
My vote is for the two panels + splitter :)

Bob
0
 
Tom KnowltonWeb developerAuthor Commented:
>>>>Why not to Use two panels and splitter control. And you will be saved from custom drawing.


This sounds like the way to go!!!!


Let me try this real quick and see if this does it for me.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now