Ejemplo n.º 1
0
        public void ControlMouseMove(object sender, MouseEventArgs e)
        {
            if (sender == form)
            {
                return;
            }

            // Initialize a point 20,10 pixels from current position of mouse cursor
            var location = new Point(Cursor.Position.X + 20, Cursor.Position.Y + 10);

            // If position hasn't changed, cancel operation
            if (location.X == this.location.X && location.Y == this.location.Y)
            {
                return;
            }

            // Set new location to point
            this.location = location;

            #region Show Hex <> Dec label for NewToolStripNumericUpDown

            object numericUpDown;
            if (sender is Controls.NewToolStripNumericUpDown)
            {
                if (baseConvertor == null || !baseConvertor.Checked)
                {
                    formConvertor.Visible = false;
                    return;
                }

                // Get NumericUpDown control containing value to convert
                var toolStripNumericUpDown = sender as Controls.NewToolStripNumericUpDown;

                // Convert NumericUpDown's value and set label's text
                if (toolStripNumericUpDown.Hexadecimal)
                {
                    labelConvertor.Text = "DEC:  " + ((int)toolStripNumericUpDown.Value).ToString();
                }
                else
                {
                    labelConvertor.Text = "HEX:  0x" + ((int)toolStripNumericUpDown.Value).ToString("X4");
                }

                // Set label form's size
                formConvertor.Width  = labelConvertor.Width;
                formConvertor.Height = labelConvertor.Height;

                // Set label form's location
                if (location.X + formConvertor.Width > Screen.PrimaryScreen.WorkingArea.Width - 10)
                {
                    location.X -= formConvertor.Width + 30;
                }
                if (location.Y + formConvertor.Height > Screen.PrimaryScreen.WorkingArea.Height - 30)
                {
                    location.Y -= formConvertor.Height + 30;
                }
                formConvertor.Location = location;

                // Bring label form to front as an inactive form
                Do.ShowInactiveTopmost(formConvertor);

                // Finished, break operation
                return;
            }

            #endregion

            #region Show ToolTip label for any type control

            object control = sender;
            if (helpTips != null && helpTips.Checked)
            {
                if (mouseOverControl != control)
                {
                    toolTipTitle = GetToolTipText(control, "title");
                    toolTipDesc  = GetToolTipText(control, "description");
                }

                // Only show tooltip label if has description
                if (toolTipDesc != null)
                {
                    if (mouseOverControl != control)
                    {
                        titleToolTip.Text = toolTipTitle;
                        labelToolTip.Text = toolTipDesc;
                    }

                    // Set label form's location
                    if (location.X + formToolTip.Width > Screen.PrimaryScreen.WorkingArea.Width - 10)
                    {
                        location.X -= formToolTip.Width + 30;
                    }
                    if (location.Y + formToolTip.Height > Screen.PrimaryScreen.WorkingArea.Height - 30)
                    {
                        location.Y -= formToolTip.Height + 30;
                    }
                    formToolTip.Location = location;

                    // Bring label form to front as an inactive form
                    if (!formToolTip.Visible)
                    {
                        Do.ShowInactiveTopmost(formToolTip);
                    }
                }
                else
                {
                    formToolTip.Hide();
                }
            }
            else
            {
                formToolTip.Visible = false;
            }

            #endregion

            #region Show Hex <> Dec label for NumericUpDown

            if (baseConvertor != null && baseConvertor.Checked)
            {
                if (control.GetType().Name == "UpDownEdit" ||
                    control.GetType().Name == "NumericUpDown")
                {
                    // Get NumericUpDown control containing value to convert
                    if (control.GetType().Name == "UpDownEdit")
                    {
                        var temp = form.GetNextControl(control as Control, false);
                        numericUpDown = form.GetNextControl(temp, false) as NumericUpDown;
                    }
                    else
                    {
                        numericUpDown = control as NumericUpDown;
                    }

                    // Convert NumericUpDown's value and set label's text
                    if ((numericUpDown as NumericUpDown).Hexadecimal)
                    {
                        labelConvertor.Text = "DEC:  " + ((int)(numericUpDown as NumericUpDown).Value).ToString();
                    }
                    else
                    {
                        labelConvertor.Text = "HEX:  0x" + ((int)(numericUpDown as NumericUpDown).Value).ToString("X4");
                    }

                    // Set label form's size
                    formConvertor.Width  = labelConvertor.Width;
                    formConvertor.Height = labelConvertor.Height;

                    // Set label form's location
                    if (location.X + formConvertor.Width > Screen.PrimaryScreen.WorkingArea.Width - 10)
                    {
                        location.X -= formConvertor.Width + 30;
                    }
                    if (location.Y + formConvertor.Height > Screen.PrimaryScreen.WorkingArea.Height - 30)
                    {
                        location.Y -= formConvertor.Height + 30;
                    }
                    formConvertor.Location = location;

                    // Bring label form to front as an inactive form
                    Do.ShowInactiveTopmost(formConvertor);
                }
                else
                {
                    formConvertor.Hide();
                }
            }
            else
            {
                formConvertor.Hide();
            }

            #endregion

            mouseOverControl = control;
        }