dotgnu-pnet
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Pnet-developers] System.Windows.Forms bug: Line breaking occurs in labe


From: Bruno Haible
Subject: [Pnet-developers] System.Windows.Forms bug: Line breaking occurs in labels when it shouldn't
Date: Tue, 6 Jan 2004 15:48:19 +0100
User-agent: KMail/1.5

Using pnet-0.6.2 on X11. When the size allocated to a label is exactly
its preferred size, the text should fit. (That's the definition of
preferred size, isn't it?) But here some line breaking kicks in (wow!),
which one would expect to occur only if the allowed width is smaller
than the preferred width.

=============================== hello.cs ============================
using System; /* String, EventHandler */
using System.Drawing; /* Point, Size */
using System.Windows.Forms; /* Application, Form, Label */
public class Hello {
  class HelloWindow : Form {
    private int border;
    private Label label1;
    public HelloWindow () {
      border = 2;
      label1 = new Label();
      label1.Text = "Hello, beautiful World!";
      label1.ClientSize = new Size(label1.PreferredWidth /* + 0 or + 1 */,
                                   label1.PreferredHeight);
      Controls.Add(label1);
      Size total = ComputePreferredSizeWithoutBorder();
      LayoutControls(total.Width, total.Height);
      ClientSize = new Size(border + total.Width + border, border + 
total.Height + border);
    }
    protected override void OnResize(EventArgs ev) {
      LayoutControls(ClientSize.Width - border - border, ClientSize.Height - 
border - border);
      base.OnResize(ev);
    }
    private Size ComputePreferredSizeWithoutBorder () {
      return new Size(label1.PreferredWidth, label1.PreferredHeight);
    }
    private void LayoutControls (int totalWidth, int totalHeight) {
      label1.Location = new Point(border, border);
    }
    private void Quit (Object sender, EventArgs ev) {
      Application.Exit();
    }
  }
  public static void Main () {
    Application.Run(new HelloWindow());
  }
}
======================================================================

$ cscc -winforms hello.cs -o hello.exe
$ ilrun hello.exe
; Only the words "Hello, beautiful" are visible; below it you can see a row of
; pixels coming from the word "World!".

If the comment is replaced with "+ 1", the label is displayed correctly,
but then there is one empty pixel room at the right end.

Maybe this could be fixed by changing System.Drawing/Graphics.cs line 1353:
replace ">=" with ">" ?

Bruno



reply via email to

[Prev in Thread] Current Thread [Next in Thread]