示例#1
0
 private void OnAddTipResult(TipEventArgs e)
 {
     if (AddTipResult != null)
     {
         AddTipResult(this, e);
     }
 }
示例#2
0
 /// <summary>Raises the <see cref="TipPopup"/> event.</summary>
 /// <param name="e">The data for the event.</param>
 protected virtual void OnTipPopup(TipEventArgs e)
 {
     if (this.TipPopup != null)
     {
         this.TipPopup(this, e);
     }
 }
 void Service_AddTipResult(object serder, TipEventArgs e)
 {
     tipResult = e.Tip;
     try
     {
         if (View.InvokeRequired)
         {
             View.Invoke(new ThreadStart(AddTipResult));
         }
         else
         {
             AddTipResult();
         }
     }
     catch (ObjectDisposedException) { }
 }
示例#4
0
        // this handler is responsible on stopping pending popup from showing when user clicks mouse
        // if popup currently shown it should be closed

        /// <summary>This methos called when it is actually time to show the popup tip window.
        /// The method should determine whether hypertooltip should be shown (is defined) or not.
        /// It is responsible for attaching all nesesary handlers to track mouse etc. to hide tip window on a right time.</summary>
        /// <param name="sender">The sender.</param>
        private void ShowTip(object sender)
        {
            // System.Console.WriteLine("ShowTip...");
            var mousePos = Cursor.Position;

            // special handling for tab pages:
            // tipId property is defined for TabPage but Mouse events are sent by parent TabControl for tabs headers.
            // So we have to find a page inside TabControl this event is related to.
            if (sender is TabControl)
            {
                var tabCtrl = sender as TabControl;
                for (var i = 0; i < tabCtrl.TabCount; i++)
                {
                    var rect = tabCtrl.GetTabRect(i);
                    rect = tabCtrl.RectangleToScreen(rect);
                    if (rect.Contains(mousePos))
                    {
                        sender = tabCtrl.TabPages[i];
                        break;
                    }
                }

                System.Diagnostics.Debug.Assert(
                    sender is TabPage, "handler installed but page is not found for TabControl");
            }

            var parent = sender as Control;

            if (sender is ToolStripItem && (sender as ToolStripItem).Owner is ToolStrip)
            {
                parent = (sender as ToolStripItem).Owner as ToolStrip;
            }

            var info = this.GetTipInfo(sender);

            if (null != info)
            {
                // place url to clipboard in debug mode
                if (this.Debug && (Control.ModifierKeys == Keys.Shift))
                {
                    Clipboard.SetText(info.Id /*info.url*/);
                }

                // Check if tip is defined but content doesn't exist. Don't try to open window at all in this case.
                if (!info.ContentExists)
                {
                    if (this.Debug)
                    {
                        var msg = string.Format("Resource doesn't exist: {0}", info.Url);

                        // show tooltip window with url to missing resource
                        var wnd = new ToolTipPopup(msg);

                        // fire event and give a chance for client to alter tip window properties or even cancel the tip
                        var args = new TipEventArgs(wnd, sender);
                        this.OnTipPopup(args);
                        if (args.Cancel)
                        {
                            return;
                        }

                        wnd.Show(parent);
                        this.hoverTracker.Start(sender, wnd);
                    }
                    else
                    {
                        if (sender is ToolStripItem)
                        {
                            var item = sender as ToolStripItem;
                            if (!string.IsNullOrEmpty(item.ToolTipText))
                            {
                                // fallback to normal tooltip
                                var wnd = new ToolTipPopup(item.ToolTipText);
                                wnd.Show(parent);
                                this.hoverTracker.Start(sender, wnd);
                            }
                        }
                    }
                }
                else
                {
                    // there was strange behaviour sometimes when single shared instance of HyperToolTipPopup was used
                    // so create a new instance each time.
                    // set all parameters for tip window to give a chance to alter them in event handler
                    var wnd = new HyperToolTipPopup {
                        UseFading = this.UseFading, FadingInterval = this.FadingInterval, Opacity = this.Opacity, Size = info.Size, TipUrl = info.Url
                    };


                    // fire event and give a chance for client to alter tip window properties or even cancel the tip
                    var args = new TipEventArgs(wnd, sender);
                    this.OnTipPopup(args);
                    if (args.Cancel)
                    {
                        return;
                    }

                    wnd.Show(parent);

                    // start tracking, we will receive TrackingStopped event when tracking will be stopped
                    this.hoverTracker.Start(sender, wnd);
                }
            }
            else
            {
                // show normal tooltips as a fallback for toolbar items
                if (sender is ToolStripItem)
                {
                    var item = sender as ToolStripItem;
                    if (!string.IsNullOrEmpty(item.ToolTipText))
                    {
                        // fallback to normal tooltip
                        var wnd = new ToolTipPopup(item.ToolTipText);
                        wnd.Show(parent);
                        this.hoverTracker.Start(sender, wnd);
                    }
                }
            }
        }