【发布时间】:2021-02-25 17:47:05
【问题描述】:
使用WS_EX_LAYOUTRTL 标志会导致控件边缘出现黑条。黑条位于每个按钮的左边缘。如何在仍然使用WS_EX_LAYOUTRTL 标志的同时防止出现黑条?
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样式。看看这个RTL Panel没有这个问题。 -
这就是
TabControl或Form在其源代码中实现RTL 的方式。 -
@RezaAghaei 添加
WS_EX_NOINHERITLAYOUT解决了这个问题。谢谢!