这个问题可以通过分析PageControl的源代码来解决。
这个属性与TCS_MULTILINE窗口风格对应。这里有一个例子:
procedure TForm1.CheckBox1Click(Sender: TObject);
var
dwStyle: LongWord;
begin
dwStyle := GetWindowLong( PageControl1.Handle, GWL_STYLE );
if CheckBox1.Checked then
dwStyle := dwStyle or TCS_MULTILINE
else
dwStyle := dwStyle and not TCS_MULTILINE;
SetWindowLong( PageControl1.Handle, GWL_STYLE, dwStyle );
with PageControl1 do
PostMessage( handle, WM_SIZE, SIZE_RESTORED, MakeLong(ClientWidth, ClientHeight) );
end;最后一句是解决从单行向多行改变时显示问题。
如果没有最后一句,除非一开始MultiLine为True,否则在切换为多行时,会导致显示不正确;只有选择别的页时,才会显示为正确的。
这个属性与TCS_MULTILINE窗口风格对应。这里有一个例子:
procedure TForm1.CheckBox1Click(Sender: TObject);
var
dwStyle: LongWord;
begin
dwStyle := GetWindowLong( PageControl1.Handle, GWL_STYLE );
if CheckBox1.Checked then
dwStyle := dwStyle or TCS_MULTILINE
else
dwStyle := dwStyle and not TCS_MULTILINE;
SetWindowLong( PageControl1.Handle, GWL_STYLE, dwStyle );
with PageControl1 do
PostMessage( handle, WM_SIZE, SIZE_RESTORED, MakeLong(ClientWidth, ClientHeight) );
end;最后一句是解决从单行向多行改变时显示问题。
如果没有最后一句,除非一开始MultiLine为True,否则在切换为多行时,会导致显示不正确;只有选择别的页时,才会显示为正确的。
可是为什么下面的代码会出这样的问题呢?
procedure TForm1.Multiline1Click(Sender: TObject);
var
dwStyle: LongWord;
begin Multiline1.Checked:=not Multiline1.Checked;
dwStyle := GetWindowLong( PageControl1.Handle, GWL_STYLE );
if multiline1.Checked then
dwStyle := dwStyle or TCS_MULTILINE
else
dwStyle := dwStyle and not TCS_MULTILINE;
SetWindowLong( PageControl1.Handle, GWL_STYLE, dwStyle );
with PageControl1 do
PostMessage( handle, WM_SIZE, SIZE_RESTORED, MakeLong(ClientWidth, ClientHeight) );end;
//这样不但PageControl1没有反应,而且菜单Multiline1根本不会改变checked状态,难道 Multiline1.Checked:=not Multiline1.Checked; 不起作用?
还是PostMessage( handle, WM_SIZE, SIZE_RESTORED, MakeLong(ClientWidth, ClientHeight) );这里有问题了?
Multiline1.Checked:=not Multiline1.Checked;
以后反而能看到预期的效果,这是为什么??
难道别的语句里面对Multiline1进行了设置??