VS 2008: Writing text on Windows form

Anybody knows how to write text on Winform without any controls on it?
Thanks.
quasar_eeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

PaulHewsCommented:
In the Form_Paint event:
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
    e.Graphics.DrawString("This is a test", Me.Font, Brushes.Blue, 10, 10)
End Sub

Open in new window

0
quasar_eeAuthor Commented:
Making this code work. Do you think there might be easier way to accomplish this? I believe forms Text property in older versions of Visual Studio allowed to accomplish it . It displays text in the form caption now instead.
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

PaulHewsCommented:
>I believe forms Text property in older versions of Visual Studio allowed to accomplish it . It displays text in the form caption now instead.

No.  In VB6, one could use the Print method to put text on a form... That method does not exist in the .NET framework, so GDI+ or using a label or other control is the only way.

0
quasar_eeAuthor Commented:
PaulHews, your code works. Thanks.
Do you know by chance how to write on the new line?
0
PaulHewsCommented:
You can position the text using the Y position... Use FontHeight to approximate the height of the new line.

    Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        For i As Integer = 0 To 9
            e.Graphics.DrawString("This is a test", Me.Font, Brushes.Blue, 10, 10 + i * Me.FontHeight)
        Next
    End Sub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.