using System;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Drawing;
using System.ComponentModel;namespace Vista.Controls
{
public class CommandLink : Button
{
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
unsafe static extern IntPtr SendMessage(HandleRef hWnd, uint Msg, void* wParam, void* lParam); const int BS_CENTER = 0x00000300;
const int BS_COMMANDLINK = 0x0000000E;
const int BS_DEFCOMMANDLINK = 0x0000000F; const uint BCM_SETNOTE = 0x00001609;
const uint BCM_GETNOTE = 0x0000160A;
const uint BCM_GETNOTELENGTH = 0x0000160B;
const uint BCM_SETSHIELD = 0x0000160C; public XButton()
{
//this.FlatStyle = FlatStyle.System;
} protected override Size DefaultSize
{
get
{
return new Size(, );
}
} protected override CreateParams CreateParams
{
get
{
CreateParams cParams = base.CreateParams;
cParams.Style |= BS_COMMANDLINK;
return cParams;
}
} private bool _shield = false; [Category("Command Link"),
Description("Gets or sets the shield icon visibility of the command link."),
DefaultValue(false)]
public unsafe bool Shield
{
get
{
return _shield;
}
set
{
_shield = value;
SendMessage(new HandleRef(this, Handle), BCM_SETSHIELD, null, &value);
}
} [Category("Command Link"),
Description("Gets or sets the note text of the command link."),
DefaultValue("")]
public string Note
{
get
{
return GetNoteText();
}
set
{
SetNoteText(value);
}
} private unsafe void SetNoteText(string value)
{
fixed (char* lpStr = value)
{
SendMessage(new HandleRef(this, Handle), BCM_SETNOTE, null, lpStr);
}
} private unsafe string GetNoteText()
{
int dwLength = (int)SendMessage(new HandleRef(this, Handle), BCM_GETNOTELENGTH, null, null) + ;
char* lpStr = stackalloc char[dwLength];
SendMessage(new HandleRef(this, Handle), BCM_GETNOTE, &dwLength, lpStr);
return new string(lpStr);
} }
}