none
如何在100%透明表單上使用滑鼠畫線 RRS feed

  • 問題

  •  

    大家好

     

    1.使用作業系統:Win XP Pro。

    2.程式語言: VB 2005 Express中文版。

    3.問題:

       A.表單透明度越高,筆色越淡,如何可使筆色不變淡?

       B.在表單100%透明時(Me.Opacity = 0),滑鼠卻又無法畫線,如何解決?

       C.在表單100%透明時,如何控制滑鼠事件?

    4.程式碼如下:

    Public Class Form1
        Dim px As Integer
        Dim py As Integer

        Private Sub Form1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.DoubleClick
            Application.Exit()
        End Sub

        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Me.WindowState = FormWindowState.Maximized
            Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
            Me.TopMost = True
            Me.Opacity = 0.2
        End Sub

        Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
            If e.Button = Windows.Forms.MouseButtons.Left Then
                px = e.X
                py = e.Y
            End If
        End Sub

        Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
            Dim g As Graphics = Me.CreateGraphics
            Dim newPen As New Pen(Brushes.Red)

            newPen.Width = 4.0F
            Label1.Text = MousePosition.ToString
            If e.Button = Windows.Forms.MouseButtons.Left Then
                g.DrawLine(newPen, px, py, e.X, e.Y)
            End If
            px = e.X
            py = e.Y
        End Sub
    End Class

    2008年11月9日 上午 02:40

所有回覆