Firstly create a user control which you want to show as tool tip (eg. ToolTipWindow)
Create a class which will have all properties to be shown on your ToolTipWindow (eg. ToolTipData)
public partial class CustomToolTip: Component,IExtenderProvider
{
private Dictionary
private SuperToolTipWindow window;
private SuperToolTipControlHost host;
private ToolTipWindow winData;
public FloatForm()
{
Init();
}
public FloatForm(IContainer container)
{
container.Add(this);
Init();
}
private void Init()
{
winData = new ToolTipWindow();
window = new SuperToolTipWindow();
host = new SuperToolTipControlHost(winData, "windowHost");
controlTable = new Dictionary
host.Margin = window.Margin = host.Padding = window.Padding = new Padding(0);
window.Items.Add(host);
}
public void SetSuperStuff(Control control, ToolTipData info)
{
SetContolInfo(control, info);
}
private void SetContolInfo(Control control, ToolTipData info)
{
if (controlTable.ContainsKey(control))
{
if (info == null)
//hook events to our event handlers;
{
control.MouseEnter -= new EventHandler(this.MouseEntered);
control.MouseLeave -= new EventHandler(this.MouseLeft);
controlTable.Remove(control);
return;
}
controlTable[control] = info;
}
else
{
controlTable.Add(control, info);
//hook events to our event handlers;
control.MouseEnter += new EventHandler(this.MouseEntered);
control.MouseLeave += new EventHandler(this.MouseLeft);
}
}
private void MouseEntered(object sender, EventArgs e)
{ Show((Control)sender); }
private void MouseLeft(object sender, EventArgs e)
{
Close();
}
public void Close()
{
window.Close();
}
//Actually shows your tooltip
public void Show(Control owner)
{
winData.dgvDecisionTree.DataSource = controlTable[owner].DecisionTreeTable;
window.Show(owner, new Point(0, owner.Height), ToolStripDropDownDirection.AboveLeft);
}
#region IExtenderProvider Members
//This will decide for which types you want allow tooltip to be shown
bool IExtenderProvider.CanExtend(object extendee)
{
if (extendee is Control)
return true;
else
return false;
}
#endregion
}
//Inherited too show you tooltip
[ToolboxItem(false)]
class SuperToolTipWindow : ToolStripDropDown
{ }
//Inherited for making your control behave like tooltip
[ToolboxItem(false)]
class SuperToolTipControlHost : ToolStripControlHost
{
public SuperToolTipControlHost(Control c)
: base(c)
{
}
public SuperToolTipControlHost(Control c, string name)
: base(c, name)
{
}
}
This is all about your tooltip, now you are ready to show customised tool tip.
Drop this Control from ToolBox on your form
ToolTipData oInfo = new ToolTipData();
//Here assign all properties
ToolTip1.SetSuperStuff(button1, oInfo);
Tuesday, May 27, 2008
Create Custom ToolTip in C#
Labels: C#
Posted by Siddharth at 9:24 AM 0 comments
Monday, May 26, 2008
Hierarchical data with SQL Query
Here is what SQL gives to avoid recursion in program.
You can get parents in tree like hierarchy.
WITH [ RECURSIVE ]A simple example for you.[ ( ) ]
AS ()
The use of only the WITH clause (without the keyword RECURSIVE), is to
build a Common Table Expression (CTE). In a way CTE is a view build
especially for a query and used in one shot: each time we execute the
query. In one sense it can be called a "non persistent view".
SELECT COUNT(NEW_ID) AS NEW_NBR, NEW_FORUM
FROM T_NEWS
GROUP BY NEW_FORUM
WITH
Q_COUNT_NEWS (NBR, FORUM)
AS
(
SELECT COUNT(NEW_ID), NEW_FORUM
FROM T_NEWS
GROUP BY NEW_FORUM),
Q_MAX_COUNT_NEWS (NBR)
AS (SELECT MAX(NBR)
FROM Q_COUNT_NEWS
)
SELECT T1.*
FROM Q_COUNT_NEWS T1
INNER JOIN Q_MAX_COUNT_NEWS T2
ON T1.NBR = T2.NBR
With this query you can get output like.
ALL
|--SEA
| |--SUBMARINE
| |--BOAT
|--EARTH
| |--CAR
| |--TWO WHEELES
| | |--MOTORCYCLE
| | |--BYCYCLE
| |--TRUCK
|--AIR
|--ROCKET
So use this SQL advantage to lower the program overheads.
|--PLANE
Labels: SQL
Posted by Siddharth at 10:34 AM 0 comments
Subscribe to:
Comments (Atom)