如果鼠标位于具有工具提示的图像上,则 C# .Net Form 不会绘制

标签 c# forms tooltip picturebox

我有一个带有图片框的表单,图片框有工具提示。问题是当表单加载并且鼠标悬停在图像上时,表单不会绘制 - 请参见图像。当鼠标离开图片框时一切正常。

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 这是鼠标离开图片框的时候 http://www.bildites.lv/images/tp47375fpl6q3oguh6e.png

最佳答案

我建议您尝试使用 Label 控件而不是 ToolTip

关于如果鼠标位于具有工具提示的图像上,则 C# .Net Form 不会绘制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10864365/

相关文章:

html - 如何在 Twitter Bootstrap 中将帮助文本添加到输入上方而不是下方

html - 如何从 Electron 应用程序中的 [mat-icon] 按钮中删除工具提示?

java - DafaultListModel 中带有工具提示文本的 JList

c++ - Tooltip 被限制在 80 个字符甚至 setmaxtipwidth 为 32767

c# - Elasticsearch ScrollId不返回任何文档

c# - 在 C# 中创建动态变量名称

c# - 如何通过 HttpContext.Current.Request.Form 知道在 HTML 页面中选中了哪些复选框?

c# - 如何使用UI自动化库点击 "pane"?

c# - C#如何改变数据表中所有列的数据类型

jquery 在点击 IE 时变灰并禁用表单元素