DebateFort - Where Warriors Come To Debate
RAGECRY - Funny, Amusing, Interesting, Trending & Viral Videos and Images
GameOrc - Free Flash Games Online
Results 1 to 5 of 5
  1. #1
    Banned
    BANNED!
    {Banned}**HACKER**'s Avatar
    Join Date
    Mar 2011
    Gender
    male
    Posts
    846
    Reputation
    8
    Thanks
    677
    My Mood
    Cheerful

    Question Drawing problems!

    Hello,
    I was wondering if anyone has a solution to keep something drawn on my screen, I have kind of fixed it by just putting a Timer in my code and getting it to draw the image over and over but this causes lag and is a bit of a problem!
    If i don't do that to keep the image on the screen, the image will show but as soon as something refreshes behind it the drawn image will be gone!
    Is there anyway to keep the image drawn on the screen by not using a timer just to repeat the drawing process ?

    Here is my whole code if this helps:
    Code:
    Public Class Form1
        Declare Function GetDC Lib "user32.dll" (ByVal hWnd As IntPtr) As System.IntPtr
        Declare Function ReleaseDC Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal hdc As IntPtr) As Integer
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
        End Sub
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim width As String = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width.ToString
            Dim height As String = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height.ToString
            Label1.Text = width
            Label2.Text = height
            Dim width2 As Integer = CInt(Label1.Text.ToString)
            Dim height2 As Integer = CInt(Label2.Text.ToString)
            Label1.Text = CStr(width2 / 2)
            Label2.Text = CStr(height2 / 2)
            Timer1.Start()
        End Sub
        Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
            Dim width3 As Integer = Label1.Text
            Dim height3 As Integer = Label2.Text
                Dim hdc As IntPtr = GetDC(IntPtr.Zero)
                Dim gr As Graphics = Graphics.FromHdc(hdc)
            Dim Point As New Point(width3, height3)
            If RadioButton1.Checked = True Then
                gr.DrawImage(My.Resources.cross1, Point)
            ElseIf RadioButton2.Checked = True Then
                gr.DrawImage(My.Resources.cross2, Point)
            ElseIf RadioButton3.Checked = True Then
                gr.DrawImage(My.Resources.cross3, Point)
            End If
        End Sub
    
        Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
            If RadioButton1.Checked = True Then
                PictureBox1.Image = My.Resources.cross1
            End If
            If RadioButton2.Checked = True Then
                PictureBox1.Image = My.Resources.cross2
            ElseIf radiobutton3.checked = True Then
                PictureBox1.Image = My.Resources.cross3
            End If
        End Sub
    End Class
    Thanks in advance guys

  2. #2
    Expert Member
    MPGH Member
    Pingo's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Posts
    658
    Reputation
    24
    Thanks
    702
    My Mood
    Blah
    Adding your code to the paint event should do the job.

    I also wouldnt use that second timer either. You can handle all that just using Radiobutton checked changed.
    Something like this should work
    Code:
        Private Sub _CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged, RadioButton2.CheckedChanged, radioButton3.CheckedChanged
            PictureBox1.Image = If(RadioButton1.Checked, My.Resources.cross1, If(RadioButton2.Checked, My.Resources.cross2, My.Resources.cross3))
        End Sub

  3. #3
    Threadstarter
    Banned
    BANNED!
    {Banned}**HACKER**'s Avatar
    Join Date
    Mar 2011
    Gender
    male
    Posts
    846
    Reputation
    8
    Thanks
    677
    My Mood
    Cheerful
    Thanks man, using paint event now and its working better anyway but still not perfect, and thanks for that code

  4. #4
    Expert Member
    MPGH Member
    Pingo's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Posts
    658
    Reputation
    24
    Thanks
    702
    My Mood
    Blah
    np dude, i didnt try fixing the main function. I'll see if i can help you further so you can get the first part working the way you want.
    I cant really tell whats wrong just by looking at it, im not a vb coder. So i'll create the code on my end to see what the problem is.

    EDIT:
    Looks like flicker. Not really sure how to fix that but i have another option.
    Instead of drawing your image on screen, draw it on another form.

    Example
    Create another form in your project. I called mine Picures
    Set the FormBorderStyle to None

    Something like this can be used to change the settings
    Code:
        Public Sub CreateImage(ByVal _Form As Form, ByVal _Size As Size, ByVal _Location As Point, ByVal _Image As Image)
            If Not _Form.Visible Then
                _Form.Show()
            End If
            _Form.Location = _Location
            _Form.Size = _Size
            _Form.BackgroundImage = _Image
            _Form.BackgroundImageLayout = ImageLayout.Stretch
        End Sub
    ByVal _Form As Form = Second Form
    ByVal _Size As Size = size you would like the image
    ByVal _Location As Point = location on screen
    ByVal _Image As Image = Image you want

    On the same RadioButton Checked Changed
    Code:
        Private Sub _CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged, RadioButton2.CheckedChanged, RadioButton3.CheckedChanged
            Dim _Size As Size = Screen.PrimaryScreen.Bounds.Size
            Dim _Image As Image = If(RadioButton1.Checked, My.Resources.cross1, If(RadioButton2.Checked, My.Resources.cross2, My.Resources.cross3))
            CreateImage(Pictures, New Size(150, 150), New Point(_Size.Width / 2, _Size.Height / 2), _Image)
        End Sub
    I only have the size 150x150 and some random location. But everytime i change radio button, the image changes without flicker.
    Maybe have a mess around with it, might help ya.
    Last edited by Pingo; 06-14-2012 at 04:52 AM.

  5. #5
    Threadstarter
    Banned
    BANNED!
    {Banned}**HACKER**'s Avatar
    Join Date
    Mar 2011
    Gender
    male
    Posts
    846
    Reputation
    8
    Thanks
    677
    My Mood
    Cheerful
    Hmm seems another good choice ill have to try this Thanks alot for your help

Similar Threads

  1. anyone else having this problem with instant draw?
    By akkuro in forum Combat Arms Mod Discussion
    Replies: 6
    Last Post: 12-23-2010, 02:48 PM
  2. Drawing problems...
    By Mr.Magicman in forum Combat Arms Coding Help & Discussion
    Replies: 8
    Last Post: 10-04-2010, 04:13 PM
  3. [Help]Problem with Drawing + Value
    By HazXoD3D in forum Visual Basic Programming
    Replies: 0
    Last Post: 03-20-2010, 06:47 PM
  4. WPE problem...
    By styx23 in forum General Game Hacking
    Replies: 8
    Last Post: 01-18-2006, 07:51 PM
  5. Problem Wit Hacking Programs
    By f5awp in forum General Gaming
    Replies: 5
    Last Post: 01-10-2006, 05:44 AM