Drawing text in C#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gkostova
    New Member
    • Jul 2007
    • 4

    Drawing text in C#

    Hi , Can someone one help me please.I'm begginer in C#, and I try to learn it , but I need help.
    I have in my form 2 spliterPamels, in one of them I want to display text when form is load. The problem is that I want to create the text dinamicaly but it doesn't work . Here is the code I try to test
    protected override void OnPaint(PaintEv entArgs e)
    {
    paint_Text(e.Gr aphics);
    base.OnPaint (e);
    }

    ....
    private void paint_Text(Grap hics gr)
    {

    int beginYtop = mainsplitContai ner.Panel2.Marg in.Top;
    int beginXtop = mainsplitContai ner.Panel2.Marg in.Left;
    int beginYbottom = mainsplitContai ner.Panel2.Marg in.Bottom;
    int beginXbottom = mainsplitContai ner.Panel2.Marg in.Right;
    RectangleF rect = new RectangleF(begi nYtop + 10, beginXtop + 10, beginYbottom - 10,
    beginXbottom - 10);

    Font objFont = new System.Drawing. Font("Lucida Console", 12, FontStyle.Itali c);
    StringFormat sf = (StringFormat)S tringFormat.Gen ericTypographic .Clone();
    sf.Alignment = StringAlignment .Center;
    sf.LineAlignmen t = StringAlignment .Center;
    sf.Trimming = StringTrimming. EllipsisWord;
    gr.DrawString(" ERRR", objFont, System.Drawing. Brushes.Azure,
    rect, sf);
    objFont.Dispose ();
    }
    ...
    private void Form1_Load(obje ct sender, EventArgs e)
    {
    Graphics g = Graphics.FromHw nd(this.Handle) ;
    paint_Text(g);
    }

    Can you pese help me,
    Thank you
Working...