Вы находитесь на странице: 1из 5

3 ways to use Popup Menus in Lazarus | LazPlanet

http://lazplanet.blogspot.com/2013/08/3-ways-to-use-popup-menus-in-...

Posts >66

$omments >66

!acebook

9ome

6tart 9ereD

!4E

>esources

3ews

+utorials

4rticles

Categories: 3 ways to use Popup Menus in Lazarus


Pop Up menus pop when you right click on the application somewhere to make available the quick jobs in a menu. We explore 3 ways of using popup menus in La arus. Popup menus are common in many popular applications. !or example" in #L$ %e&ia Player 'or any other typical me&ia player( if you right click on the vi&eo area then a popup menu appears. )t lets you open me&ia files" play or pause" skip to the next song an& many more. La arus has a very easy implementation of this popup*style menu. La arus has a component name& +Popup%enu for this purpose. ,nce we create menus we can show it in 3 &ifferent ways" which ) will &emonstrate.
9ow to )nstall La arus :.;.< on Ubuntu :3.;= '>aring( Ubuntu :3.;= has been release& recently but its repo has an out&ate& version of La arus ';.?.3;.=(. La arus is at version :.;.< stable wi... 9ow to %ake La arus run in a 6ingle Win&ow +his tutorial shows you how to make la arus run with just one win&ow. )t is a goo& &ocking solution which will be integrate& in La arus ... 9ow to re&uce .exe file si e of your program @y &efault" La arus makes /A/s inclu&ing &ebug information which makes them extremely big. 1ou can strip out this &ebug information easil... )mage $opy PasteB 6toring an )mage in $lipboar& C >etrieving it )n paint programs" we see a function to copy an image to clipboar& an& paste it from there. Paste an image from anywhere" Photoshop" !iref... 9ow to 4&&" 7elete" $lear )tems of a List@ox Learn how to co&e a program to list
4lgorithms $onsole Programs $o&e 6nippets $ustom $ontrols 7atabases %ath 7ates !iles 7irectories !orm $ontrols List )teration 8ames 9+%L Web %isc 4u&io #i&eo 6creen 8raphics 37 8raphics 6ystem 4P) 6ecurity 9ar&ware +ext ,peration 4rtificial )ntelligence

Popular this Month

Creating the popup menu


$reating the popup menu is easy. -ust &rop a +Popup%enu component in the form" then right click it an& choose .%enu /&itor..... +hen select the item you want to mo&ify then mo&ify it with the help of the ,bject )nspector *0 Properties. 1ou can then change the menu item caption" name" checke& etc. 1ou can also a&& items by right clicking any of the existing menu items in the menu e&itor win&ow. 1ou will have to create as many +Popup%enu components as many popup menus you want. Let2s just see it practically... $reate a new project 'Project*0 3ew Project*0 4pplication*0 ,5(.

Creating a new popup menu and editing its items' properties

3ow &rop a +Popup%enu component in the form. 3ow right click it an& select .%enu /&itor.....

1 de 5

24/10/2013 11:06 p.m.

3 ways to use Popup Menus in Lazarus | LazPlanet

http://lazplanet.blogspot.com/2013/08/3-ways-to-use-popup-menus-in-...

&ifferent things. %ake your own lists with your own programD Utili e this article to list many things ...

"ollowers
Bscanos en Facebook

1ou will see : menu item alrea&y create& for you. 1ou can change its property" for example" $aption property to something like .%y popup menu item :.. !or this you can click on the item to select it" then change the property from the ,bject )nspector.

LazPlanet
Me gusta A 103 personas les gusta LazPlanet.

Adding new item to the menu

)f you want more item's( to be a&&e& then the &efault single item" then obviously you nee& to a&& more menu items. 1ou can a&& new menu items by right clicking an& selecting .)nsert 3ew )tem 'after(. or .)nsert 3ew )tem 'before(..

Plug-in social de Facebook

La#els

+utorials '3F( $o&e 6nippets 'FF( 6ample $o&e 'FF( 4rticles


':?( ':3( '::( ':;( /xplanation ':3( 6creen 8raphics !orm $ontrols ':F( %ath 7ates +ext ,peration '::( 6ystem 4P)
List )teration '<( $onsole 'G( !iles

7irectories 'G( 4lgorithms 'H( 3ews 'H( canvas 'H(

4fter inserting menu items" close the %enu /&itor win&ow to get back to your form.

Using Popup Menu in 3 ways

Way 1: Using the PopupMenu property (without ode! 1ou can skip all the mumbo jumbo an& show the popup menu without writing any co&eD )f you set the Popup%enu property of a component to the +Popup%enu you just prepare&" then the menu will appear when you right click on that component. 7rop a +@utton on the form. 6et its Popup%enu property to the +Popup%enu from the &rop&own menu.

$log Ar hi%e
F;:3 'G;( ,ctober ':( 4ugust ':( 3 ways to use Popup %enus in La arus -uly '=( -une '<( %ay 'F=(

2 de 5

24/10/2013 11:06 p.m.

3 ways to use Popup Menus in Lazarus | LazPlanet

http://lazplanet.blogspot.com/2013/08/3-ways-to-use-popup-menus-in-...

4pril '::( %arch '::(

3ow run the project '!? or >un*0 >un( an& right click on the button to see the popup menu.

Way &: Using ode to show the popup menu Using the Popup%enu property to show the popup menu is just simple an& proper for almost all uses. 6ometimes you may want to &o some custom co&ing before showing the popup menu. +hen using this metho& is a goo& i&ea. 7rop another +@utton component in the form 'suppose it is name& @uttonF(. ,n its ,n%ouse7own event ',bject inspector*0 /vents*0 ,n%ouse7own( enter the following co&eB 1 2 3 4 5 6
: procedure TForm1.Button2MouseDown(Sender: TObject; Button: TMouseButton; S !"t: TS !"tSt#te; $% &: Integer'; begin if Button ( mb)!* t then +o,u,Menu1.+o,-,; end;

3ow run the project '!? or >un*0 >un( an& right click the button an& you will see the popup menu. +he +Popup%enu.PopUp shows the menu. )t automatically shows the menu at the position of the mouse pointer. Way 3: 'howing menu on Le(t Cli ) ((i*ed position! +his is also another use. )t is seen in many U) &esigns. !or example" there are many antivirus programs which have an .,ptions. button. )f you click it" you can see many customi ing menu options. We can create such a menu with the co&e belowB !irst" &rop a +@utton 'suppose it is name& @utton3( an& then &ouble click it an& enterB

1 2 3 4 5 6 . / 0 11 11 12

procedure TForm1.Button323!c4(Sender: TObject'; var ,t% ,t2: T+o!nt; begin ,t.5:(Button3.6e"t; ,t.7:(Button3.To,8Button3.9e!* t; ,t2:(23!entToScreen(,t'; +o,u,Menu1.+o,-,(,t2.5% ,t2.7'; end;

3ow run the project an& click on the button. 1ou will see the menu to appear at the

3 de 5

24/10/2013 11:06 p.m.

3 ways to use Popup Menus in Lazarus | LazPlanet

http://lazplanet.blogspot.com/2013/08/3-ways-to-use-popup-menus-in-...

bottom of the button. +he PopUp proce&ure shoul&2ve shown the menu at the mouse pointer" not the bottom of the button. 9ow &i& we &o itJ With the PopUp'x" y( syntax. 1ou can show the menu at any place on the screen you wish at any time with this syntax. +here you have it. 3 ways to use popup menus in La arus form &esigner.

+ownload 'ample Code ,-P


1ou can &ownloa& the above example tutorial project source co&e from hereB httpBKK&b.ttK3PFlG1/5 6i eB G3H 5@ +he package contains compile& executable /A/.

Yo u m i g h t a l s o l i k e

9ow to show +ool+ip" @alloon +ip an...

9ow to list the files in a fol&er I...

9ow to get $omputer >unning +ime

9ow to create an airbrush tool for ...

9ow to get 7rag an& 7rop files on y...

Poste& by 4&nan 6hameem at :B;< P%

LabelsB 4rticles" !orm $ontrols" )nterface" menu" popup" right click" 6ystem 4P)" +utorials

Tweet

StumbleUpon

Like

Send

& omments: Walter said...


9i" ) fin& your site while searching for the $astle 8ame /ngine for La arus.) really like the way that you &ivi&e your posts in sections" very simple an& easy to rea&. 8reat WorkDD 8reetings from @ra il B7
4ugust :H" F;:3 at :FB=H P%

Adnan 'hameem said...


9i Walter.

4 de 5

24/10/2013 11:06 p.m.

3 ways to use Popup Menus in Lazarus | LazPlanet

http://lazplanet.blogspot.com/2013/08/3-ways-to-use-popup-menus-in-...

+hanks for visiting La Planet. 5eep visiting La Planet for more articles. Plus" you are welcome to like our facebook page. )f you are having any questions for a project of yours" you can ask it in the facebook page. 3ice to see a @ra ilian fanD 9appy co&ing.
4ugust :G" F;:3 at HBH; P%

Post a $omment

6ubscribe toB Post $omments '4tom(

5 de 5

24/10/2013 11:06 p.m.