如何为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
相关产品推荐
相关产品推荐

