Delphi XE5中的样式问题,链接到Mainmenu

时间:2016-04-18 10:22:56

标签: delphi menu delphi-xe5 vcl-styles

前段时间我已经从Delphi 5转移到Delphi XE5,并且也开始使用styles选项。 将我的一个旧程序从 5 转换为 XE5 时,当我使用“windows”样式时,一切正常,但是当我改为另一种样式时,主菜单消失,表格中的所有对象都向上移动。工具栏在主菜单上绘制。请注意,在这种情况下不会绘制工具栏上的tBitBtn和tCombobox,但即使从工具栏中删除这些元素也无法解决问题。

主菜单问题

enter image description here

经过一番尝试后,我发现这个问题与某些菜单项有关,这些菜单项的'enable'设置为false。 启用所有菜单项会使屏幕再次正确显示。

我的主要问题是我不明白为什么会发生这种情况,因为当我尝试使用新项目重现此问题时,一切似乎都能正常工作,即使某些菜单项已禁用。欢迎任何想法。

请附上将显示问题的DPR,PAS和DFM:
DPR:

program GeoUTM;

uses
  Forms,
  GeoUTM_Main in 'GeoUTM_Main.pas' {GeoUTMForm},
  Vcl.Themes,
  Vcl.Styles;

{$R *.RES}

begin
  Application.Initialize;
  TStyleManager.TrySetStyle('Aqua Light Slate');

  Application.CreateForm(TGeoUTMForm, GeoUTMForm);
  Application.Run;
end.  

PAS:

unit GeoUTM_Main;

interface

uses
  System.SysUtils,

  VCL.Forms, Vcl.Menus, Vcl.Dialogs, Vcl.Controls, Vcl.ExtCtrls,
  Vcl.StdCtrls, Vcl.ComCtrls, Vcl.ToolWin, Vcl.Graphics, System.Classes;

type
  TGeoUTMForm = class(TForm)
    Bevel1: TBevel;
    Bevel2: TBevel;
    ComboBox_Route: TComboBox;
    Files1: TMenuItem;
    GroupBox1: TGroupBox;
    GroupBox2: TGroupBox;
    Label3: TLabel;
    Label4: TLabel;
    Lbl_data11: TLabel;
    Lbl_data12: TLabel;
    Lbl_data13: TLabel;
    Lbl_data14: TLabel;
    Lbl_data21: TLabel;
    Lbl_data22: TLabel;
    Lbl_data23: TLabel;
    Lbl_data24: TLabel;
    Lbl_GridTitle1: TLabel;
    Lbl_GridTitle2: TLabel;
    Lbl_Title_1: TLabel;
    Lbl_Title_2: TLabel;
    MainMenu1: TMainMenu;
    MI_Blockshift: TMenuItem;
    mi_Conversion: TMenuItem;
    mi_Crossing: TMenuItem;
    mi_DataConversion: TMenuItem;
    mi_DTM: TMenuItem;
    mi_Exit: TMenuItem;
    mi_GridInfo: TMenuItem;
    mi_KPlist: TMenuItem;
    mi_Route: TMenuItem;
    mi_Routeinfo: TMenuItem;
    mi_Routes: TMenuItem;
    mi_Views: TMenuItem;
    N11: TMenuItem;
    N8: TMenuItem;
    Panel1: TPanel;
    Panel2: TPanel;
    StatusBar: TStatusBar;
    TB_1: TToolButton;
    TB_2: TToolButton;
    TB_4: TToolButton;
    TB_5: TToolButton;
    Timer1: TTimer;
    ToolBar: TToolBar;
    ToolBtn_Conv: TToolButton;
    ToolBtn_Crds: TToolButton;
    ToolBtn_Export: TToolButton;
    ToolBtn_Grid: TToolButton;
    ToolBtn_Heights: TToolButton;
    ToolBtn_KPlist: TToolButton;
    ToolBtn_Left: TToolButton;
    ToolBtn_Load: TToolButton;
    ToolBtn_Right: TToolButton;
    ToolBtn_Route: TToolButton;
    ToolBtn_RouteInfo: TToolButton;
    ToolBtn_Save: TToolButton;
    ToolBtn_Xing: TToolButton;
    ToolButton_DecDigit: TToolButton;
    ToolButton_incDigit: TToolButton;
    ToolButton1: TToolButton;
    Worldmap1: TMenuItem;

    procedure FormActivate(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure FormCreate(Sender: TObject);


    procedure FormShow(Sender: TObject);



  private
    procedure UpdateForm;
    procedure PanelUpdate;

     { Private declarations }
  public
    { Public declarations }
  end;

var
  GeoUTMForm: TGeoUTMForm;


{------------------------------------------------}
{------------------------------------------------}
{------------------------------------------------}
{------------------------------------------------}

implementation

{$R *.DFM}

Const
  Progname   = 'GeoUTM' ;

  GridTitle11 = 'Coordinates list';
  GridTitle12 = 'Route : ';
  GridTitle13 = 'KP list : ';
  GridTitle14 = 'Crossing list : ';

  GridTitle21 = 'Conversion';
  GridTitle22 = 'Grid info';
  GridTitle23 = 'Route info';

 var
   ProgramName : string;

{-----------------------------------}
{             FormCreate            }
{-----------------------------------}
procedure TGeoUTMForm.FormCreate(Sender: TObject);
var
   sExe, txt:string;
   dummy : integer;
   Wtot : integer;

begin
  With Statusbar do
  begin

    Panels[1].text := '© HPH van Rossen';
    ProgramName := ExtractFileName(Application.ExeName);

    Panels[3].text := 'Version - Temp';
  end;

  Lbl_GridTitle1.caption := GridTitle11;
  Lbl_GridTitle2.caption := GridTitle21;
end;

{-----------------------------------}
{              FormShow             }
{-----------------------------------}
procedure TGeoUTMForm.FormShow(Sender: TObject);
begin
  // UpdateForm;
end;

{-----------------------------------}
{            FormActivate           }
{-----------------------------------}
procedure TGeoUTMForm.FormActivate(Sender: TObject);
begin
   UpdateForm;    // removing this one and move to OnShow solves the issue
end;

{-----------------------------------}
{             UpdateForm            }
{-----------------------------------}
procedure TGeoUTMForm.UpdateForm;

begin
  // Menu items in first tier
  mi_Routes.enabled      := false;         // This one is causing the problem
  mi_Blockshift.enabled  := true;


  // Menu items in 2nd and other tiers
  mi_KPlist.enabled := False;

  mi_Crossing.enabled   := False;
  mi_Route.enabled  := false;

  // Toolbar items
  Combobox_route.enabled := False;

  ToolBtn_Route.enabled   := False;
  ToolBtn_KPlist.enabled  := False ;
  ToolBtn_Xing.enabled    := False ;
  ToolBtn_Heights.enabled := False;

  ToolBtn_Export.enabled := False;

  ToolBtn_RouteInfo.enabled :=  false;
  ToolBtn_Grid.enabled      :=  true;

  PanelUpdate;
end;

{------------------------------------------------}
{                  PanelUpdate                   }
{------------------------------------------------}
procedure TGeoUTMForm.PanelUpdate;
begin
  With Statusbar do
  begin
    Panels[5].text := '' ;
    Panels[7].text := FormatDateTime('dd mmm yyyy',Now);
    Panels[9].text := FormatDateTime('h:nn:ss AM/PM',Now);
  end;
end;

{------------------------------------------------}
{                Timer1Timer                     }
{------------------------------------------------}
procedure TGeoUTMForm.Timer1Timer(Sender: TObject);
begin
  PanelUpdate;
end;

end.

最后是DFM:

object GeoUTMForm: TGeoUTMForm
  Left = 201
  Top = 59
  HelpContext = 40
  BorderIcons = [biSystemMenu, biMinimize]
  BorderStyle = bsSingle
  Caption = 'GeoUTM'
  ClientHeight = 676
  ClientWidth = 900
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Arial'
  Font.Style = []
  Menu = MainMenu1
  OldCreateOrder = False
  Position = poDesktopCenter
  Visible = True
  OnActivate = FormActivate
  OnCreate = FormCreate
  OnShow = FormShow
  PixelsPerInch = 96
  TextHeight = 14
  object Bevel1: TBevel
    Left = 10
    Top = 136
    Width = 225
    Height = 97
    Shape = bsFrame
    Style = bsRaised
  end
  object Bevel2: TBevel
    Left = 10
    Top = 32
    Width = 225
    Height = 89
    ParentShowHint = False
    Shape = bsFrame
    ShowHint = False
    Style = bsRaised
  end
  object Label3: TLabel
    Left = 304
    Top = 320
    Width = 368
    Height = 24
    Caption = 'The license on GeoUTM has expired '
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clBlack
    Font.Height = -21
    Font.Name = 'Arial'
    Font.Style = [fsBold]
    ParentFont = False
  end
  object Label4: TLabel
    Left = 264
    Top = 352
    Width = 445
    Height = 16
    Caption = 
      'Please use "e-mail feedback" option to request for an updated ve' +
      'rsion'
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clBlack
    Font.Height = -13
    Font.Name = 'Arial'
    Font.Style = [fsBold]
    ParentFont = False
  end
  object Panel2: TPanel
    Left = 576
    Top = 136
    Width = 289
    Height = 97
    BevelOuter = bvNone
    Color = 4194304
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWhite
    Font.Height = -11
    Font.Name = 'Arial'
    Font.Style = []
    ParentFont = False
    TabOrder = 5
    object Lbl_GridTitle1: TLabel
      Left = 0
      Top = 19
      Width = 289
      Height = 30
      Alignment = taCenter
      AutoSize = False
      Caption = 'Lbl_GridTitle1'
      Font.Charset = DEFAULT_CHARSET
      Font.Color = clWhite
      Font.Height = -13
      Font.Name = 'Arial'
      Font.Style = [fsBold]
      ParentFont = False
    end
    object Lbl_GridTitle2: TLabel
      Left = 0
      Top = 54
      Width = 289
      Height = 19
      Alignment = taCenter
      AutoSize = False
      Caption = 'Lbl_GridTitle2'
      Font.Charset = DEFAULT_CHARSET
      Font.Color = clWhite
      Font.Height = -13
      Font.Name = 'Arial'
      Font.Style = [fsBold]
      ParentFont = False
    end
  end
  object StatusBar: TStatusBar
    Left = 0
    Top = 657
    Width = 900
    Height = 19
    Panels = <
      item
        Alignment = taCenter
        Bevel = pbNone
        Width = 25
      end
      item
        Alignment = taCenter
        Width = 120
      end
      item
        Alignment = taCenter
        Bevel = pbNone
        Width = 30
      end
      item
        Alignment = taCenter
        Width = 100
      end
      item
        Alignment = taCenter
        Bevel = pbNone
        Width = 30
      end
      item
        Alignment = taCenter
        Width = 200
      end
      item
        Alignment = taCenter
        Bevel = pbNone
        Width = 30
      end
      item
        Alignment = taCenter
        Width = 100
      end
      item
        Alignment = taCenter
        Bevel = pbNone
        Width = 30
      end
      item
        Alignment = taCenter
        Width = 100
      end
      item
        Alignment = taCenter
        Bevel = pbNone
        Width = 15
      end>
  end
  object GroupBox1: TGroupBox
    Left = 243
    Top = 129
    Width = 312
    Height = 105
    Caption = ' 1st data set  '
    Color = clBtnFace
    Ctl3D = True
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clBlack
    Font.Height = -11
    Font.Name = 'Arial'
    Font.Style = []
    ParentBackground = False
    ParentColor = False
    ParentCtl3D = False
    ParentFont = False
    TabOrder = 0
    object Lbl_data12: TLabel
      Left = 39
      Top = 40
      Width = 221
      Height = 16
      Alignment = taCenter
      AutoSize = False
      Caption = 'Spheroid : Hayford / International'
    end
    object Lbl_data13: TLabel
      Left = 39
      Top = 64
      Width = 221
      Height = 16
      Alignment = taCenter
      AutoSize = False
      Caption = 'Central Meridian : 3'#176' East'
    end
    object Lbl_data11: TLabel
      Left = 39
      Top = 16
      Width = 221
      Height = 16
      Alignment = taCenter
      AutoSize = False
      Caption = 'Universal Transverse Mercator (UTM)'
      Font.Charset = ANSI_CHARSET
      Font.Color = clBlack
      Font.Height = -12
      Font.Name = 'Arial'
      Font.Style = [fsBold, fsUnderline]
      ParentFont = False
    end
    object Lbl_data14: TLabel
      Left = 39
      Top = 84
      Width = 221
      Height = 16
      Alignment = taCenter
      AutoSize = False
      Caption = 'Zone 31'
    end
  end
  object GroupBox2: TGroupBox
    Left = 561
    Top = 130
    Width = 312
    Height = 105
    Caption = ' 2nd data set  '
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clBlack
    Font.Height = -11
    Font.Name = 'Arial'
    Font.Style = []
    ParentBackground = False
    ParentFont = False
    TabOrder = 1
    Visible = False
    object Lbl_data22: TLabel
      Left = 47
      Top = 40
      Width = 221
      Height = 25
      Alignment = taCenter
      AutoSize = False
      Caption = 'Spheroid : Hayford / International'
      Font.Charset = DEFAULT_CHARSET
      Font.Color = clBlack
      Font.Height = -12
      Font.Name = 'Arial'
      Font.Style = []
      ParentFont = False
    end
    object Lbl_data23: TLabel
      Left = 47
      Top = 64
      Width = 221
      Height = 16
      Alignment = taCenter
      AutoSize = False
      Caption = 'Central Meridian : 3'#176' East'
      Font.Charset = ANSI_CHARSET
      Font.Color = clBlack
      Font.Height = -12
      Font.Name = 'Arial'
      Font.Style = []
      ParentFont = False
    end
    object Lbl_data21: TLabel
      Left = 47
      Top = 16
      Width = 221
      Height = 16
      Alignment = taCenter
      AutoSize = False
      Caption = 'Geographical coordinates'
      Font.Charset = ANSI_CHARSET
      Font.Color = clBlack
      Font.Height = -12
      Font.Name = 'Arial'
      Font.Style = [fsBold, fsUnderline]
      ParentFont = False
    end
    object Lbl_data24: TLabel
      Left = 47
      Top = 84
      Width = 221
      Height = 16
      Alignment = taCenter
      AutoSize = False
      Caption = 'Zone 31'
      Font.Charset = DEFAULT_CHARSET
      Font.Color = clBlack
      Font.Height = -12
      Font.Name = 'Arial'
      Font.Style = []
      ParentFont = False
    end
  end
  object Panel1: TPanel
    Left = 243
    Top = 32
    Width = 630
    Height = 89
    BevelInner = bvLowered
    ParentColor = True
    TabOrder = 2
    object Lbl_Title_2: TLabel
      Left = 128
      Top = 56
      Width = 377
      Height = 25
      Alignment = taCenter
      AutoSize = False
      Caption = 'Coordinate Conversion and Routing Program'
      Font.Charset = ANSI_CHARSET
      Font.Color = clBlack
      Font.Height = -16
      Font.Name = 'Arial'
      Font.Style = [fsBold]
      ParentFont = False
    end
    object Lbl_Title_1: TLabel
      Left = 240
      Top = 8
      Width = 131
      Height = 37
      Caption = 'GeoUTM'
      Font.Charset = DEFAULT_CHARSET
      Font.Color = clBlack
      Font.Height = -32
      Font.Name = 'Arial'
      Font.Style = [fsBold, fsUnderline]
      ParentFont = False
    end
  end
  object ToolBar: TToolBar
    Left = 0
    Top = 0
    Width = 900
    Height = 22
    ButtonHeight = 30
    ButtonWidth = 38
    Caption = 'ToolBar'
    Color = clBtnFace
    DrawingStyle = dsGradient
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -11
    Font.Name = 'Arial'
    Font.Style = []
    ParentColor = False
    ParentFont = False
    ShowCaptions = True
    TabOrder = 3
    Transparent = False
    object ToolButton1: TToolButton
      Left = 0
      Top = 0
      Width = 12
      Caption = 'ToolButton1'
      ImageIndex = 12
      Style = tbsSeparator
    end
    object ToolBtn_Load: TToolButton
      Left = 12
      Top = 0
      Caption = 'TB1'
      ImageIndex = 0
      ParentShowHint = False
      ShowHint = True
      Style = tbsDropDown
    end
    object ToolBtn_Save: TToolButton
      Left = 65
      Top = 0
      Caption = 'TB2'
      ImageIndex = 1
      ParentShowHint = False
      ShowHint = True
      Style = tbsDropDown
    end
    object ToolBtn_Export: TToolButton
      Left = 118
      Top = 0
      Caption = 'TB3'
      ImageIndex = 16
      ParentShowHint = False
      ShowHint = False
    end
    object TB_1: TToolButton
      Left = 156
      Top = 0
      Width = 18
      Caption = 'TB_1'
      ImageIndex = 2
      Style = tbsSeparator
    end
    object ToolBtn_Heights: TToolButton
      Left = 174
      Top = 0
      Caption = 'TB4'
      ImageIndex = 6
    end
    object TB_2: TToolButton
      Left = 212
      Top = 0
      Width = 18
      Caption = 'TB_2'
      ImageIndex = 2
      Style = tbsSeparator
    end
    object ToolBtn_Crds: TToolButton
      Left = 230
      Top = 0
      Hint = 'Show Coordinates'
      Caption = 'TB5'
      Down = True
      Grouped = True
      ImageIndex = 7
      ParentShowHint = False
      ShowHint = True
      Style = tbsCheck
    end
    object ToolBtn_Left: TToolButton
      Left = 268
      Top = 0
      Caption = 'TB6'
      Enabled = False
      ImageIndex = 13
    end
    object ComboBox_Route: TComboBox
      Left = 306
      Top = 0
      Width = 152
      Height = 22
      Style = csDropDownList
      TabOrder = 0
      Items.Strings = (
        'Route 1'
        'Route 2'
        'Route 3'
        'Route 4'
        'Route 5'
        'Route 6'
        'Route 7'
        'Route 8'
        'Route 9'
        'Route 10'
        '')
    end
    object ToolBtn_Right: TToolButton
      Left = 458
      Top = 0
      Caption = 'TB7'
      Enabled = False
      ImageIndex = 14
    end
    object ToolBtn_Route: TToolButton
      Left = 496
      Top = 0
      Caption = 'TB8'
      Grouped = True
      ImageIndex = 9
      ParentShowHint = False
      ShowHint = True
      Style = tbsCheck
    end
    object ToolBtn_KPlist: TToolButton
      Left = 534
      Top = 0
      Caption = 'TB9'
      Grouped = True
      ImageIndex = 8
      Style = tbsCheck
    end
    object ToolBtn_Xing: TToolButton
      Left = 572
      Top = 0
      Caption = 'TB10'
      Grouped = True
      ImageIndex = 10
      ParentShowHint = False
      ShowHint = True
      Style = tbsCheck
    end
    object TB_4: TToolButton
      Left = 610
      Top = 0
      Width = 30
      Caption = 'TB_4'
      ImageIndex = 4
      Style = tbsSeparator
    end
    object ToolBtn_Conv: TToolButton
      Left = 640
      Top = 0
      Hint = 'Show Conversion'
      Caption = 'TB11'
      Down = True
      Grouped = True
      ImageIndex = 2
      ParentShowHint = False
      ShowHint = True
      Style = tbsCheck
    end
    object ToolBtn_RouteInfo: TToolButton
      Left = 678
      Top = 0
      Hint = 'Show Routing Info'
      Caption = 'TB12'
      Grouped = True
      ImageIndex = 4
      ParentShowHint = False
      ShowHint = True
      Style = tbsCheck
    end
    object ToolBtn_Grid: TToolButton
      Left = 716
      Top = 0
      Hint = 'Show Grid Info'
      Caption = 'TB13'
      Grouped = True
      ImageIndex = 3
      ParentShowHint = False
      ShowHint = True
      Style = tbsCheck
    end
    object TB_5: TToolButton
      Left = 754
      Top = 0
      Width = 28
      Caption = 'TB_5'
      ImageIndex = 4
      Style = tbsSeparator
    end
    object ToolButton_incDigit: TToolButton
      Left = 782
      Top = 0
      Hint = 'Increase decimal'
      Caption = 'TB14'
      ImageIndex = 11
      ParentShowHint = False
      ShowHint = True
    end
    object ToolButton_DecDigit: TToolButton
      Left = 820
      Top = 0
      Hint = 'Decrease decimal'
      Caption = 'TB15'
      ImageIndex = 12
      ParentShowHint = False
      ShowHint = True
    end
  end
  object Timer1: TTimer
    OnTimer = Timer1Timer
    Left = 8
    Top = 296
  end
  object MainMenu1: TMainMenu
    Left = 16
    Top = 240
    object Files1: TMenuItem
      Caption = 'Files'
      object mi_Exit: TMenuItem
        Caption = 'Exit'
      end
    end
    object mi_Views: TMenuItem
      Caption = 'Views'
      object mi_DataConversion: TMenuItem
        Caption = 'Data conversion'
      end
      object mi_GridInfo: TMenuItem
        Caption = 'Grid info'
      end
      object mi_Routeinfo: TMenuItem
        Caption = 'Route info'
      end
      object N8: TMenuItem
        Caption = '-'
      end
      object N11: TMenuItem
        Caption = '-'
      end
    end
    object mi_Conversion: TMenuItem
      Caption = 'Conversion'
    end
    object mi_Routes: TMenuItem
      Caption = 'Routes'
      object mi_Route: TMenuItem
        Caption = 'Routes'
      end
      object mi_KPlist: TMenuItem
        Caption = 'KP list'
      end
      object mi_Crossing: TMenuItem
        Caption = 'Crossings'
      end
    end
    object mi_DTM: TMenuItem
      Caption = 'DTM'
    end
    object MI_Blockshift: TMenuItem
      Caption = 'Block-Shift'
    end
    object Worldmap1: TMenuItem
      Caption = 'Worldmap'
    end
  end
end

我希望这足以让你重复这个问题。

0 个答案:

没有答案