OS X style menu (app specific)

Heres your chance to share your own tutorials with the community. Just post them on here. If your lucky they may even be posted on the main site.
4 posts Page 1 of 1
Contributors
User avatar
samideano
New Member
New Member
Posts: 11
Joined: Wed Dec 22, 2010 1:04 pm

OS X style menu (app specific)
samideano
I know everyone and their brother tries to emulate OS X in one way or the other. This is a somewhat similar idea to Apples global menu, although it is built in to the app.

I use VB 2010 for this.

What you will need:

Two forms


Form1:
MenuStrip
1 Button

Form2:
Media Player Control
1 button



Step One:

On the Form1 design page, add a Menu Strip. Position it at the top of Form1.
Add the following Menu Item: Player
Under the Player Menu, add Hide, Show and Quit menus.

Set the ShowInTaskBar property to false.

Step Two:

Resize Form1 to fit the menustrip. I sized my form to 682, 58.

Change Form1's name property to 'menuForm'
Set menuForm's startPosition to manual, and set it's anchor to Right, Top, Left.
This will lock the menuForm to the top of the screen.
Double click on menuForm to add the following code to it's Load function:
Code: Select all
mediaForm.Show()
Set the menuForm control box property to false. Set the text property so that the text property is blank.
This will make menuForms's Title Bar go away, so to speak.

Step 5:

In the menuForm menustrip, under the Player menu you created in step one, double click Quit to open it's section of the code editor.

Enter the code
Code: Select all
end
in the sub, so that the Quit code looks like this:
Code: Select all
Private Sub QuitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles QuitToolStripMenuItem.Click
        End
    End Sub
Now whenever you debug you have an option for quitting this little app from within the app itself.

Step 6:

Go to the Form2 design tab. Add a button and a Windows Media Player Control.

Organize Form2 in any way you see fit, and change Button1's Text property to "Play" and it's name property to "playButton". I always recommend giving all of your controls a logical name that represents the function which they serve for your app. This will make your code easier to understand should you come back to it after months of doing other projects, and help others understand your code if you need help.

Not to mention that it is just proper programming manners :)

Change Form2's name property to mediaForm, and it's text property to 'Player'.

Double Click the Play button (playButton) in mediaForm (formerly Form2) and enter the following code:
Code: Select all
 AxWindowsMediaPlayer1.URL = "http://www.hot108.com/hot108jamz.asx"
*** I did not come up with that little snippet myself, it is all over the net, I just used it here to make things easier***


OK, now if you haven't been saving your project like crazy, do so now. I always save after making any change that functions as intended, so I do not lose work. At this point, if you debug your app, your menuForm should load at the top of the screen, and your mediaForm should show automatically. You should be able to press the Play button you created and the Media Player control will play the internet stream. You should be able to click Player in the menuForm and click Quit, which should quit the app. Closing the mediaForm window will only close that window, not the app.

Now, back for menuForm's design tab, under the Player menu, double click Hide and enter the following code:
Code: Select all
mediaForm.Hide()
Now for the Show entry in the Player menu, double click and add the following code:
Code: Select all
mediaForm.Show()
Now save and debug your project. The Player > Hide menu should hide the mediaForm window. Likewise, Player > Show should bring it back.




There you go, a VERY basic app which is controlled by a separate menubar. Add images to the menuForm background, or make whatever tweaks you like.

This is my first tutorial and I get the feeling I may not have explained things well enough, and it is VERY basic, but I wanted to start out small I guess. Any tips and pointers, questions and the like are welcome.
Last edited by samideano on Fri Dec 24, 2010 3:26 pm, edited 1 time in total.
User avatar
Usman55
VIP - Site Partner
VIP - Site Partner
Posts: 2821
Joined: Thu Dec 24, 2009 7:52 pm

Re: OS X style menu (app specific)
Usman55
Sorry to say but in the
Code: Select all
 thing you put the slash opposite.
Image
User avatar
samideano
New Member
New Member
Posts: 11
Joined: Wed Dec 22, 2010 1:04 pm

Usman55 wrote:
Sorry to say but in the
Code: Select all
 thing you put the slash opposite.[/quote]


LOL Thanks I didn't catch that! Guess I am in Windows mode lmao!
User avatar
HarrySeddon
Just Registered
Just Registered
Posts: 6
Joined: Tue Jan 11, 2011 4:18 pm

that sounds good
4 posts Page 1 of 1
Return to “Tutorials”