我这里有一个控件 DevExpress.XtraNavBar.NavBarItem
我对它进行了重写 public partial class DeNavBarItem : DevExpress.XtraNavBar.NavBarItem
但它本身没有单击事件,我想给他添加些 鼠标事件,如获得焦点,和失去焦点事件,鼠标单击、等
该怎样做,有谁做过没?
我对它进行了重写 public partial class DeNavBarItem : DevExpress.XtraNavBar.NavBarItem
但它本身没有单击事件,我想给他添加些 鼠标事件,如获得焦点,和失去焦点事件,鼠标单击、等
该怎样做,有谁做过没?
如public event EventHandler TextChanged;
protected virtual void OnTextChanged()
{
if(this.TextChanged!=null)
this.TextChanged(this,EventArgs.Empty);
} 自定义事件
实际上获取NavBarItem的焦点,单击等事件没有必要。
因为可以在NavBarControl 类中处理。
另外NavBarItem是支持单击事件的,事件名为
LinkClicked和 LinkPressed
类似于这样的
不知道你们明白没 this.Loaded +=
是我这个控件 没有 this.Loaded 怎么来的 +=
public partial class DeNavBarItem : DevExpress.XtraNavBar.NavBarItem
{ #region 事件声明
//
// 摘要:
// Occurs when the mouse pointer is moved over the control.
public event MouseEventHandler MouseMove;
//
// 摘要:
// A System.Windows.Forms.MouseEventArgs that contains the event data.
[EditorBrowsable(EditorBrowsableState.Advanced)]
protected virtual void OnMouseMove(MouseEventArgs e)
{
if (this.MouseMove != null)
this.MouseMove(this,e);
}
#endregionnewNavBarItem.MouseMove+=new MouseEventHandler(newNavBarItem_MouseMove);
void newNavBarItem_MouseMove(object sender, MouseEventArgs e)
{
} 子类里面也调用了,但是不执行
namespace WindowsFormsApplication4
{
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.navBarControl1 = new DevExpress.XtraNavBar.NavBarControl();
this.navBarGroup1 = new DevExpress.XtraNavBar.NavBarGroup();
this.navBarGroup2 = new DevExpress.XtraNavBar.NavBarGroup();
this.navBarItem6 = new DevExpress.XtraNavBar.NavBarItem();
this.navBarItem7 = new DevExpress.XtraNavBar.NavBarItem();
this.navBarItem8 = new DevExpress.XtraNavBar.NavBarItem();
((System.ComponentModel.ISupportInitialize)(this.navBarControl1)).BeginInit();
this.SuspendLayout();
//
// navBarControl1
//
this.navBarControl1.ActiveGroup = this.navBarGroup1;
this.navBarControl1.Groups.AddRange(new DevExpress.XtraNavBar.NavBarGroup[] {
this.navBarGroup1,
this.navBarGroup2});
this.navBarControl1.Items.AddRange(new DevExpress.XtraNavBar.NavBarItem[] {
this.navBarItem6,
this.navBarItem7,
this.navBarItem8});
this.navBarControl1.Location = new System.Drawing.Point(51, 29);
this.navBarControl1.Name = "navBarControl1";
this.navBarControl1.OptionsNavPane.ExpandedWidth = 140;
this.navBarControl1.Size = new System.Drawing.Size(140, 300);
this.navBarControl1.TabIndex = 0;
this.navBarControl1.Text = "navBarControl1";
this.navBarControl1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.navBarControl1_MouseMove);
//
// navBarGroup1
//
this.navBarGroup1.Caption = "navBarGroup1";
this.navBarGroup1.Expanded = true;
this.navBarGroup1.ItemLinks.AddRange(new DevExpress.XtraNavBar.NavBarItemLink[] {
new DevExpress.XtraNavBar.NavBarItemLink(this.navBarItem6),
new DevExpress.XtraNavBar.NavBarItemLink(this.navBarItem7),
new DevExpress.XtraNavBar.NavBarItemLink(this.navBarItem8)});
this.navBarGroup1.Name = "navBarGroup1";
//
// navBarGroup2
//
this.navBarGroup2.Caption = "navBarGroup2";
this.navBarGroup2.Name = "navBarGroup2";
//
// navBarItem6
//
this.navBarItem6.Caption = "navBarItem6";
this.navBarItem6.Name = "navBarItem6";
//
// navBarItem7
//
this.navBarItem7.Caption = "navBarItem7";
this.navBarItem7.Name = "navBarItem7";
//
// navBarItem8
//
this.navBarItem8.Caption = "navBarItem8";
this.navBarItem8.Name = "navBarItem8";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(292, 385);
this.Controls.Add(this.navBarControl1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.navBarControl1)).EndInit();
this.ResumeLayout(false); } #endregion private DevExpress.XtraNavBar.NavBarControl navBarControl1;
private DevExpress.XtraNavBar.NavBarGroup navBarGroup1;
private DevExpress.XtraNavBar.NavBarGroup navBarGroup2;
private DevExpress.XtraNavBar.NavBarItem navBarItem6;
private DevExpress.XtraNavBar.NavBarItem navBarItem7;
private DevExpress.XtraNavBar.NavBarItem navBarItem8; }
}using System;
using System.Windows.Forms;
using DevExpress.XtraNavBar.ViewInfo;namespace WindowsFormsApplication4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{ } private void navBarControl1_MouseMove(object sender, MouseEventArgs e)
{
NavBarViewInfo vi = this.navBarControl1.GetViewInfo();
if (vi.HotTrackedLink != null)
{
Console.WriteLine(vi.HotTrackedLink.Item.Name);
} if (vi.PressedLink != null)
Console.WriteLine(vi.PressedLink.Item.Name);
}
}
}
Dim vi As NavBarViewInfo = Me.NavBarControl1.GetViewInfo()
If e.Button = MouseButtons.Left Then
If vi.HotTrackedGroup Is Nothing Then Exit Sub
Select Case vi.HotTrackedGroup.Caption
Case "改装企业"
NavBarGroup1.Expanded = Not NavBarGroup1.Expanded
Case "终端用户"
NavBarGroup2.Expanded = Not NavBarGroup2.Expanded
Case "气瓶企业"
NavBarGroup3.Expanded = Not NavBarGroup3.Expanded
Case "套装企业"
NavBarGroup4.Expanded = Not NavBarGroup4.Expanded
Case "特检部门"
NavBarGroup5.Expanded = Not NavBarGroup5.Expanded
Case "质检部门"
NavBarGroup6.Expanded = Not NavBarGroup6.Expanded
Case "加气站"
NavBarGroup7.Expanded = Not NavBarGroup7.Expanded
Case "汽车厂"
NavBarGroup8.Expanded = Not NavBarGroup8.Expanded
Case "经销商"
NavBarGroup9.Expanded = Not NavBarGroup9.Expanded
Case "系统管理"
NavBarGroup10.Expanded = Not NavBarGroup10.Expanded
End Select
End If