Карта сайта Kansoftware
НОВОСТИУСЛУГИРЕШЕНИЯКОНТАКТЫ
Разработка программного обеспечения
KANSoftWare

Как сделать пункты меню с картинками

Delphi , Компоненты и Классы , Меню

Как сделать пункты меню с картинками

Следующий код показывает, как добавить картинку в виде объекта TImage в объект TMenuItem:


var
   hHandle: THandle;
   x: integer;
   // visual controls:
   hMenu: TMenuItem;
   Image1: TImage;
...
x:= 10; // десятый пункт меню
hHandle := GetMenuItemID(hMenu.handle, x);
ModifyMenu(hMenu.handle, hHandle, MF_BYCOMMAND or MF_BITMAP,
hHandle, PChar(Image1.picture.bitmap.handle));

You're trying to add an image to a menu item! That's a great question!

The code you provided is almost correct, but there are a few things to keep in mind.

Firstly, TMenuItem has a property called ImageIndex, which allows you to associate an image with the menu item. This property should be set to the index of the image list that contains the desired image.

Secondly, ModifyMenu function is used to modify an existing menu or menu item. In your case, you're trying to add a new menu item, so you'll need to use InsertMenu instead.

Here's an updated code snippet that should work:

var
  hHandle: THandle;
  x: integer; // tenth menu item
  Image1: TImage;

// Create an image list and add the desired image to it
ImageList1 := TImageList.Create(nil);
ImageList1.ImageCount := 1;
ImageList1.AddBitmap(Image1.Picture.Bitmap);

// Create the menu item
hHandle := InsertMenu(hMenu.Handle, x, MF_BYCOMMAND or MF_IMAGE, 'Menu Item', ImageList1.GetBitmap(x));

// If you want to add a tooltip to the menu item
SetMenuItemInfo(hHandle, True, 0, PChar('Tooltip text'), nil);

In this code:

  • We create an TImageList object and add the desired image to it using its AddBitmap method.
  • We set the ImageIndex property of the menu item to the index of the image list (in this case, 0).
  • We use InsertMenu instead of ModifyMenu to insert a new menu item at the specified position.
  • If you want to add a tooltip to the menu item, you can set it using the SetMenuItemInfo function.

Remember to handle the OnClick event of the menu item to perform any actions when the user selects it.

Статья описывает способ добавления картинки в пункт меню на языке программирования Delphi, используя компонент TImage и функции ModifyMenu.


Комментарии и вопросы


Ваше мнение или вопрос к статье в виде простого текста (Tag <a href=... Disabled). Все комментарии модерируются, модератор оставляет за собой право удалить непонравившейся ему комментарий.

заголовок

e-mail

Ваше имя

Сообщение

Введите код




Материалы статей собраны из открытых источников, владелец сайта не претендует на авторство. Там где авторство установить не удалось, материал подаётся без имени автора. В случае если Вы считаете, что Ваши права нарушены, пожалуйста, свяжитесь с владельцем сайта.



:: Главная :: Меню ::


реклама



©KANSoftWare (разработка программного обеспечения, создание программ, создание интерактивных сайтов), 2007
Top.Mail.Ru Rambler's Top100

Время компиляции файла: 2024-05-19 17:53:24
2024-05-19 17:54:39/0.0046710968017578/2