'__________________________________________________________ ' C R E A T I N G N O N - R E C T A N G U L A R F O R M S ' Ron Kessler ' Created 10/5/08 '__________________________________________________________ 'This project shows you how to: ' Create an oval form ' Start the form in center screen ' Change the color and opacity of the form with the TrackBar control. ' Let you move the form around by dragging it! Public Class frmOval Private mouseOffset As Point Private isMouseDown As Boolean = False Private Sub frmOval_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load '---no border/control box/buttons Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None '---start with normal opacity TrackBar1.Minimum = 2 'don't let it become invisible! TrackBar1.Maximum = 10 TrackBar1.Value = TrackBar1.Maximum 'Oval form centered on screen Me.Left = Screen.PrimaryScreen.Bounds.Width / 2 - Me.Width / 2 Me.Top = Screen.PrimaryScreen.Bounds.Height / 2 - Me.Height / 2 Dim myPath As New System.Drawing.Drawing2D.GraphicsPath() myPath.AddEllipse(0, 0, Me.Width, Me.Height) Dim myRegion As New Region(myPath) Me.Region = myRegion End Sub Private Sub rdoBlue_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rdoBlue.CheckedChanged Me.BackColor = Color.Blue End Sub Private Sub rdoRed_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rdoRed.CheckedChanged Me.BackColor = Color.Red End Sub Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click Me.Close() End Sub Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll Me.Opacity = TrackBar1.Value / TrackBar1.Maximum End Sub Private Sub frmOval_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown Dim xOffset As Integer Dim yOffset As Integer If e.Button = MouseButtons.Left Then xOffset = -e.X - SystemInformation.FrameBorderSize.Width yOffset = -e.Y - SystemInformation.CaptionHeight - _ SystemInformation.FrameBorderSize.Height mouseOffset = New Point(xOffset, yOffset) isMouseDown = True End If End Sub Private Sub frmOval_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove If isMouseDown Then Dim mousePos As Point = Control.MousePosition mousePos.Offset(mouseOffset.X, mouseOffset.Y) Location = mousePos End If End Sub Private Sub frmOval_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp ' Changes the isMouseDown field so that the form does ' not move unless the user is pressing the left mouse button. If e.Button = MouseButtons.Left Then isMouseDown = False End If End Sub End Class