This sample inspects events generated by the tab control.
The source code is located at C:\Program Files (x86)\Softelvdm\SftTabs NET 3.0\Samples\CSharp\EventViewer\Form1.cs.
using System;
using System.Drawing;
using System.Reflection;
using System.Windows.Forms;
using Softelvdm.SftTabsNET;
namespace EventViewer {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
private string strLastEvent = "";
private bool fLastEventDup = false;
private int addedTabs = 0;
// This is a small helper routine to show all properties and fields of an object
private void DumpValues(string title, object o) {
string s = "";
if (strLastEvent == title) {
if (!fLastEventDup) {
s = "Additional " + title + " events ... now suppressed";
fLastEventDup = true;
} else
return;
} else {
strLastEvent = title;
fLastEventDup = false;
PropertyInfo[] api = o.GetType().GetProperties();
foreach (PropertyInfo pi in api)
s += pi.Name + "=" + Describe(pi.GetValue(o, new object[] { })) + " ";
FieldInfo[] afi = o.GetType().GetFields();
foreach (FieldInfo fi in afi)
s += fi.Name + "=" + Describe(fi.GetValue(o)) + " ";
}
ListViewItem item = listView1.Items.Add(new ListViewItem(new string[] { title, s }));
listView1.SelectedItems.Clear();
item.Selected = true;
item.EnsureVisible();
}
// Tabs are shown with their text instead of their class name
private string Describe(object value) {
TabClass tab = value as TabClass;
if (tab != null)
return "\"" + tab.Text + "\"";
return value == null ? "null" : value.ToString();
}
private void buttonAdd_Click(object sender, EventArgs e) {
++addedTabs;
TabClass tab = sftTabs1.Tabs.Add("Added " + addedTabs);
tab.CloseButton = TabCloseButtonOptionalEnum.Always;
// the page of the new tab is created by the control
Label label = new Label();
label.AutoSize = true;
label.Location = new Point(12, 12);
label.Text = "This tab was added by the Add Tab button. Its close button removes it.";
tab.Page.Controls.Add(label);
tab.Select();
}
private void buttonClear_Click(object sender, EventArgs e) {
listView1.Items.Clear();
strLastEvent = "";
fLastEventDup = false;
}
private void sftTabs1_Switching(object sender, TabSwitchingEventArgs e) {
DumpValues("Switching", e);
// e.Cancel = true; would keep the current tab
}
private void sftTabs1_SwitchingDisabled(object sender, TabEventArgs e) {
DumpValues("SwitchingDisabled", e);
}
private void sftTabs1_Switched(object sender, TabSwitchedEventArgs e) {
DumpValues("Switched", e);
}
private void sftTabs1_SelectedIndexChanged(object sender, EventArgs e) {
DumpValues("SelectedIndexChanged", e);
}
private void sftTabs1_Scrolled(object sender, TabScrolledEventArgs e) {
DumpValues("Scrolled", e);
}
private void sftTabs1_PartClicked(object sender, TabPartClickedEventArgs e) {
DumpValues("PartClicked", e);
}
private void sftTabs1_TabCloseButtonClicked(object sender, TabEventArgs e) {
DumpValues("TabCloseButtonClicked", e);
// the control does not remove the tab, the application does
e.Tab.Remove();
}
private void sftTabs1_CloseButtonClicked(object sender, EventArgs e) {
DumpValues("CloseButtonClicked", e);
// the control's Close button removes the selected tab in this sample
TabClass tab = sftTabs1.SelectedTab;
if (tab != null)
tab.Remove();
}
private void sftTabs1_MinimizeButtonClicked(object sender, EventArgs e) {
DumpValues("MinimizeButtonClicked", e);
}
private void sftTabs1_RestoreButtonClicked(object sender, EventArgs e) {
DumpValues("RestoreButtonClicked", e);
}
private void sftTabs1_DragDetected(object sender, TabDragDetectedEventArgs e) {
DumpValues("DragDetected", e);
// e.Handled is left False, so the control lets the user move the tab (AllowReordering property)
}
private void sftTabs1_TabReordered(object sender, TabReorderedEventArgs e) {
DumpValues("TabReordered", e);
}
private void sftTabs1_TabAdded(object sender, TabEventArgs e) {
DumpValues("TabAdded", e);
}
private void sftTabs1_TabRemoved(object sender, TabEventArgs e) {
DumpValues("TabRemoved", e);
}
private void sftTabs1_ShowToolTip(object sender, TabToolTipEventArgs e) {
DumpValues("ShowToolTip", e);
if (e.Area == TabHitAreaEnum.Tab && e.Tab != null && e.Tab.Text == "&Tooltips") {
e.ToolTipIcon = ToolTipIcon.Info;
e.ToolTipTitle = "Balloon Tooltip";
e.ToolTipStyle = Softelvdm.SftTabsNET.Controls.ToolTipAppearanceEnum.Balloon;
e.ToolTipText = "A simple explanatory tooltip\nfor just this tab";
}
}
private void sftTabs1_Enter(object sender, EventArgs e) {
DumpValues("Enter", e);
}
private void sftTabs1_Leave(object sender, EventArgs e) {
DumpValues("Leave", e);
}
private void sftTabs1_KeyDown(object sender, KeyEventArgs e) {
DumpValues("KeyDown", e);
}
private void sftTabs1_KeyPress(object sender, KeyPressEventArgs e) {
DumpValues("KeyPress", e);
}
private void sftTabs1_KeyUp(object sender, KeyEventArgs e) {
DumpValues("KeyUp", e);
}
private void sftTabs1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) {
DumpValues("PreviewKeyDown", e);
}
private void sftTabs1_MouseClick(object sender, MouseEventArgs e) {
DumpValues("MouseClick", e);
}
private void sftTabs1_MouseDoubleClick(object sender, MouseEventArgs e) {
DumpValues("MouseDoubleClick", e);
}
private void sftTabs1_MouseDown(object sender, MouseEventArgs e) {
DumpValues("MouseDown", e);
}
private void sftTabs1_MouseEnter(object sender, EventArgs e) {
DumpValues("MouseEnter", e);
}
private void sftTabs1_MouseHover(object sender, EventArgs e) {
DumpValues("MouseHover", e);
}
private void sftTabs1_MouseLeave(object sender, EventArgs e) {
DumpValues("MouseLeave", e);
}
private void sftTabs1_MouseMove(object sender, MouseEventArgs e) {
// DumpValues("MouseMove", e); // deliberately suppressed
}
private void sftTabs1_MouseMoveHoverTimer(object sender, EventArgs e) {
DumpValues("MouseMoveHoverTimer", e);
}
private void sftTabs1_MouseMoveTimer(object sender, EventArgs e) {
DumpValues("MouseMoveTimer", e);
}
private void sftTabs1_MouseUp(object sender, MouseEventArgs e) {
DumpValues("MouseUp", e);
}
private void sftTabs1_MouseWheel(object sender, MouseEventArgs e) {
DumpValues("MouseWheel", e);
}
// The control validates the control with the focus before the user switches to another tab
private void textBox1_Validating(object sender, System.ComponentModel.CancelEventArgs e) {
if (textBox1.Text.Trim() == "") {
e.Cancel = true;
DumpValues("textBox1 Validating (canceled, the text box is empty)", e);
}
}
}
}