Results 1 to 6 of 6

Thread: vb 2010 module's

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2011
    Posts
    118

    vb 2010 module's

    hey

    im making a game in vb 2010. but im new to 2010 so i dont know how it works (because i used 6.0 before).

    I have a form, where the graphics should be drawn on. "frmMainGame"
    I have a module where I want to put all Graphic things in.
    so I have in my module Graphics.vb

    Code:
        Public Sub DrawPlayerCoordinates()
    
            G.DrawString("Map: " & GetPlayerMap(MyIndex) & vbCrLf & "X: " & GetPlayerX(MyIndex) & vbCrLf & "Y: " & GetPlayerY(MyIndex), Game.font, Brushes.Red, 15, 15)
    
        End Sub
    now I have a button what calls the sub "Call DrawPlayerCoordinates()"

    but now it gives an error because it don't know where to draw the string. So how do the code above know it should draw it on "frmMainGame" and not in a module what isn't possible?

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,416

    Re: vb 2010 module's

    try this:

    vb Code:
    1. Module Module1
    2.     Public Sub DrawPlayerCoordinates(ByVal frm As Form)
    3.         Dim g As Graphics = frm.CreateGraphics
    4.         g.DrawString("Map: " & GetPlayerMap(MyIndex) & vbCrLf & "X: " & GetPlayerX(MyIndex) & vbCrLf & "Y: " & GetPlayerY(MyIndex), frm.Font, Brushes.Red, 15, 15)
    5.     End Sub
    6. End Module

    to call it from your button_click event:

    vb Code:
    1. Public Class Form1
    2.  
    3.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    4.         DrawPlayerCoordinates(Me)
    5.     End Sub
    6.  
    7. End Class

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2011
    Posts
    118

    Re: vb 2010 module's

    no errors, but it's not drawing anything.. :/

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,416

    Re: vb 2010 module's

    are you sure theres an empty part of the form at 15, 15?
    it won't draw over controls

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jan 2011
    Posts
    118

    Re: vb 2010 module's

    actually it should draw over the colors or not? if not -> how should i draw it over the colors?

    Code:
           G.DrawString(Player(0).Name, Me.Font, Brushes.AntiqueWhite, 145, 140)
    this draws the name of my player and i'll see the text. (this code is still in frmMainGame but should be also in the modGraphics).

  6. #6
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,416

    Re: vb 2010 module's

    the problem with drawing on your form with CreateGraphics is that the graphics aren't persistent + they'll be erased next time the form is repainted.
    the easiest workaround is to put the:

    vb Code:
    1. DrawPlayerCoordinates(Me)

    ...line in the form's _paint event

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width