我如何让它看起来像是自动的,就像垂直的一样?
窗口的宽度是300,所以我试着在打开SCI_SETSCROLLWIDTHTRACKING的情况下将SCI_SETSCROLLWIDTH设置为300,然后再设置为小于300,但是滚动条要么总是显示,要么根本不显示。
发布于 2019-04-03 01:51:39
如果你想显示/隐藏水平的SB,你需要SCI_SETHSCROLLBAR(布尔可见),但是你需要知道行尾在哪里。所以你可以试试我下面的。它的影响相当小,因为您只看到当前可见的线条。
注意,我对scintilla control/DLL使用了一个Delphi包装器,但是所有的调用都可以使用常规的scintilla消息(相同的基本名称),并且我还使用了一些函数,如下所示。您可以在获得SCN_UPDATEUI消息的地方调用它。
function GetFirstVisiblePos: Integer;
begin
Result := PositionFromPoint(0,0);
end;
function GetLastVisiblePos: Integer;
begin
Result := PositionFromPoint(clientwidth,clientheight);
end;
function GetFirstVisibleLine: Integer;
begin
Result := LineFromPosition(GetFirstVisiblePos);
end;
function GetLastVisibleLine: Integer;
begin
Result := LineFromPosition(GetLastVisiblePos);
end;
[...]
var
i: integer;
x, endPos: integer;
needHSB: boolean;
begin
if not WordWrap then //Only need to do this if not wordwrapped
begin
x := ClientWidth ;
needHSB := false;
//Check currently visible lines only
for i := GetFirstVisibleLine to GetLastVisibleLine do
begin
//GetXOffset adds left scroll spacing if we are already scrolled left some.
endPos := PointXFromPosition(GetLineEndPosition(i) ) - x + GetXOffset ;
needHSB := endPos > ClientWidth;
if needHSB then break; //once set, don't need to set again...
end;
SetHScrollBar( needHSB );
end;
end;试一试,它应该会做你想做的事情(如果我没有读错原来的问题)。它对我很有效,尽管我最初追求的是一些不同的东西。
我需要一种方法来尝试控制水平滚动宽度,这是sci控件不能自动完成的(对我来说,SCI_SETSCROLLWIDTHTRACKING似乎就是用来做这件事的,但我从来没能开始工作(至少在文档中它暗示它应该是有效的)。我想出了以下代码。在我的应用程序中,代码位于SCN_UPDATEUI消息区。
//Set new scroll width if there's a line longer than the current scroll
//width can show:
if not WordWrap then //Only need to do this if not wordwrapped
begin
//vars: i, x, endPos, LeftScrollPos : integer;
x := ClientWidth ;
//Check currently visible lines only
for i := GetFirstVisibleLine to GetLastVisibleLine do
begin
//GetXOffset adds extra left scroll space if we are already scrolled left some.
//24 is just a fudge factor to add a little visual space after a long line.
endPos := PointXFromPosition(GetLineEndPosition(i) ) - x + GetXOffset + 24;
if endPos > 2000 then //Greater than the control's default
if endPos > ( GetScrollWidth ) then //Only need to proceed if we need more room
begin
LeftScrollPos := GetXOffset; //Store our current left scroll position
SetScrollWidth( endPos ) ; //This sets left scroll to 0, so...
SetXOffset( LeftScrollPos ); //Restore current left scroll position
end;
end;
end;https://stackoverflow.com/questions/19710281
复制相似问题