Johan Vromans wrote:
Hi,

I have a Wx::TextCtrl that contains a series of words. Its contents
are wrapped if too long. I want it to always show two lines of text,
and a scrollbar if there's more than two lines to show.

Piece of cake? Yes, except that I cannot find the right value for the
height of the TextCtrl.

I tried something like this:

  my $sz = 24;
  $self->{tc_message}->SetFont(Wx::Font->new($sz, wxDEFAULT, wxNORMAL, wxNORMAL, 0, 
""));
  my $scale = 3.6;
  $self->{tc_message}->SetMinSize(Wx::Size->new(-1,$scale*$sz));
  $self->{tc_message}->SetSize(Wx::Size->new(-1, $scale*$sz));

The scale value of 3.6 gives acceptable results on both Linux GTK and
Windows.

But I think there's should be a better, more correct way.

Any ideas?

I am not sure there is a correct way, a slightly better (untested) way might be:

  $txt->SetClientSize(Wx::Size->new(-1,2*$font_height));
  my $height = $txt->GetSize->height;
  # use height to set min size/size

this SHOULD take into account the external border, but I am not sure it takes into account the internal padding the control might decide to add.

(Yes, I looked at using dialog points but that didn't seem to help.)

You must use GetTextExtents to determine the pixel size of a font; the conversion might be 1 point == 1 pixel in your current setup, but it is not guaranteed to be (it depends on screen DPI).

HTH a bit,
Mattia

  • Line height Johan Vromans
    • Re: Line height Mattia Barbon

Reply via email to