C# [Win32] [API] Vista Command Link Control with Windows Forms

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(180, 60);
            }
        }

        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) + 1; char* lpStr = stackalloc char[dwLength]; SendMessage(new HandleRef(this, Handle), BCM_GETNOTE, &dwLength, lpStr); return new string(lpStr); } } }

 

转载于:https://www.cnblogs.com/shitekudasai/p/5884896.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值