public virtual void SetTipTitle(Control control, string title) { bool bNewControl, bValidText; if (control == null) { throw new ArgumentNullException("control"); } bNewControl = !m_controls.ContainsKey(control); bValidText = (title != null && title.Length > 0); if (bNewControl) { if (bValidText) { ToolTipInfo info = new ToolTipInfo("", title, ToolTipIconType.None); m_controls.Add(control, info); control.HandleCreated += new EventHandler(HandleCreated); control.HandleDestroyed += new EventHandler(HandleDestroyed); if (control.IsHandleCreated) { this.HandleCreated(control, EventArgs.Empty); } } } else { ToolTipInfo info = (ToolTipInfo)m_controls[control]; info.TipTitle = title; if (info.TipText.Length == 0 && info.TipTitle.Length == 0 && info.IconType == ToolTipIconType.None) { // Remove the control. m_controls.Remove(control); // unhook events control.HandleCreated -= new EventHandler(HandleCreated); control.HandleDestroyed -= new EventHandler(HandleDestroyed); if (m_addedList.Contains(control)) { DestroyRegion(control); m_addedList.Remove(control); } } } }
/// <summary> /// Registers the specified control with the tooltip window. /// </summary> /// <param name="ctl"></param> private void CreateRegion(Control ctl) { if (!m_controls.ContainsKey(ctl)) { return; } ToolTipInfo info = (ToolTipInfo)this.m_controls[ctl]; bool flag = info.TipText.Length > 0 || info.TipTitle.Length > 0 || info.IconType != ToolTipIconType.None; if (flag && !this.m_addedList.Contains(ctl) && !base.DesignMode) { int num1 = (int)NativeMethods.SendMessage(new HandleRef(this, this.Handle), NativeMethods.TTM_ADDTOOL, 0, this.GetTOOLINFO(ctl)); if (num1 == 0) { throw new InvalidOperationException("error:" + NativeMethods.GetLastError()); } this.m_addedList.Add(ctl); } }
/// <summary> /// Associates ToolTip text with the specified control. /// </summary> /// <param name="control">The Control whose ToolTip text you want to set</param> /// <param name="text">The ToolTip text</param> public virtual void SetToolTip(Control control, string text) { bool bNewControl,bValidText; if (control == null) { throw new ArgumentNullException("control"); } bNewControl = !m_controls.ContainsKey(control); bValidText = (text != null && text.Length > 0); if (bNewControl) { if (bValidText) { ToolTipInfo info = new ToolTipInfo(text,"",ToolTipIconType.None); m_controls.Add(control,info); control.HandleCreated += new EventHandler(HandleCreated); control.HandleDestroyed += new EventHandler(HandleDestroyed); if (control.IsHandleCreated) { this.HandleCreated(control,EventArgs.Empty); } } } else { ToolTipInfo info = (ToolTipInfo)m_controls[control]; info.TipText = text; if (info.TipText.Length == 0 && info.TipTitle.Length == 0 && info.IconType == ToolTipIconType.None) { // Remove the control. m_controls.Remove(control); // unhook events control.HandleCreated -= new EventHandler(HandleCreated); control.HandleDestroyed -= new EventHandler(HandleDestroyed); if (m_addedList.Contains(control)) { DestroyRegion(control); m_addedList.Remove(control); } } } }