gpt4 book ai didi

c# - 如何在不移动按钮的情况下在中间设置 XtraForm 标题文本?

转载 作者:太空宇宙 更新时间:2023-11-03 13:15:52 25 4
gpt4 key购买 nike

如何将 XtraForm 标题文本设置到标题栏的中间?
我试过来自 other answer 的例子, 但它会导致窗口按钮根据焦点移动几个像素。

当我单击窗口标题栏时,窗口按钮会转到一个位置,当我将鼠标移到按钮上时,它们会移到另一个位置,相差几个像素。

最佳答案

尝试以下方法(基于 XtraForm - How to center-align a header caption text 示例)。就 DevExpress 团队提供的解决方案而言,它对我有用,但不包含 Buttons.CalcButtons 理论上可以影响表单按钮位置的方法调用:

public partial class Form1 : XtraForm {
static Form1() {
SkinManager.EnableFormSkins();
}
public Form1() {
InitializeComponent();
}
protected override FormPainter CreateFormBorderPainter() {
return new CustomFormPainter(this, LookAndFeel);
}
}
public class CustomFormPainter : FormPainter {
public CustomFormPainter(Control owner, DevExpress.Skins.ISkinProvider provider)
: base(owner, provider) {
}
protected override void DrawText(DevExpress.Utils.Drawing.GraphicsCache cache) {
string text = Text;
if(text == null || text.Length == 0 || TextBounds.IsEmpty) return;
using(AppearanceObject appearance = new AppearanceObject(GetDefaultAppearance())) {
appearance.TextOptions.Trimming = Trimming.EllipsisCharacter;
appearance.TextOptions.HAlignment = HorzAlignment.Center;
if(AllowHtmlDraw) {
DrawHtmlText(cache, appearance);
return;
}
Rectangle r = RectangleHelper.GetCenterBounds(TextBounds, new Size(TextBounds.Width, CalcTextHeight(cache.Graphics, appearance)));
DrawTextShadow(cache, appearance, r);
cache.DrawString(text, appearance.Font, appearance.GetForeBrush(cache), r, appearance.GetStringFormat());
}
}
}

关于c# - 如何在不移动按钮的情况下在中间设置 XtraForm 标题文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26211989/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com