Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > .NET Framework > Forum > VB.NET ติด Error เกี่ยวกับ Event Paint ช่วยตอบหน่อยคร่า



 

VB.NET ติด Error เกี่ยวกับ Event Paint ช่วยตอบหน่อยคร่า

 



Topic : 076394

Guest




Code (VB.NET)
Imports System.Drawing.Drawing2D
Imports System.Runtime.InteropServices
Public Class Form1

    Dim bmp As Bitmap
    Dim Blocation As Rectangle
    Dim g As Graphics
    Dim Dragging As Boolean = False
    Dim OffsetX, OffsetY As Integer

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        bmp = New Bitmap(My.Resources.tree1_1)
        bmp.MakeTransparent(Color.White)
        Blocation = New Rectangle(10, 10, bmp.Width, bmp.Height)
        AddHandler Panel2.Paint, AddressOf Panel2_Paint
        AddHandler Panel2.MouseMove, AddressOf Panel2_MouseMove
        AddHandler Panel2.MouseDown, AddressOf Panel2_MouseDown
        AddHandler Panel2.MouseUp, AddressOf Panel2_MouseUp

    End Sub

    Private Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
        bmp = New Bitmap(My.Resources.tree1_2)
        bmp.MakeTransparent(Color.White)
        Blocation = New Rectangle(30, 30, bmp.Width, bmp.Height)


    End Sub
    Private Sub Panel2_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel2.Paint
        e.Graphics.DrawImage(bmp, Blocation)
    End Sub
    Private Sub Panel2_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel2.MouseMove
        ' See if we're dragging.
        If (Dragging) Then
            ' We're dragging the image. Move it.
            Blocation.X = e.X + OffsetX
            Blocation.Y = e.Y + OffsetY

            ' Redraw.
            Panel2.Invalidate()
        Else
            ' We're not dragging the image. See if we're over it.
            Dim new_cursor As Cursor = Cursors.Default
            If (PointIsOverPicture(e.X, e.Y)) Then
                new_cursor = Cursors.Hand
            End If
            If (Panel2.Cursor <> new_cursor) Then
                Panel2.Cursor = new_cursor
            End If
        End If
    End Sub

    Private Sub Panel2_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel2.MouseDown
        ' See if we're over the picture.
        If (PointIsOverPicture(e.X, e.Y)) Then
            ' Start dragging.
            Dragging = True

            ' Record the offset from the mouse to the picture's origin.
            OffsetX = Blocation.X - e.X
            OffsetY = Blocation.Y - e.Y
        End If
    End Sub

    Private Sub Panel2_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel2.MouseUp
        Dragging = False
    End Sub


    Private Function PointIsOverPicture(ByVal x As Integer, ByVal y As Integer) As Boolean
        ' See if it's over the picture's bounding rectangle.
        If ((x < Blocation.Left) OrElse _
            (y < Blocation.Top) OrElse _
            (x >= Blocation.Right) _
            OrElse (y >= Blocation.Bottom)) _
                Then Return False

        ' See if the point is above a non-transparent pixel.
        Dim i As Integer = x - Blocation.X
        Dim j As Integer = y - Blocation.Y
        Return (bmp.GetPixel(i, j).A > 0)
    End Function

End Class



รูปที่Error

Error



Tag : .NET, VB.NET







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2012-03-30 12:57:10 By : kimlung View : 1190 Reply : 2
 

 

No. 1



โพสกระทู้ ( 100 )
บทความ ( 0 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Facebook

Addhandler ใช้ครั้งเดียวตอน from_load นะครับ

Code (VB.NET)
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Me.DoubleBuffered = True
        bmp = New Bitmap(My.Resources.tree1_1)
        bmp.MakeTransparent(Color.White)
        Blocation = New Rectangle(10, 10, bmp.Width, bmp.Height)
        AddHandler Panel2.Paint, AddressOf Panel2_Paint
        AddHandler Panel2.MouseMove, AddressOf Panel2_MouseMove
        AddHandler Panel2.MouseDown, AddressOf Panel2_MouseDown
        AddHandler Panel2.MouseUp, AddressOf Panel2_MouseUp
    End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        bmp = New Bitmap(My.Resources.tree1_1)
        bmp.MakeTransparent(Color.White)
        Blocation = New Rectangle(10, 10, bmp.Width, bmp.Height)
        Panel2.Invalidate()
 
    End Sub

    Private Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
        bmp = New Bitmap(My.Resources.tree1_2)
        bmp.MakeTransparent(Color.White)
        Blocation = New Rectangle(30, 30, bmp.Width, bmp.Height)
        Panel2.Invalidate()

    End Sub


ส่วนโค้ดนอกนั้นเหมือนเดิม






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-03-30 21:19:36 By : Programmer Of Persia
 


 

No. 2

Guest


ขอบคุณคร๊า
แต่อยากให้เมื่อ คลิ๊ก แร้วรูปเดิม ยังคงมีอยู่ เมื่อคลิ๊กรูปใหม่ แล้วรูปสามารถซ้อนทับกันได้ เคลื่อนที่ได้ทั้งสอง
bmp
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-03-31 15:47:12 By : Kimlung
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : VB.NET ติด Error เกี่ยวกับ Event Paint ช่วยตอบหน่อยคร่า
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 03
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่