鼠标悬停事件不触发了面板在C# [英] Mouse Hover event not firing over a panel in c#

查看:461
本文介绍了鼠标悬停事件不触发了面板在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用C#写在面板Mouse_Hover事件代码在我的winform应用程序。这是我的代码..

 私人无效viewscreen_MouseHover(对象发件人,EventArgs五)
{
statuspnl .Enabled = TRUE;
statuspnl.Visible = TRUE;
}



但问题是当我在服用鼠标事件在不触发观察屏面板

  //视屏
//
this.viewscreen.BackColor = System.Drawing中。 SystemColors.ActiveCaptionText;
this.viewscreen.Controls.Add(this.statuspnl);
this.viewscreen.Location =新System.Drawing.Point(208,16);
this.viewscreen.Name =视屏;
this.viewscreen.Size =新System.Drawing.Size(370,290);
this.viewscreen.TabIndex = 0;
this.viewscreen.MouseHover + =新System.EventHandler(this.viewscreen_MouseHover);


解决方案

请创建一个窗口的应用程序的名称为panelvisible 。添加一种形式为Form1的
,并添加相应的文件中的这些代码。



代码设计者

 命名空间panelvisible 
{
部分Form1类
{
///<总结>
///必需的设计变量。
///< /总结>
私人System.ComponentModel.IContainer成分= NULL;

///<总结>使用
///清理的任何资源。
///< /总结>
///< PARAM NAME =处理>真要是托管资源应释放;否则为false< /参数>
保护覆盖无效的Dispose(BOOL处置)
{
如果(处置和放大器;及(成分= NULL)!)
{
components.Dispose();
}
base.Dispose(处置);
}

#region Windows窗体设计器生成的代码

///<总结>
///设计器支持所需的方法 - 不要修改
///此方法的代码编辑器的内容。
///< /总结>
私人无效的InitializeComponent()
{
this.panel1 =新System.Windows.Forms.Panel();
this.label1 =新System.Windows.Forms.Label();
this.panel2 =新System.Windows.Forms.Panel();
this.panel1.SuspendLayout();
this.SuspendLayout();
//
// PANEL1
//
this.panel1.BackColor = System.Drawing.Color.Red;
this.panel1.Controls.Add(this.panel2);
this.panel1.Controls.Add(this.label1);
this.panel1.Location =新System.Drawing.Point(101,36);
this.panel1.Name =PANEL1;
this.panel1.Size =新System.Drawing.Size(200,100);
this.panel1.TabIndex = 0;
this.panel1.MouseHover + =新System.EventHandler(this.panel1_MouseHover);
//
// LABEL1
//
this.label1.AutoSize = TRUE;
this.label1.Location =新System.Drawing.Point(49,42);
this.label1.Name =LABEL1;
this.label1.Size =新System.Drawing.Size(31,13);
this.label1.TabIndex = 0;
this.label1.Text =你好;
this.label1.Visible = FALSE;
//
//是Panel2
//
this.panel2.BackColor = System.Drawing.Color.Gray;
this.panel2.Location =新System.Drawing.Point(33,70);
this.panel2.Name =是Panel2;
this.panel2.Size =新System.Drawing.Size(118,10);
this.panel2.TabIndex = 1;
this.panel2.Visible = FALSE;
//
// Form1中
//
this.AutoScaleDimensions =新System.Drawing.SizeF(6F,13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize =新System.Drawing.Size(494,205);
this.Controls.Add(this.panel1);
this.Name =Form1的;
this.Text =Form1的;
this.panel1.ResumeLayout(假);
this.panel1.PerformLayout();
this.ResumeLayout(假);

}

#endregion

私人System.Windows.Forms.Panel PANEL1;
私人System.Windows.Forms.Label LABEL1;
私人System.Windows.Forms.Panel是Panel2;
}
}



代码背后

$ B $代码b

 使用系统;使用System.Windows.Forms的
;

命名空间panelvisible
{
公共部分Form1类:表格
{
公共Form1中()
{
的InitializeComponent() ;
}

私人无效panel1_MouseHover(对象发件人,EventArgs五)
{
this.label1.Visible = TRUE;
this.label1.Enabled = TRUE;
this.panel2.Visible = TRUE;
this.panel2.Enabled = TRUE;
}


}
}


i am trying to write a code on Mouse_Hover event of a panel in my winform app using c#. This is my code ..

private void viewscreen_MouseHover(object sender, EventArgs e)
    {
        statuspnl.Enabled = true;
        statuspnl.Visible = true;
    }

but the problem is the event is not firing when i am taking the mouse over the viewscreen panel

 // viewscreen
        // 
        this.viewscreen.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
        this.viewscreen.Controls.Add(this.statuspnl);
        this.viewscreen.Location = new System.Drawing.Point(208, 16);
        this.viewscreen.Name = "viewscreen";
        this.viewscreen.Size = new System.Drawing.Size(370, 290);
        this.viewscreen.TabIndex = 0;
        this.viewscreen.MouseHover += new System.EventHandler(this.viewscreen_MouseHover);

解决方案

Please create one window app with the name as "panelvisible". Add one form as "Form1" and add these code in respective files.

Code for designer

namespace panelvisible
{
    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.panel1 = new System.Windows.Forms.Panel();
            this.label1 = new System.Windows.Forms.Label();
            this.panel2 = new System.Windows.Forms.Panel();
            this.panel1.SuspendLayout();
            this.SuspendLayout();
            // 
            // panel1
            // 
            this.panel1.BackColor = System.Drawing.Color.Red;
            this.panel1.Controls.Add(this.panel2);
            this.panel1.Controls.Add(this.label1);
            this.panel1.Location = new System.Drawing.Point(101, 36);
            this.panel1.Name = "panel1";
            this.panel1.Size = new System.Drawing.Size(200, 100);
            this.panel1.TabIndex = 0;
            this.panel1.MouseHover += new System.EventHandler(this.panel1_MouseHover);
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(49, 42);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(31, 13);
            this.label1.TabIndex = 0;
            this.label1.Text = "Hello";
            this.label1.Visible = false;
            // 
            // panel2
            // 
            this.panel2.BackColor = System.Drawing.Color.Gray;
            this.panel2.Location = new System.Drawing.Point(33, 70);
            this.panel2.Name = "panel2";
            this.panel2.Size = new System.Drawing.Size(118, 10);
            this.panel2.TabIndex = 1;
            this.panel2.Visible = false;
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(494, 205);
            this.Controls.Add(this.panel1);
            this.Name = "Form1";
            this.Text = "Form1";
            this.panel1.ResumeLayout(false);
            this.panel1.PerformLayout();
            this.ResumeLayout(false);

        }

        #endregion

        private System.Windows.Forms.Panel panel1;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.Panel panel2;
    }
}

Code for code behind

using System;
using System.Windows.Forms;

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

        private void panel1_MouseHover(object sender, EventArgs e)
        {
            this.label1.Visible = true;
            this.label1.Enabled = true;
            this.panel2.Visible = true;
            this.panel2.Enabled = true;
        }


    }
}

这篇关于鼠标悬停事件不触发了面板在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆