【发布时间】:2016-04-27 22:29:09
【问题描述】:
我正在使用 Microsoft Visual Studio 2013 并用 c# 编写。我编写了 TabControl 类的后代并重写了 OnClick 方法,然后更改了现有的 TabControl 元素以使用新类。一切都编译并运行,我在构造函数中的断点已到达,但它没有使用 OnClick 覆盖!这是 TabControl 后代代码,在此先感谢您的帮助!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace LumaSense.Imaging.Calibration.UI
{
public partial class TabControlModified : TabControl
{
public TabControlModified()
{
InitializeComponent();
}
private bool superuser;
public int lastTabSelectedIndex = 0;
public bool Superuser
{
get { return superuser; }
set { superuser = value; }
}
public int LastTabSelectedIndex
{
get { return lastTabSelectedIndex; }
set
{ this.lastTabSelectedIndex = value; }
}
protected override void OnClick(EventArgs e)
{
// SelectedIndex and tab have already changed before we get here
if (this.superuser == false)
{
if (this.SelectedIndex <= this.lastTabSelectedIndex)
{
this.LastTabSelectedIndex = this.SelectedIndex;
base.OnClick(e);
}
else
{
base.OnClick(e);
this.SelectedIndex = lastTabSelectedIndex;
}
}
else
{
this.LastTabSelectedIndex = this.SelectedIndex;
base.OnClick(e);
}
}
}
}
【问题讨论】:
-
当您实例化此自定义选项卡控件时,您是否向控件添加任何页面?除非有任何页面,否则它不会显示单击时触发的选项卡而不是 OnClick 方法。
标签: c# visual-studio overriding controls