Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi everyone,

 

I have the following code which is serving as an overlay to a seperate form and was wondering if there was any way that I could make the ellipses transparent like the rest of the background (i.e. empty circles). I can't find out how to do this anywhere and will greatly appreciate any help you can give.

 

Heres the code:

 

Public Class Form1

Inherits System.Windows.Forms.Form

 

#Region " Windows Form Designer generated code "

 

Public Sub New()

MyBase.New()

 

'This call is required by the Windows Form Designer.

InitializeComponent()

 

'Add any initialization after the InitializeComponent() call

 

End Sub

 

'Form overrides dispose to clean up the component list.

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing Then

If Not (components Is Nothing) Then

components.Dispose()

End If

End If

MyBase.Dispose(disposing)

End Sub

 

'Required by the Windows Form Designer

Private components As System.ComponentModel.IContainer

 

'NOTE: The following procedure is required by the Windows Form Designer

'It can be modified using the Windows Form Designer.

'Do not modify it using the code editor.

Friend WithEvents Label1 As System.Windows.Forms.Label

Friend WithEvents Label2 As System.Windows.Forms.Label

Friend WithEvents ToolTip1 As System.Windows.Forms.ToolTip

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

Me.components = New System.ComponentModel.Container

Me.Label1 = New System.Windows.Forms.Label

Me.Label2 = New System.Windows.Forms.Label

Me.ToolTip1 = New System.Windows.Forms.ToolTip(Me.components)

Me.SuspendLayout()

'

'Label1

'

Me.Label1.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _

Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)

Me.Label1.BackColor = System.Drawing.Color.Yellow

Me.Label1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle

Me.Label1.Location = New System.Drawing.Point(0, 0)

Me.Label1.Name = "Label1"

Me.Label1.Size = New System.Drawing.Size(392, 24)

Me.Label1.TabIndex = 0

Me.Label1.Text = "Moveable Grid Overlay"

Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter

Me.ToolTip1.SetToolTip(Me.Label1, "Left Click and Drag to Move Overlay")

'

'Label2

'

Me.Label2.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)

Me.Label2.BackColor = System.Drawing.Color.Red

Me.Label2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle

Me.Label2.Location = New System.Drawing.Point(392, 0)

Me.Label2.Name = "Label2"

Me.Label2.Size = New System.Drawing.Size(24, 24)

Me.Label2.TabIndex = 1

Me.Label2.Text = "X"

Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter

Me.ToolTip1.SetToolTip(Me.Label2, "Click to Close Application")

'

'Form1

'

Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)

Me.BackColor = System.Drawing.Color.White

Me.ClientSize = New System.Drawing.Size(416, 424)

Me.Controls.Add(Me.Label2)

Me.Controls.Add(Me.Label1)

Me.Cursor = System.Windows.Forms.Cursors.Hand

Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None

Me.Name = "Form1"

Me.Text = "Form1"

Me.ToolTip1.SetToolTip(Me, "Click on Point to Toggle its Selection")

Me.TopMost = True

Me.ResumeLayout(False)

 

End Sub

 

#End Region

 

Public Declare Auto Function ReleaseCapture Lib "user32.dll" () As Integer

Public Declare Ansi Function MoveForm Lib "user32.dll" Alias "SendMessageA" _

(ByVal hWnd As IntPtr, Optional ByVal Message As Integer = WM_NCLBUTTONDOWN, _

Optional ByVal HitTest As Integer = HTCAPTION, Optional ByVal wParam As Integer = 0) As Integer

 

Public Const WM_NCLBUTTONDOWN As Integer = &HA1

Public Const HTCAPTION As Integer = &H2

 

Private Const xInterval As Integer = 30

Private Const yInterval As Integer = 30

Private Const radius As Integer = 4

 

Private selections As New ArrayList

Private rectangles As New ArrayList

 

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim x As Integer

Dim y As Integer

 

Dim rect As Rectangle

Dim gp As New System.Drawing.Drawing2D.GraphicsPath

 

gp.AddRectangle(New Rectangle(Label1.Location, Label1.Size))

gp.AddRectangle(New Rectangle(Label2.Location, Label2.Size))

For x = xInterval To Me.Width Step xInterval

For y = (Label1.Top + Label1.Height + yInterval) To Me.Height Step yInterval

rect = New Rectangle(x - radius, y - radius, radius * 2, radius * 2)

gp.AddEllipse(rect)

rectangles.Add(rect)

Next

Next

 

Me.Region = New Region(gp)

End Sub

 

Private Sub Label1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Label1.MouseEnter

Label1.ForeColor = Color.Red

End Sub

 

Private Sub Label1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Label1.MouseLeave

Label1.ForeColor = Color.Black

End Sub

 

Private Sub Label1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseDown

If e.Button = MouseButtons.Left Then

ReleaseCapture()

MoveForm(Me.Handle)

End If

End Sub

 

Private Sub Label2_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Label2.MouseEnter

Label2.ForeColor = Color.Yellow

End Sub

 

Private Sub Label2_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Label2.MouseLeave

Label2.ForeColor = Color.Black

End Sub

 

Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label2.Click

Me.Close()

End Sub

 

Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown

Dim rect As Rectangle

Dim pt As New Point(e.X, e.Y)

For Each rect In rectangles

If rect.Contains(pt) Then

If selections.Contains(rect) Then

selections.Remove(rect)

Else

selections.Add(rect)

End If

Me.Refresh()

Exit Sub

End If

Next

End Sub

 

Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint

Dim rect As Rectangle

For Each rect In selections

e.Graphics.FillEllipse(Brushes.Red, rect)

Next

End Sub

 

End Class

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...