Handy Hints



Hint 1 - Drawing on the Main Form

My first hint is how to draw on the actual form with pens and brushes. Since I can;t go over how to use every single function, ill say how to start drawing, and how to draw a circle.

To start the graphics engine, you have to declare a global variable of type Graphics. During the paint event of the form, we create the graphics on the form, and assign it to the variable.
We also draw a circle, or ellipse. There are default pens that you can use, and I used the black one.
Public Class frmHhOne
 
    Dim g As Graphics
    Private Sub frmHhOne_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        g = Me.CreateGraphics()
        g.DrawEllipse(Pens.Black, 0, 0, Me.Width - 50, Me.Height - 50)
    End Sub
End Class
This would draw a very boring circle, also when the form is resized, it won't erase the last circle and redraw it. It will just redraw. This can make for some pretty interesting patterns, but not what I want.
First off, Ill fix the boring circle. Create our own pen. Where we have declared the graphics, declare another variable of type Pen. Then in the Paint Event, give it a value of a new pen. The parameters of this are what colour to make the pen, and what size to make it.
Public Class frmHhOne
 
    Dim g As Graphics
    Dim pen As Pen
    Private Sub frmHhOne_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        g = Me.CreateGraphics()
        pen = New Pen(Color.Red, 5)
        g.DrawEllipse(pen, 0, 0, Me.Width - 50, Me.Height - 50)
    End Sub
End Class
Now for the resizing. On the resize event, we want to invalidate the form. It will remove all the old circles, and then call the paint event again.
Public Class frmHhOne
 
    Dim g As Graphics
    Dim pen As Pen
    Private Sub frmHhOne_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        g = Me.CreateGraphics()
        pen = New Pen(Color.Red, 5)
        g.DrawEllipse(pen, 0, 0, Me.Width - 50, Me.Height - 50)
    End Sub
 
    Private Sub frmHhOne_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
        Invalidate()
    End Sub
End Class

Hint 2 - Making a Media Player

This seems like a hard task? It isn't. In the Components section of the Toolbox, right click the name and select "Choose Items..." Go to the "COM Components" section and put a tick in "Windows Media Player"

The WMP will appear in the toolbox now. Drag it over to the form. On the properties, name it appropriately and dock it to center. Now drag over an OpenFileDialog. Also drag over a menu strip. Create a file menu with "Open" and "Exit." On the event of clicking Open, display the OpenFileDialog.

On the OpenFileDialog file ok event, change the url of the WMP to the file selected in the OpenFileDialog.

In the menu exit event, close the window.
Public Class frmHhTwo
 
    Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click
        OpenFileDialog1.ShowDialog()
    End Sub
 
    Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
        wmpOne.URL = OpenFileDialog1.FileName()
    End Sub
 
    Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
        Me.Close()
    End Sub
End Class