View Single Post
  #3 (permalink)  
Old 05-05-2009, 8:36 AM
albundy albundy is offline
VB.NET Forum Newbie
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: May 2009
Posts: 3
Reputation: 0
albundy is on a distinguished programming path ahead
Default

Hi,
meanwhile i found a solution to my problem, with help of this thread:

Keeping Graphics on the form

my original code was :
Code:
Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub
    Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        ' grid back---------------------------------------------
        Dim w As Graphics = Me.CreateGraphics
        w.FillRectangle(Brushes.Beige, 20, 20, 20 + 390, 20 + 390)
        w.Dispose()


        ' letters-----------------------------------------------
        Dim fontObj As Font
        fontObj = New System.Drawing.Font("Times", 10, FontStyle.Bold)
        Dim stringFormat As New StringFormat()
        stringFormat.Alignment = StringAlignment.Far
        'stringFormat.LineAlignment = StringAlignment.Near
        Dim i As Integer
        Dim f As Integer
        Dim mystring1 = New String() {"A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T"}
        Dim mystring2 = New String() {"19", "18", "17", "16", "15", "14", "13", "12", "11", "10", "9", "8", "7", "6", "5", "4", "3", "2", "1"}
        For i = 0 To 18
            e.Graphics.DrawString(mystring1(i), fontObj, Brushes.Chocolate, 45 + i * 20, 410)
        Next
        For f = 0 To 18
            e.Graphics.DrawString(mystring2(f), fontObj, Brushes.Chocolate, 40, 35 + f * 20, stringFormat)
        Next
    End Sub
    'Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)

    'End Sub
End Class
(when i put a button on the form, or resized it, the letters disappeared, i guess a new rectangle was drawn on top of all graphics, but no new letters?)
then i noticed, i have two Graphics objects "w", and "e"
and changed it like this:

Code:
' grid back---------------------------------------------
        e.Graphics.FillRectangle(Brushes.Beige, 20, 20, 20 + 390, 20 + 390)

now it works fine, but i don't understand why in the first version only the rectangle is redrawn on form resize (or putting a button on the form)
Reply With Quote