Click here to Skip to main content
15,886,049 members
Home / Discussions / C#
   

C#

 
GeneralRe: Word compatibility Pin
Spaz808-Aug-07 1:59
Spaz808-Aug-07 1:59 
GeneralRe: Word compatibility Pin
satsumatable8-Aug-07 3:29
satsumatable8-Aug-07 3:29 
GeneralRe: Word compatibility Pin
Spaz808-Aug-07 5:09
Spaz808-Aug-07 5:09 
Questionproblem with printer Pin
help as an alias7-Aug-07 23:02
help as an alias7-Aug-07 23:02 
QuestionSetting network adapter to promiscuous mode Pin
dotman17-Aug-07 22:45
dotman17-Aug-07 22:45 
QuestionResponse.Content Type Pin
sarodam7-Aug-07 22:43
sarodam7-Aug-07 22:43 
AnswerRe: Response.Content Type Pin
asithangae7-Aug-07 23:51
asithangae7-Aug-07 23:51 
QuestionCreateHandle() error on an Overriden Tooltip for the DataGridView [modified] Pin
Rafferty Uy7-Aug-07 22:23
Rafferty Uy7-Aug-07 22:23 
Hello,

This will be a pretty long message so please bear with me, and thank you in advance for your help.

For the DataGridView, we needed to disable the ToolTip of the cells for all the columns EXCEPT for one column. And we wanted the ToolTip for that specific column to always show (and not hide after a certain amount of time).

My understanding is that the ToolTip of the DataGridView cannot be exposed, and therefore we had to do a work around. What we did was to create a class that extends the ToolTip and also a class that extends the DataGridView. The new tooltip class, named ManualToolTip, is then instantiated in our extended DataGridView class. (Note: there are other reasons for extending the DataGridView, but extending the ToolTip was done solely for this purpose.) Now, doing this created a lot of problems, I will not copy paste some code snippets and the error that we are getting.

ManualToolTip.cs
using System;<br />
using System.ComponentModel;<br />
using System.Drawing;<br />
using System.Windows.Forms;<br />
<br />
namespace UIControls<br />
{<br />
  /// <summary><br />
  /// This class provides some more predictable behavior for displaying<br />
  /// and hiding the tooltip.  <br />
  /// </summary><br />
  public class ManualControlToolTip : ToolTip<br />
  {<br />
    private bool _toolTipDisplayed = false;<br />
    private Timer _toolTipTimer = new Timer();<br />
    private Control _control;<br />
    private Point _mousePoint = new Point();<br />
    private string _toolTipText = string.Empty;<br />
    private bool _hideOnMouseMove = true;<br />
    private int _movePixelThreshold = 3;<br />
    private bool _useTimer = true;<br />
    <br />
    public ManualControlToolTip()<br />
      : base()<br />
    {<br />
      Init();<br />
    }<br />
<br />
    public ManualControlToolTip(IContainer container)<br />
      : base(container)<br />
    {<br />
      Init();<br />
    }<br />
<br />
    private void Init()<br />
    {<br />
      // stop the internal tooltip timer.  Use the one here.<br />
      this.StopTimer();<br />
      <br />
      _toolTipTimer.Interval = this.InitialDelay;<br />
      _toolTipTimer.Tick += new EventHandler(ToolTipTimer_Pop);<br />
    }<br />
<br />
    /// <summary><br />
    /// Start the timers for the tooltip.  Use the timer values (initial,<br />
    /// autoPop, reshow) to show the tooltip.<br />
    /// </summary><br />
    public void StartTimers()<br />
    {<br />
      _toolTipTimer.Start();<br />
      _useTimer = true;<br />
    }<br />
<br />
    /// <summary><br />
    /// Stop the timers for the tooltip.  Displaying/hiding the tooltip<br />
    /// manually.<br />
    /// </summary><br />
    public void StopTimers()<br />
    {<br />
      _toolTipTimer.Stop();<br />
      _useTimer = false;<br />
    }<br />
<br />
    /// <summary><br />
    /// Hide the tooltip when the mouse is moved.<br />
    /// Amount of movement is depenedent on MovePixelThreshold.<br />
    /// </summary><br />
    [DefaultValue(true)]<br />
    public bool HideOnMouseMove<br />
    {<br />
      get { return _hideOnMouseMove; }<br />
      set { _hideOnMouseMove = value; }<br />
    }<br />
<br />
    /// <summary><br />
    /// The number of pixels of movement needed to hide the <br />
    /// tooltip (if HideOnMouseMove is true).<br />
    /// </summary><br />
    [DefaultValue(3)]<br />
    public int MovePixelThreshold<br />
    {<br />
      get { return _movePixelThreshold; }<br />
      set { _movePixelThreshold = value; }<br />
    }<br />
<br />
    /// <summary><br />
    /// The control this tooltip responds to.<br />
    /// </summary><br />
    [DefaultValue(null)]<br />
    public Control Control<br />
    {<br />
      get { return _control; }<br />
      set<br />
      {<br />
        if (_control != null)<br />
        {<br />
          if (_control is DataGridView)<br />
          {<br />
            DataGridView grid = (DataGridView)_control;<br />
<br />
            grid.CellMouseEnter -= new DataGridViewCellEventHandler(grid_CellMouseEnter);<br />
            grid.CellMouseLeave -= new DataGridViewCellEventHandler(grid_CellMouseLeave);<br />
          }<br />
          else<br />
          {<br />
            _control.MouseEnter -= new EventHandler(_control_MouseEnter);<br />
            _control.MouseLeave -= new EventHandler(_control_MouseLeave);<br />
            _control.MouseMove -= new MouseEventHandler(_control_MouseMove);<br />
          }<br />
        }<br />
<br />
        _control = value;<br />
<br />
        if (_control is DataGridView)<br />
        {<br />
          DataGridView grid = (DataGridView) _control;<br />
<br />
          grid.CellMouseEnter += new DataGridViewCellEventHandler(grid_CellMouseEnter);<br />
          grid.CellMouseLeave += new DataGridViewCellEventHandler(grid_CellMouseLeave);<br />
        }<br />
        else<br />
        {<br />
          _control.MouseEnter += new EventHandler(_control_MouseEnter);<br />
          _control.MouseLeave += new EventHandler(_control_MouseLeave);<br />
          _control.MouseMove += new MouseEventHandler(_control_MouseMove);<br />
        }<br />
      }<br />
    }<br />
<br />
    private void grid_CellMouseLeave(object sender, DataGridViewCellEventArgs e)<br />
    {<br />
      HideToolTip();<br />
      _toolTipTimer.Stop();<br />
    }<br />
<br />
    private void grid_CellMouseEnter(object sender, DataGridViewCellEventArgs e)<br />
    {<br />
      DataGridView grid = sender as DataGridView;<br />
<br />
      if (grid != null && e.RowIndex != -1)<br />
      {<br />
        DataGridViewCell cell = grid.Rows[e.RowIndex].Cells[e.ColumnIndex];<br />
        ToolTipText = cell.ToolTipText;<br />
      }<br />
      _toolTipTimer.Start();<br />
    }<br />
<br />
    /// <summary><br />
    /// The text to display in the tooltip<br />
    /// </summary><br />
    [DefaultValue("")]<br />
    public string ToolTipText<br />
    {<br />
      get { return _toolTipText; }<br />
      set { _toolTipText = value; }<br />
    }<br />
<br />
    private void _control_MouseMove(object sender, MouseEventArgs e)<br />
    {<br />
      HandleMouseMove(e.Location);<br />
    }<br />
<br />
    private void HandleMouseMove(Point location)<br />
    {<br />
      int pixelMovements = Math.Abs(_mousePoint.X - location.X) +<br />
                           Math.Abs(_mousePoint.Y - location.Y);<br />
      if (pixelMovements >= MovePixelThreshold)<br />
      {<br />
        // check if the tooltip should be removed<br />
        if (HideOnMouseMove &&<br />
            _toolTipDisplayed &&<br />
            !_mousePoint.Equals(location))<br />
        {<br />
          HideToolTip();<br />
        }<br />
        else if (_useTimer)<br />
        {<br />
          // enough movement to reset the timer.<br />
          _toolTipTimer.Stop();<br />
          _toolTipTimer.Start();<br />
        }<br />
      }<br />
    }<br />
<br />
    public bool IsDisplayed<br />
    {<br />
      get { return _toolTipDisplayed; }<br />
    }<br />
<br />
    private void _control_MouseLeave(object sender, EventArgs e)<br />
    {<br />
      HideToolTip();<br />
      _toolTipTimer.Stop();<br />
    }<br />
<br />
    private void _control_MouseEnter(object sender, EventArgs e)<br />
    {<br />
      _toolTipTimer.Start();<br />
    }<br />
<br />
    private void ToolTipTimer_Pop(object sender, EventArgs e)<br />
    {<br />
      if (_toolTipDisplayed)<br />
      {<br />
        HideToolTip();<br />
      }<br />
      else<br />
      {<br />
        ShowToolTip();<br />
      }<br />
    }<br />
<br />
    /// <summary><br />
    /// Show the tool tip.<br />
    /// </summary><br />
    public void ShowToolTip()<br />
    {<br />
      if ( Control != null && !Control.Disposing )<br />
      {<br />
        this.Show(ToolTipText, Control,<br />
                  Control.PointToClient(new Point(Cursor.Position.X + Cursor.Current.Size.Width, Cursor.Position.Y)),<br />
                  Int32.MaxValue);<br />
        _toolTipDisplayed = true;<br />
        _mousePoint = Control.PointToClient(Cursor.Position);<br />
<br />
        if (_useTimer)<br />
        {<br />
          _toolTipTimer.Stop();<br />
          _toolTipTimer.Interval = this.AutoPopDelay;<br />
          _toolTipTimer.Start();<br />
        }<br />
      }<br />
    }<br />
<br />
    /// <summary><br />
    /// Hide the tool tip.<br />
    /// </summary><br />
    public void HideToolTip()<br />
    {<br />
      if ( Control != null && !Control.Disposing )<br />
      {<br />
        this.Hide(Control);<br />
        _toolTipDisplayed = false;<br />
<br />
        if (_useTimer)<br />
        {<br />
          _toolTipTimer.Stop();<br />
          _toolTipTimer.Interval = this.ReshowDelay;<br />
          _toolTipTimer.Start();<br />
        }<br />
      }<br />
    }<br />
  }<br />
}


Error Message 1:
See the end of this message for details on invoking <br />
just-in-time (JIT) debugging instead of this dialog box.<br />
<br />
************** Exception Text **************<br />
System.ObjectDisposedException: Cannot access a disposed object.<br />
Object name: 'ViewSolutionForm'.<br />
   at System.Windows.Forms.Control.CreateHandle()<br />
   at System.Windows.Forms.Form.CreateHandle()<br />
   at System.Windows.Forms.Control.get_Handle()<br />
   at System.Windows.Forms.ToolTip.get_CreateParams()<br />
   at System.Windows.Forms.ToolTip.CreateHandle()<br />
   at System.Windows.Forms.ToolTip.Hide(IWin32Window win)<br />
   at UiControls.ManualControlToolTip.HideToolTip()<br />
   at UiControls.ManualControlToolTip.ToolTipTimer_Pop(Object sender, EventArgs e)<br />
   at System.Windows.Forms.Timer.OnTick(EventArgs e)<br />
   at System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m)<br />
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


Error Message 2:
See the end of this message for details on invoking <br />
just-in-time (JIT) debugging instead of this dialog box.<br />
<br />
************** Exception Text **************<br />
System.NullReferenceException: Object reference not set to an instance of an object.<br />
   at UiControls.ManualControlToolTip.ShowToolTip()<br />
   at System.Windows.Forms.Timer.OnTick(EventArgs e)<br />
   at System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m)<br />
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)



My guess is that I am not understanding the ToolTip correctly. It could be that it is creating and disposing differently than I thought. Could it be that a separate ToolTip instance is created per cell in the table? And does it Dispose when you do a Hide? Well, I'm really just guessing. I need help! Or, at the very least, direction.


Thanks in advance!

Rafferty


-- modified at 10:18 Wednesday 8th August, 2007
AnswerRe: CreateHandle() error on an Overriden Tooltip for the DataGridView Pin
Rafferty Uy8-Aug-07 14:06
Rafferty Uy8-Aug-07 14:06 
QuestionTRY THIS!.. [modified] Pin
dianenacario7-Aug-07 22:08
dianenacario7-Aug-07 22:08 
AnswerRe: TRY THIS!.. Pin
Hessam Jalali7-Aug-07 22:46
Hessam Jalali7-Aug-07 22:46 
GeneralRe: TRY THIS!.. Pin
dianenacario7-Aug-07 22:56
dianenacario7-Aug-07 22:56 
GeneralRe: TRY THIS!.. Pin
Hessam Jalali7-Aug-07 23:15
Hessam Jalali7-Aug-07 23:15 
GeneralRe: TRY THIS!.. Pin
dianenacario7-Aug-07 23:21
dianenacario7-Aug-07 23:21 
GeneralRe: TRY THIS!.. Pin
dianenacario7-Aug-07 22:58
dianenacario7-Aug-07 22:58 
AnswerRe: TRY THIS!.. Pin
m@u7-Aug-07 22:50
m@u7-Aug-07 22:50 
GeneralRe: TRY THIS!.. Pin
dianenacario7-Aug-07 22:57
dianenacario7-Aug-07 22:57 
AnswerRe: TRY THIS!.. Pin
Luc Pattyn7-Aug-07 23:16
sitebuilderLuc Pattyn7-Aug-07 23:16 
QuestionC# class questions Pin
choadvach7-Aug-07 21:45
choadvach7-Aug-07 21:45 
AnswerRe: C# class questions Pin
originSH7-Aug-07 22:25
originSH7-Aug-07 22:25 
GeneralRe: C# class questions Pin
choadvach7-Aug-07 23:12
choadvach7-Aug-07 23:12 
QuestionMulti Language Windows base Software Pin
Abubakarsb7-Aug-07 21:25
Abubakarsb7-Aug-07 21:25 
AnswerRe: Multi Language Windows base Software Pin
Hessam Jalali7-Aug-07 21:43
Hessam Jalali7-Aug-07 21:43 
AnswerRe: Multi Language Windows base Software Pin
lmoelleb7-Aug-07 21:51
lmoelleb7-Aug-07 21:51 
QuestionDataset format inconsistency. Pin
M. J. Jaya Chitra7-Aug-07 20:52
M. J. Jaya Chitra7-Aug-07 20:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.