I created new userControl empty & used paint event and drawstring but have bugs help:

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Chocolade
    New Member
    • Aug 2010
    • 69

    I created new userControl empty & used paint event and drawstring but have bugs help:

    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Drawing;
    using System.Data;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    
    namespace WindowsFormsApplication1
    {
        public partial class NewsControl : UserControl
        {
            public NewsControl()
            {
                InitializeComponent();
            }
    
            private void NewsControl_Paint(object sender, PaintEventArgs e)
            {
                // Create string to draw.
                String drawString = "Sample Text";
                // Create font and brush.
                Font drawFont = new Font("Arial", 16);
                SolidBrush drawBrush = new SolidBrush(Color.Black);
                // Create point for upper-left corner of drawing.
                float x = 150.0F;
                float y = 50.0F;
                // Set format of string.
                StringFormat drawFormat = new StringFormat();
                drawFormat.FormatFlags = StringFormatFlags.DirectionVertical;
                // Draw string to screen.
                e.Graphics.DrawString(drawString, drawFont, drawBrush, x, y, drawFormat);
            }
        }
    }
    I drag the control from the toolbox to form1 and i see in it Sample Text and when i run my program nothing is shown up in the control.

    I tried in the control code to put in the end : this.Refresh(); and this.Validate() ;

    But then when im doing rebuild project my program got stuck and the control in the form1 designer is blinking before i even run the application.

    Whats wrong here?



    Thanks.
Working...