Visual Basic .NET Forums  
Click here to advertise with us

Go Back   Visual Basic .NET Forums > VB.NET > Graphics/GDI+

Graphics/GDI+ Graphics discussion for VB.NET applications, Winforms, Web, Compact Framework, etc.

VB.NET Forums Newsletter Signup:
Email address:


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-02-2009, 8:00 PM
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 Drawstring string disappears when Button on Form

Hi,

I'm drawing a game board with GDI in VB2005. (it's like a gomoku board)
First i draw a background with FillRectangle, then I draw the grid with
DrawLine, then I draw some row and column letters with DrawString.
They are all in the Paint event of the Form.

Everything works fine, until i put some Buttons on the Form (not at runtime).
Then the column and row letters go behind the background rectangle (so they can't be seen ), when the form is shown. The grid remains on top of the background rectangle.

I would like the letters to stay on top of the other graphics.
Thanks in advance for the help
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 05-04-2009, 10:42 PM
jmcilhinney's Avatar
VB.NET Forum Moderator
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Aug 2004
Location: Sydney, Australia
Age: 40
Posts: 6,123
Reputation: 541
jmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalist
Default

Can you show us your Paint event handler?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 05-05-2009, 7:36 AM
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)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





All times are GMT -4. The time now is 8:03 AM.

Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2


For advertising opportunities click here.