gpt4 book ai didi

c# - WS_EX_LAYOUTRTL 导致控件边缘出现黑条

转载 作者:行者123 更新时间:2023-12-04 08:02:43 27 4
gpt4 key购买 nike

使用 WS_EX_LAYOUTRTL flag 导致控件边缘出现黑条。黑条位于每个按钮的左边缘。如何在仍然使用 WS_EX_LAYOUTRTL 的同时防止出现黑条旗帜?
black bars on edges of controls

public class MyForm : Form {

Button btn1 = new Button { Text = "Button1" };
ComboBox combo1 = new ComboBox();
Button btn2 = new Button { Text = "Button2" };

public MyForm() : base() {
Size = new Size(600, 100);
StartPosition = FormStartPosition.CenterScreen;
var mc = new MyControl();

int x = 0;
btn1.Location = new Point(x, 0);
x += btn1.Size.Width + 10;
combo1.Location = new Point(x, 0);
x += combo1.Size.Width + 10;
btn2.Location = new Point(x, 0);

mc.Controls.AddRange(new Control[] { btn1, combo1, btn2 });
Controls.Add(mc);
}

private class MyControl : UserControl {
private const int WS_EX_LAYOUTRTL = 0x00400000;
public MyControl() : base() {
this.Dock = DockStyle.Top;
this.AutoSize = true;
this.BackColor = Color.LightPink;
}

protected override CreateParams CreateParams {
get {
var cp = base.CreateParams;
cp.ExStyle |= WS_EX_LAYOUTRTL;
return cp;
}
}
}
}

最佳答案

添加 WS_EX_NOINHERITLAYOUT (0x100000) 风格也是如此。这就是像 TabControl 这样的容器或 Form在他们的源代码中实现了 RTL。
例如:

using System;
using System.ComponentModel;
using System.Windows.Forms;
public class ExPanel : Panel
{
const int WS_EX_LAYOUTRTL = 0x400000;
const int WS_EX_NOINHERITLAYOUT = 0x100000;
private bool rightToLeftLayout = false;

[Localizable(true)]
public bool RightToLeftLayout
{
get { return rightToLeftLayout; }
set
{
if (rightToLeftLayout != value)
{
rightToLeftLayout = value;
this.RecreateHandle();
}
}
}
protected override CreateParams CreateParams
{
get
{
CreateParams CP;
CP = base.CreateParams;
if (this.RightToLeftLayout &&
this.RightToLeft == System.Windows.Forms.RightToLeft.Yes)
CP.ExStyle = CP.ExStyle | WS_EX_LAYOUTRTL | WS_EX_NOINHERITLAYOUT;
return CP;
}
}
}

关于c# - WS_EX_LAYOUTRTL 导致控件边缘出现黑条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66373800/

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