DrawString only works in top-left part of form vb.net

Posted by WillumMaguire on Stack Overflow See other posts from Stack Overflow or by WillumMaguire
Published on 2012-10-31T22:45:22Z Indexed on 2012/10/31 23:00 UTC
Read the original article Hit count: 228

Here is my code

Public Class Form1

Public MyFormObject As Graphics = Me.CreateGraphics
Public objFont = New System.Drawing.Font("arial", 20)
Public a, b As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Randomize()
    For i = 1 To 10
        a = CInt(Int(Rnd() * Me.Width))
        b = CInt(Int(Rnd() * Me.Height))
        MyFormObject.DrawString("text", objFont, System.Drawing.Brushes.Black, a, b)
    Next
End Sub
End Class

As you can see, I have one button that draws the string "text" randomly in the form 10 times. My problem is that it will ONLY draw the string in the upper-left portion of the form, roughly 260x260 starting at 0,0. It literally cuts off the text if it goes beyond. Why is this? Shouldn't it work for the entire form?

© Stack Overflow or respective owner

Related posts about .NET

Related posts about vb.net