Jump to content

Recommended Posts

Posted

Hi,

I use a canvas, which could be longer than the available height of the form. So I put the canvas on a scrollbox. 

But there are no scrollbars visible, so I cannot scroll the canvas/scrollbox.

I've added a sample (call with localhost:8222 ). The examples adds 100 lines to the canvas. I want to scroll through the canvas, but it's not possible.

Thanks in advance

Mike

 

UniGui.rar

Posted

Hello,

45 minutes ago, likemike said:

The examples adds 100 lines to the canvas. I want to scroll through the canvas, but it's not possible.

Solution:

procedure TMainmForm.FillCanvas;
var
  Count, LineStep, FontSize, BottomMargin, H: Integer;
begin
  Count := 100;
  LineStep := 25;
  FontSize := 16;
  BottomMargin := 10;

  H := Count * LineStep + FontSize + BottomMargin;

  UnimCanvas1.Align := alNone; // important
  UnimCanvas1.Height := H;
  UnimCanvas1.Width := UnimScrollBox1.Width - 5;

  UnimCanvas1.JSInterface.JSCode(
    'setTimeout(function(){' +
    '  var me = '#1'._cc_;' +
    '  if (me && me.canvas) {' +
    '    me.canvas.height = ' + IntToStr(H) + ';' +
    '    me.canvas.style.height = "' + IntToStr(H) + 'px";' +
    '    me.clearRect(0,0,me.canvas.width,me.canvas.height);' +
    '    me.fillStyle = "' + uniColor2Web(clMaroon, 1) + '";' +
    '    me.font = "' + IntToStr(FontSize) + 'px sans-serif";' +
    '    for (var k=1; k<=' + IntToStr(Count) + '; k++) {' +
    '      me.fillText("New Line: " + k, 20, ' + IntToStr(LineStep) + '*k);' +
    '    }' +
    '  }' +
    '}, 0);'
  );
end;

 

×
×
  • Create New...