2012-06-02 62 views
4

我有一個帶有圖片框的表單並且圖片框有工具提示。問題是當表單加載和鼠標在圖像上,表單不會繪製 - 查看圖像。當鼠標離開picturebox時,一切都很好。如果鼠標位於具有工具提示的圖像上,C#.Net窗體將不會繪製

Form1.cs的

using System; 
using System.Windows.Forms; 

namespace testTooltip 
{ 
    public partial class Form1 : Form 
    { 
     public Form1() 
     { 
      InitializeComponent(); 
     } 

     private void pictureBox1_MouseMove(object sender, MouseEventArgs e) 
     { 
      if(toolTip1.Active) 
      toolTip1.Show(e.X + " " + e.Y, this, e.X, e.Y); 
     } 

     private void pictureBox1_MouseLeave(object sender, EventArgs e) 
     { 
      toolTip1.Hide(this); 
     } 
    } 
} 

Form1.designer.cs

namespace testTooltip 
{ 
    partial class Form1 
    { 
     /// <summary> 
     /// Required designer variable. 
     /// </summary> 
     private System.ComponentModel.IContainer components = null; 

     /// <summary> 
     /// Clean up any resources being used. 
     /// </summary> 
     /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> 
     protected override void Dispose(bool disposing) 
     { 
      if (disposing && (components != null)) 
      { 
       components.Dispose(); 
      } 
      base.Dispose(disposing); 
     } 

     #region Windows Form 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.components = new System.ComponentModel.Container(); 
      this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); 
      this.pictureBox1 = new System.Windows.Forms.PictureBox(); 
      ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); 
      this.SuspendLayout(); 
      // 
      // toolTip1 
      // 
      this.toolTip1.AutomaticDelay = 5000; 
      this.toolTip1.OwnerDraw = true; 
      this.toolTip1.ToolTipTitle = "Test"; 
      // 
      // pictureBox1 
      // 
      this.pictureBox1.Image = global::testTooltip.Properties.Resources.screen000; 
      this.pictureBox1.Location = new System.Drawing.Point(29, 12); 
      this.pictureBox1.Name = "pictureBox1"; 
      this.pictureBox1.Size = new System.Drawing.Size(678, 429); 
      this.pictureBox1.TabIndex = 0; 
      this.pictureBox1.TabStop = false; 
      this.pictureBox1.MouseLeave += new System.EventHandler(this.pictureBox1_MouseLeave); 
      this.pictureBox1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseMove); 
      // 
      // Form1 
      // 
      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 
      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 
      this.ClientSize = new System.Drawing.Size(730, 457); 
      this.Controls.Add(this.pictureBox1); 
      this.DoubleBuffered = true; 
      this.Name = "Form1"; 
      this.Text = "Form1"; 
      ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); 
      this.ResumeLayout(false); 

     } 

     #endregion 

     private System.Windows.Forms.ToolTip toolTip1; 
     private System.Windows.Forms.PictureBox pictureBox1; 
    } 
} 

這裏是預覽 http://www.bildites.lv/images/1iftt7hxbqloz0vw949.png ,這是當鼠標離開PictureBox的 http://www.bildites.lv/images/tp47375fpl6q3oguh6e.png

+1

您是否在沒有提示的情況下嘗試過,看看是否導致問題? –

+0

明顯的一個明顯錯誤:將工具提示的OwnerDraw屬性重新設置爲False。或者實際執行Draw事件。 –

+0

沒有工具提示它工作正常,但我需要該工具提示並將OwnerDraw屬性設置爲False不修復任何內容,它只會使工具提示閃爍 – user1432667

回答

1

我建議你嘗試只用Label控制而不是ToolTip

+0

嘗試使用標籤 - label1.Location = pictureBox1.PointToScreen(e.Location);工作正常,但它遠離鼠標位置,並且每次都隨機選擇 label1.Location = e.Location;與工具提示相同的問題 – user1432667

+1

假設我的標籤名爲lblTooltip並在您的事件處理程序中:'lblTooltip.Location = new Point(e.X,e.Y); lblTooltip.Text = eX +「」+ eY;' –

+0

確定這一個工作正常,謝謝 – user1432667

相關問題