Форум по Delphi программированию

Delphi Sources



Вернуться   Форум по Delphi программированию > Все о Delphi > Компоненты и классы
Ник
Пароль
Регистрация <<         Правила форума         >> FAQ Пользователи Календарь Поиск Сообщения за сегодня Все разделы прочитаны

Ответ
 
Опции темы Поиск в этой теме Опции просмотра
  #1  
Старый 11.07.2009, 22:50
Аватар для Alenov
Alenov Alenov вне форума
Прохожий
 
Регистрация: 11.07.2009
Сообщения: 4
Репутация: 10
По умолчанию Подчеркивание в меню

Добрый день. Возникла проблема с использованием компонента меню в стиле ХР. В заголовках пунктов меню подчеркивается первый символ (Заголовок), а если заголовок начинается с того же символа, что и предыдущий, то второй. Меня это не устраивает, хотелось бы, чтобы подчеркивался или все время первый символ, или вообще подчеркивания не было. Вот процедура ответственная за прорисовку пунктов меню:
Код:
procedure TMXPMenu.DrawMenuItem;
var
  Text: string;
  Bitmap: TBitmap;
  IconRect,
  TextRect,
  CheckRect: TRect;
  i,x1,x2,TextFormat: integer;
  MenuItem: TMenuItem;
  Menu: TMenu;
begin
  MenuItem:=TMenuItem(Sender);
  Menu:=MenuItem.Parent.GetParentMenu;
  if Menu.IsRightToLeft then begin
    x1:=ARect.Right-20;
    x2:=ARect.Right;
  end else begin
    x1:=ARect.Left;
    x2:=ARect.Left+20;
  end;
  IconRect:=Rect(x1,ARect.Top,x2,ARect.Bottom);
  TextRect:=ARect;
  Text:=#32+MenuItem.Caption;
  Bitmap:=TBitmap.Create;
  Bitmap.Transparent:=True;
  if Assigned(MenuItem.Parent.GetParentMenu.Images) or Assigned(MenuItem.Parent.SubMenuImages) then begin
    if (MenuItem.ImageIndex<>-1) then begin
      if Assigned(MenuItem.Parent.SubMenuImages) then
        MenuItem.Parent.SubMenuImages.GetBitmap(MenuItem.ImageIndex,Bitmap)
      else
        MenuItem.Parent.GetParentMenu.Images.GetBitmap(MenuItem.ImageIndex,Bitmap)
    end;
  end;
  if Menu.IsRightToLeft then begin
    x1:=ARect.Left;
    x2:=ARect.Right-20;
  end else begin
    x1:=ARect.Left+20;
    x2:=ARect.Right;
  end;
  TextRect:=Rect(x1,ARect.Top,x2,ARect.Bottom);
  ACanvas.Brush.Color:=FBackColor;
  ACanvas.FillRect(TextRect);
  if (Menu is TMainMenu) then begin
    for i:=0 to MenuItem.GetParentMenu.Items.Count-1 do begin
      if (MenuItem.GetParentMenu.Items[i]=MenuItem) then begin
        ACanvas.Brush.Color:=FIconBackColor;
        ACanvas.FillRect(ARect);
        if (MenuItem.ImageIndex=-1) and (MenuItem.Bitmap.Width=0) then begin
          TextRect:=ARect;
          Break;
        end;
      end;
    end;
  end;
  ACanvas.Brush.Color:=FIconBackColor;
  ACanvas.FillRect(IconRect);
  if MenuItem.Enabled then
    ACanvas.Font.Color:=FFontColor
  else
    ACanvas.Font.Color:=FDisabledFontColor;
  if (odSelected in State) or (odHotLight in State) then begin
    ACanvas.Brush.Style:=bsSolid;
    ACanvas.Brush.Color:=FSelectedBackColor;
    ACanvas.FillRect(TextRect);
    ACanvas.Pen.Color:=FSelectedBorderColor;  //Цвет рамки области выделения
    ACanvas.Brush.Style:=bsClear;
    ACanvas.RoundRect(TextRect.Left,TextRect.Top,TextRect.Right,TextRect.Bottom,6,6); //Углы области выделения
    if MenuItem.Enabled then
      ACanvas.Font.Color:=FSelectedFontColor;
  end;
  x1:=IconRect.Left+2;
  if MenuItem.Checked then begin    //Галочка
    ACanvas.Pen.Color:=FCheckedColor;
    ACanvas.Brush.Style:=bsClear;
    if (Bitmap.Width=0) then begin
      ACanvas.RoundRect(IconRect.Left+5,IconRect.Top+5,IconRect.Right-5,IconRect.Bottom-5,3,3);
      CopyRect(CheckRect,IconRect);
      InflateRect(CheckRect,-7,-7);
      ACanvas.Brush.Color:=FCheckSignColor;
      ACanvas.FillRect(CheckRect);
    end else begin
      ACanvas.Brush.Color:=FCheckSignColor;
      ACanvas.RoundRect(IconRect.Left,IconRect.Top,IconRect.Right,IconRect.Bottom,3,3);
    end;
  end;
  if Assigned(Bitmap) then
    ACanvas.Draw(x1,IconRect.Top+1,Bitmap);
  if not MenuItem.IsLine then begin
    SetBkMode(ACanvas.Handle,TRANSPARENT);
    ACanvas.Font.Name:='Tahoma';
    ACanvas.Font.Style:=[];
    if Menu.IsRightToLeft then
      ACanvas.Font.Charset:=DEFAULT_CHARSET;
    if Menu.IsRightToLeft then
      TextFormat:=DT_RIGHT+DT_RTLREADING
    else
      TextFormat:=0;
    if MenuItem.Default then
      ACanvas.Font.Style:=ACanvas.Font.Style+[fsBold];
    inc(TextRect.Left,2);
    inc(TextRect.Top,FInterval); //Здесь опускается текст
    DrawTextEx(ACanvas.Handle,PChar(Text),Length(Text),TextRect,TextFormat,nil);
    Text:=ShortCutToText(MenuItem.ShortCut)+' ';
    if Menu.IsRightToLeft then
      TextFormat:=DT_LEFT
    else
      TextFormat:=DT_RIGHT;
    DrawTextEx(ACanvas.Handle,PChar(Text),Length(Text),TextRect,TextFormat,nil);
  end else begin
    ACanvas.Pen.Color:=FSeparatorColor;  //Сепаратор
    ACanvas.MoveTo(ARect.Left+10,TextRect.Top+Round((TextRect.Bottom-TextRect.Top)/2));
    ACanvas.LineTo(ARect.Right-2,TextRect.Top+Round((TextRect.Bottom-TextRect.Top)/2));
  end;
  Bitmap.Free;
end;
Ответить с цитированием
  #2  
Старый 12.07.2009, 12:13
Аватар для Alenov
Alenov Alenov вне форума
Прохожий
 
Регистрация: 11.07.2009
Сообщения: 4
Репутация: 10
По умолчанию

Проблема решается:
Код:
TMainMenu.AutoHotKeys := maManual
Ответить с цитированием
Ответ


Delphi Sources

Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск
Опции просмотра

Ваши права в разделе
Вы не можете создавать темы
Вы не можете отвечать на сообщения
Вы не можете прикреплять файлы
Вы не можете редактировать сообщения

BB-коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход


Часовой пояс GMT +3, время: 20:50.


 

Сайт

Форум

FAQ

RSS лента

Прочее

 

Copyright © Форум "Delphi Sources" by BrokenByte Software, 2004-2023

ВКонтакте   Facebook   Twitter