垂直滚动条始终位于底部 - Delphi

时间:2013-12-09 00:54:05

标签: delphi

我有一个备忘录字段,可以显示如何使用我的GUI的说明。我为备忘录启用了水平和垂直滚动条。两个滚动条都显示为详细说明,并且垂直和水平都超出了框架。但是,垂直滚动条始终位于底部,因此除非用户向上滚动,否则他将在开头时错过指令。水平滚动条正确在左侧。我需要在Object Inspector中更改备忘录的某些属性,以确保垂直条位于顶部,以便用户可以从头开始阅读说明吗?

我已将指令保存为名为Instructions的字符串。我通过以下代码将此字符串复制到备忘录中:

procedure TfrmHSR.mmuDispInstructionsClick(Sender: TObject);
//display instructions in Memo field
var
  DispText: string;
begin
  Memo1.Clear;
  DispText := Wraptext(Instructions, 125);
  Memo1.Lines.Add(DispText);
  mmuDisplayClear.Enabled := True;
  mmuFileSave.Enabled := False;
  //if input file created and opened, allow display of input data
  if Assigned(InputFile) then //if TStringList has been created
    begin
      if (InputFile.Count > 0) then mmuDispData.Enabled := True
      else mmuDispData.Enabled := False;
    end
  else mmuDispData.Enabled := False;

  //if results available, allow display
  if Assigned(OutputFile) then //if TStringList has been created
    begin
      if (OutputFile.Count > 0) then mmuDispResults.Enabled := True
      else mmuDispResults.Enabled := False;
    end
  else mmuDispResults.Enabled := False;
  mmuDispInstructions.Enabled := False;
end;

2 个答案:

答案 0 :(得分:2)

对您遇到的问题最简单的解决方法就是不使用TMemo.ClearTMemo.Add,而是直接分配给Text属性作为整体。 (您可以同时拥有所有文本,因此根本不需要使用Add。)

我冒昧地对您的代码进行了一些其他微小的更改,您可能也会觉得有用; IMO读起来更清晰一点,而且更短。 : - )

//display instructions in Memo field
procedure TfrmHSR.mmuDispInstructionsClick(Sender: TObject);
var
  DispText: string;
begin
  DispText := Wraptext(Instructions, 125);
  Memo1.Text := DispText;

  mmuDisplayClear.Enabled := True;
  mmuFileSave.Enabled := False;

  //if input file created and opened, allow display of input data
  //if TStringList has been created
  mnuDispData.Enabled := Assigned(InputFile) and (InputFile.Count > 0); 

  //if results available, allow display
  //if TStringList has been created
  mnuDispResults.Enabled := Assigned(OutputFile) and (OutputCount > 0);
  mmuDispInstructions.Enabled := False;
end;

答案 1 :(得分:0)

//if you need to add the lines using lines.add() you can use this...

    procedure TForm2.Button1Click(Sender: TObject);
    var
      I: Integer;
     begin        
       for I := 0 to 1000 do
        begin
         memo1.Lines.add('line ' + intToStr(i));
        end;
    SendMessage(Memo1.Handle, EM_SETSEL, 0, 0);
    SendMessage(Memo1.Handle, EM_SCROLLCARET, 0, 0);        
    end;