As we all know, using Delphi's Tpopupmenu widget can make pop-up menus. But how can we create a pop-up menu that resembles the various styles in Photoshop? (for example, Photoshop's Brush shape selection menu, see figure)
The production method is as follows:
1. Open Delphi and place a TButton widget in the Form1.
2. Create a new form and use the default name Form2.
3. Set the Form2 BorderStyle property to Bsnone, which will remove the form's title bar and border.
4. Add the Tpanel widget Panel1 to the Form2, set the Panel1 Bevelinner and Bevelouter properties to bvraised, and set the Align property to alclient. Use a Panel1 border as a border for the menu form.
5. Add Unit2 to the uses of the implementation section of UNIT1.
6. Double-click the button widget Button1 in Form 1 to add the following code:
procedure TForm1.Button1ClickSender TObject
var
ShowingPoint TPoint
begin
GetCursorPosShowingPoint // 得到光标的当前坐标
Form2.Left = ShowingPoint.X // 让Form2在当前光标处显示
Form2.Top = ShowingPoint.Y
Form2.Show
end
7. Add the following code under the Form2 ondeactivate event:
procedure TForm2.FormDeactivateSender TObject
begin
Close // 当窗体失去焦点后,关闭自己。
end
8. Press F9 to run the program, double-click Button1, Form2 will be like pop-up menu display, click Form1 any place, Form2 will automatically close. Next, friends will be able to design their own pop-up menu on the Form2.
The above program is tested in Windows + Delphi 5.