You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为Krypton Button设置内边距以拉开左侧图片与按钮边缘的距离?

解决Krypton Button图片左边缘间距问题的几种方法
  • 调整内置的图片内边距属性
    KryptonButton的StateCommon.Content子项里有个ImagePadding属性,直接设置它的Left值就能让图片远离按钮左边缘。比如把ImagePadding.Left设为5,图片就会往右偏移5个像素。别只盯着CommonState顶层,往下找Content子项就能看到这个属性。

  • 自定义绘制调整位置
    如果内置属性没生效,你可以继承KryptonButton重写OnPaint方法,手动控制图片绘制坐标:

    public class CustomKryptonButton : KryptonButton
    {
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            if (StateCommon.Content.Image != null)
            {
                // 左边偏移10像素,垂直居中
                int x = 10;
                int y = (ClientSize.Height - StateCommon.Content.Image.Height) / 2;
                e.Graphics.DrawImage(StateCommon.Content.Image, x, y);
            }
        }
    }
    

    注意要隐藏原控件的默认图片,避免重复绘制。

  • 给图片添加透明边距
    最省心的快速解法:用画图工具或PS给按钮图片左侧加一段透明空白区域,保存后再导入KryptonButton的CommonState中,不用改代码就能实现间距效果。

内容的提问来源于stack exchange,提问作者mosSoft

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.05 16:40:54