DrawString error?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • kynos

    #1

    DrawString error?

    I would like to paint a box using DrawString, standard Unicode
    characters (box drawings characters) and monospaced font.

    Unfortunately for some fonts painted lines contain a break.

    Example code, in whom one can see the error:

    private void Form1_Paint (object sender, PaintEventArgs e)
    (
    Font font = new Font ( "Courier New", 9);
    e.Graphics.Draw String (new String ( '\u2500', 200),
    font,
    new SolidBrush (Color.Red), new PointF (0, 0),
    StringFormat.Ge nericTypographi c);
    )

    I must use DrawString, not the DrawLine etc. fuctions.
    Does anybody knows how paint lines via the DrawString, so that did not
    have the breaks?
  • TAB

    #2
    Re: DrawString error?

    Hi

    If I understand you right, you mean a line break or word wrap, if so you
    could use
    StringFormat strFormat = StringFormat.Ge nericTypographi c;
    strFormat.Forma tFlags |= StringFormatFla gs.NoWrap;


    "kynos" <niechciane_mai le@gazeta.plskr ev i meddelandet
    news:3d40e8b3-aac8-49dc-85a3-5df422d65687@m3 g2000hsc.google groups.com...
    I would like to paint a box using DrawString, standard Unicode
    characters (box drawings characters) and monospaced font.
    >
    Unfortunately for some fonts painted lines contain a break.
    >
    Example code, in whom one can see the error:
    >
    private void Form1_Paint (object sender, PaintEventArgs e)
    (
    Font font = new Font ( "Courier New", 9);
    e.Graphics.Draw String (new String ( '\u2500', 200),
    font,
    new SolidBrush (Color.Red), new PointF (0, 0),
    StringFormat.Ge nericTypographi c);
    )
    >
    I must use DrawString, not the DrawLine etc. fuctions.
    Does anybody knows how paint lines via the DrawString, so that did not
    have the breaks?

    Comment

    • kynos

      #3
      Re: DrawString error?

      Hi,

      Thanks for your reply, but I do not mean word wrap or a line break.
      If you choose Courier New, _eight_ pts font, and DrawString using
      string containts some graphical unicode character ('horizontal line')
      you have straight line without gaps on it.

      But if you choose _nine_ pts (and several another sizes) font there
      are gaps on the line.

      Please, try the code I posted before - it looks really strange.

      Comment

      • TAB

        #4
        Re: DrawString error?

        Using your example, I get a straight red line across the form, no gaps.
        Something wrong with your font file?

        "kynos" <niechciane_mai le@gazeta.plskr ev i meddelandet
        news:1227718c-b297-42d7-a11c-e3d16d3b6659@f3 6g2000hsa.googl egroups.com...
        Hi,
        >
        Thanks for your reply, but I do not mean word wrap or a line break.
        If you choose Courier New, _eight_ pts font, and DrawString using
        string containts some graphical unicode character ('horizontal line')
        you have straight line without gaps on it.
        >
        But if you choose _nine_ pts (and several another sizes) font there
        are gaps on the line.
        >
        Please, try the code I posted before - it looks really strange.

        Comment

        • kynos

          #5
          Re: DrawString error?

          I have got gaps on XP Pro SP3 and Vista Ultimate SP1.
          The example was run on MSV C# Express Edition 2008.

          Have you tried my code with 8 pts and 9 pts font size?
          And there is no difference betwen them?
          On my systems, with the 9 pts font, the gaps size is about 1 pixel,
          and take place every few (5) character.

          Comment

          • TAB

            #6
            Re: DrawString error?

            I have so far tried 7, 7.5, 8, 8.5 9, 10, 11 and they all show nothing like
            you describe, so I am still aiming at a font problem or maybe a graphics
            driver problem?

            "kynos" <niechciane_mai le@gazeta.plskr ev i meddelandet
            news:55719a01-51e3-43d5-bb7e-af4efe02f9ac@x3 5g2000hsb.googl egroups.com...
            I have got gaps on XP Pro SP3 and Vista Ultimate SP1.
            The example was run on MSV C# Express Edition 2008.
            >
            Have you tried my code with 8 pts and 9 pts font size?
            And there is no difference betwen them?
            On my systems, with the 9 pts font, the gaps size is about 1 pixel,
            and take place every few (5) character.

            Comment

            • kynos

              #7
              Re: DrawString error?

              Did you use Courier New font?

              Comment

              • Peter Duniho

                #8
                Re: DrawString error?

                On Fri, 19 Sep 2008 05:38:40 -0700, kynos <niechciane_mai le@gazeta.pl>
                wrote:
                [...]
                I must use DrawString, not the DrawLine etc. fuctions.
                Does anybody knows how paint lines via the DrawString, so that did not
                have the breaks?
                The bottom line: you _cannot_ depend on being able to draw text characters
                and have them produce some specific graphical output, such as a line.
                Judicious choices for font family and size can produce nearly-perfect
                results, and you might have some better success using the TextRenderer
                class, but there will always be exceptions.

                If you want a 100% reliable line, you must use DrawLine().

                If you can explain why it is you want to restrict yourself to using
                DrawString(), it's possible someone could suggest an alternative direction
                to take that still meets whatever goal you have. Surely the goal is not
                in and of itself to only use DrawString().

                Pete

                Comment

                • TAB

                  #9
                  Re: DrawString error?

                  Yes, exact copy of your example. Only changed font size. By the way, I'm
                  running Vista SP1, .NET 3.5 VS 2008 C# Express.

                  "kynos" <niechciane_mai le@gazeta.plskr ev i meddelandet
                  news:9944e34c-9a9c-4d0d-9e73-e087fa83c8f6@f6 3g2000hsf.googl egroups.com...
                  Did you use Courier New font?

                  Comment

                  • kynos

                    #10
                    Re: DrawString error?

                    TextRenderer seems to be better way - I will have to test it.
                    Tank you Tab & Peter.

                    Comment

                    Working...