have a try while (GetScrollPos(Memo1->Handle;ssVertical) > 0) { //do something }
最近C用多了,Delphi反而有点不习惯了 have a try while (GetScrollPos(Memo1->Handle, SB_VERT) > 0) begin //do something end;
老兄,还是不行哦,我是想获得scroll的size啊。
procedure TForm1.Memo1Change(Sender: TObject); begin while GetScrollPos(Memo1.Handle, SB_VERT)>0 do begin if Memo1.Font.Size=1 then break; Memo1.Font.Size := Memo1.Font.Size - 1; end; end; 首先要设置Memo1.ScrollBars等于ssVertical
To cuteant 兄 GetScrollPos(Memo1.Handle, SB_VERT)是获得位置,不是获得长度,当scrollbar可以拉动时,POS也有可能是0啊,
抽空仔细研究了一下问题,原来我自己倒把问题复杂化了 其实用GetScrollPos和SetScrollPos互相结合就能完成需要的功能 以下是一段通用代码,在BCB测试通过,垂直滚动条用SB_VERT,水平滚动条用SB_HORZ while (true) { if (TestMemo->Font->Size == 1) break; if (SetScrollPos(TestMemo->Handle, SB_HORZ, 1, false) > 0) { TestMemo->Font->Size--; } else { if (GetScrollPos(TestMemo->Handle, SB_HORZ) == 0) break; TestMemo->Font->Size--; } }以下是改写成delphi的代码 while (true) do begin if TestMemo.Font.Size = 1 then break; if SetScrollPos(TestMemo.Handle, SB_VERT, 1, false) > 0 then begin TestMemo.Font.Size = TestMemo.Font.Size-1; end else begin if GetScrollPos(TestMemo.Handle, SB_VERT) = 0 then break; TestMemo.Font.Size = TestMemo.Font.Size-1; end; end;
while (GetScrollPos(Memo1->Handle;ssVertical) > 0) {
//do something
}
have a try
while (GetScrollPos(Memo1->Handle, SB_VERT) > 0)
begin
//do something
end;
begin
while GetScrollPos(Memo1.Handle, SB_VERT)>0 do
begin
if Memo1.Font.Size=1 then break;
Memo1.Font.Size := Memo1.Font.Size - 1;
end;
end;
首先要设置Memo1.ScrollBars等于ssVertical
-------------------------------------------------------------
难道就不会变统一下处理吗?
在调用GetScrollPos(Memo1.Handle, SB_VERT)之前先自己设定滚动条的位置
SetScrollPos(Memo1.Handle, SB_VERT, 1, false); //false表示不刷新Memo的内容
借用楼上的代码
SetScrollPos(Memo1.Handle, SB_VERT, 1, false); //这里设置滚动条的位置,但不刷新内容
while GetScrollPos(Memo1.Handle, SB_VERT)>0 do
begin
if Memo1.Font.Size=1 then break;
Memo1.Font.Size := Memo1.Font.Size - 1;
end;
我现在没有delphi环境,不能用delphi测试
我用BCB测试了一下,我做的是水平滚动条的测试,垂直的只要把SB_HORZ改成SB_VERT就可以TRect rect;
int nMin=0, nMax=0;
::GetClientRect(TestMemo->Handle, &rect);
GetScrollRange(TestMemo->Handle, SB_HORZ, &nMin, &nMax);
while (nMax > (rect.Width()-2)) { //2作为误差补偿,因为如果文字刚好达到边缘,滚动条就开始有效了
if (TestMemo->Font->Size == 1) break;
TestMemo->Font->Size--;
GetScrollRange(TestMemo->Handle, SB_HORZ, &nMin, &nMax);
}
----------------------------------------
不知道楼主想获得的size是指什么?宽度吗?可以这样试试
TRect rect;
int nWidth1=0, nWidth2=0;
::GetClientRect(TestMemo->Handle, &rect);
nWidth1 = rect.Width();
GetWindowRect(TestMemo->Handle, &rect);
nWidth2 = rect.Width();
int nSize = nWidth2 - nWidth1; //滚动条宽度
其实用GetScrollPos和SetScrollPos互相结合就能完成需要的功能
以下是一段通用代码,在BCB测试通过,垂直滚动条用SB_VERT,水平滚动条用SB_HORZ
while (true) {
if (TestMemo->Font->Size == 1) break;
if (SetScrollPos(TestMemo->Handle, SB_HORZ, 1, false) > 0) {
TestMemo->Font->Size--;
} else {
if (GetScrollPos(TestMemo->Handle, SB_HORZ) == 0) break;
TestMemo->Font->Size--;
}
}以下是改写成delphi的代码
while (true) do
begin
if TestMemo.Font.Size = 1 then break;
if SetScrollPos(TestMemo.Handle, SB_VERT, 1, false) > 0 then
begin
TestMemo.Font.Size = TestMemo.Font.Size-1;
end else
begin
if GetScrollPos(TestMemo.Handle, SB_VERT) = 0 then break;
TestMemo.Font.Size = TestMemo.Font.Size-1;
end;
end;