精华区 [关闭][返回]

当前位置:网易精华区>>讨论区精华>>编程开发>>● Delphi>>Windows API函数>>[文章]如何实现浮动、状态自动提示

主题:[文章]如何实现浮动、状态自动提示
发信人: delphifan()
整理人: windfire(2000-12-05 19:54:01), 站内信件
                            如何实现浮动、状态自动提示

                                  西安      梁  明



      如果注意到Delphi4提供给TStatusBar类的新特性---AutoHint,那么要获
得这样的效果简直就是太
      简单了!这样做,我们不需要写一句代码,而且,我们可以设置显示浮动
提示的截获时间、停留时
      间、背景颜色等等。
      下面,我来解释一下如何快速实现这个功能:
      首先,我们必须明白,Delphi下的Hint实际上由两部分组成,中间由“|”
隔开,第一部分就是我
      们需要的浮动提示,第二部分就是状态栏提示。当然,要说明的是,如果
我们只提供第一部分,那
      么,系统将不区别这来两者,以同样的提示显示出来。
      何为浮动提示,大家很容易理解,而状态栏提示即是在窗体的状态栏上显
示的提示。对于浮动提
      示,我们很容易获得,只需将其组件的ShowHint属性设为True即可。在De
lphi4以前,要实现状态
      栏提示,必须自己手动添加一个过程来实现,但是,在Delphi4中只需设置
TStatusBar的一个属性
      即可,但是这也要付出代价,那就是“只能”在状态栏的第一个Panel中显
示。
      具体做法是:
      1、为需要提示的组件添加Hint属性(由两部分组成),并设置其ShowHin
t=True;
      2、为窗体添加TStatusBar,并添加一个Panel,设置其AutoHint=True;

      注意:如果你不想显示浮动提示,只需将Hint设置为“|what you want..
.”即可,意思就是将第
      一部分设置为空!下面,我将举一例,程序本身并无价值,但是能体现出
这个意思。
      关于如何改变浮动提示的截获时间、停留时间、背景颜色等等,可以查阅
一下全局变量
      TApplication的帮助,本文暂时不涉及到,今后将专文论述!
      下面是源代码(不需要一句!):
      {=======Copyright by Liangming }
      {        Delphifan WorkRoom    }
      unit main;

      interface

      uses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
 Dialogs,
      Menus, ComCtrls, ToolWin, StdActns, ActnList, ImgList, StdCtrls;


      type
      TForm1 = class(TForm)
      MainMenu1: TMainMenu;
      F1: TMenuItem;
      E1: TMenuItem;
      H1: TMenuItem;
      StatusBar1: TStatusBar;
      N1: TMenuItem;
      N2: TMenuItem;
      N3: TMenuItem;
      A1: TMenuItem;
      N4: TMenuItem;
      N5: TMenuItem;
      N6: TMenuItem;
      T1: TMenuItem;
      C1: TMenuItem;
      P1: TMenuItem;
      H2: TMenuItem;
      I1: TMenuItem;
      N7: TMenuItem;
      A2: TMenuItem;
      CoolBar1: TCoolBar;
      ToolBar1: TToolBar;
      ToolButton1: TToolButton;
      ToolButton2: TToolButton;
      ToolButton3: TToolButton;
      ImageList1: TImageList;
      procedure FormCreate(Sender: TObject);
      private
      { Private declarations }
      public
      { Public declarations }
      end;

      var
      Form1: TForm1;

      implementation

      {$R *.DFM}

      procedure TForm1.FormCreate(Sender: TObject);
      begin

      end;

      end. 

      窗体As text代码 
      object Form1: TForm1
      Left = 198
      Top = 215
      Width = 437
      Height = 251
      Caption = '测试浮动、状态栏提示-->梁明'
      Color = clBtnFace
      Font.Charset = GB2312_CHARSET
      Font.Color = clWindowText
      Font.Height = -12
      Font.Name = '宋体'
      Font.Style = []
      OldCreateOrder = False
      OnCreate = FormCreate
      PixelsPerInch = 96
      TextHeight = 12
      object StatusBar1: TStatusBar
      Left = 0
      Top = 205
      Width = 429
      Height = 19
      AutoHint = True
      Panels = <
item
Width = 50
end>
      SimplePanel = False
      end
      object CoolBar1: TCoolBar
      Left = 0
      Top = 0
      Width = 429
      Height = 24
      AutoSize = True
      Bands = <
item
Control = ToolBar1
ImageIndex = -1
MinHeight = 20
Width = 425
end>
      DockSite = True
      object ToolBar1: TToolBar
      Left = 9
      Top = 0
      Width = 412
      Height = 20
      AutoSize = True
      ButtonHeight = 20
      ButtonWidth = 55
      Caption = '快捷工具栏'
      DragKind = dkDock
      DragMode = dmAutomatic
      EdgeBorders = []
      Flat = True
      ShowCaptions = True
      TabOrder = 0
      object ToolButton1: TToolButton
      Left = 0
      Top = 0
      Caption = '文件(&F)'
      Grouped = True
      MenuItem = F1
      end
      object ToolButton2: TToolButton
      Left = 55
      Top = 0
      Caption = '编辑(&E)'
      Grouped = True
      MenuItem = E1
      end
      object ToolButton3: TToolButton
      Left = 110
      Top = 0
      Caption = '帮助(&H)'
      Grouped = True
      MenuItem = H1
      end
      end
      end
      object MainMenu1: TMainMenu
      Images = ImageList1
      Left = 248
      Top = 88
      object F1: TMenuItem
      Caption = '文件(&F)'
      object N1: TMenuItem
      Caption = '打开'
      Hint = '打开'
      ImageIndex = 0
      ShortCut = 16463
      end
      object N2: TMenuItem
      Caption = '-'
      GroupIndex = 1
      end
      object N3: TMenuItem
      Caption = '保存'
      GroupIndex = 1
      Hint = '保存'
      ShortCut = 16467
      end
      object A1: TMenuItem
      Caption = '另存为(&A)'
      GroupIndex = 1
      Hint = '另存为'
      end
      object N4: TMenuItem
      Caption = '-'
      GroupIndex = 1
      end
      object N5: TMenuItem
      Caption = '关闭'
      GroupIndex = 1
      Hint = '关闭'
      ShortCut = 32883
      end
      end
      object E1: TMenuItem
      Caption = '编辑(&E)'
      object N6: TMenuItem
      Caption = '恢复'
      Hint = '恢复'
      ShortCut = 16474
      end
      object T1: TMenuItem
      Caption = '剪切(&T)'
      Hint = '剪切'
      ShortCut = 16472
      end
      object C1: TMenuItem
      Caption = '拷贝(&C)'
      Hint = '拷贝'
      ImageIndex = 1
      ShortCut = 16451
      end
      object P1: TMenuItem
      Caption = '粘贴(&P)'
      Hint = '粘贴'
      ImageIndex = 2
      ShortCut = 16470
      end
      end
      object H1: TMenuItem
      Caption = '帮助(&H)'
      object H2: TMenuItem
      Caption = '主题(&H)'
      Hint = '主题'
      ImageIndex = 1
      end
      object I1: TMenuItem
      Caption = '索引(&I)'
      Hint = '索引'
      end
      object N7: TMenuItem
      Caption = '-'
      end
      object A2: TMenuItem
      Caption = '关于(&A)'
      Hint = '关于...'
      end
      end
      end
      object ImageList1: TImageList
      Left = 208
      Top = 48
      Bitmap = {
      494C010101000400040010001000FFFFFFFFFF10FFFFFFFFFFFFFFFF424D3600

      0000000000003600000028000000400000001000000001001000000000000008

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      000000000000000000000000000000000000000000000000E07FF75EE07FF75E

      E07FF75EE07FF75EE07F00000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      00000000000000000000000000000000000000000000FF7F0000E07FF75EE07F

      F75EE07FF75EE07FF75EE07F0000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      00000000000000000000000000000000000000000000E07FFF7F0000E07FF75E

      E07FF75EE07FF75EE07FF75EE07F000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      00000000000000000000000000000000000000000000FF7FE07FFF7F00000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      00000000000000000000000000000000000000000000E07FFF7FE07FFF7FE07F

      FF7FE07FFF7FE07F000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      00000000000000000000000000000000000000000000FF7FE07FFF7FE07FFF7F

      E07FFF7FE07FFF7F000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      00000000000000000000000000000000000000000000E07FFF7FE07FFF7FE07F

      FF7F000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      000000000000000000000000000000000000000000000000E07FFF7FE07FFF7F

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      00000000000000000000000000000000000000000000EF3D0000000000000000

      EF3D000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      000000000000000000000000000000000000424D3E000000000000003E000000

      2800000040000000100000000100010000000000800000000000000000000000

      000000000000000000000000FFFFFF00FFFF000000000000FFFF000000000000

      FFFF000000000000FFFF000000000000C00F0000000000008007000000000000

      800300000000000080010000000000008001000000000000800F000000000000

      800F000000000000801F000000000000C0FF000000000000C0FF000000000000

      FFFF000000000000FFFF00000000000000000000000000000000000000000000

      000000000000}
      end
      end

        
      版主:梁明 
      日期:1999-03-16-1:37
      E-mail:[email protected] 


--
+===========请与我联系(Please remember me)===========+
+                                                    +
+                [email protected]                   +
+                                                    + 
+         http://www4.netease.com/~delphifan         +

※ 来源:.月光软件站 http://www.moon-soft.com.[FROM: 202.100.29.199]

[关闭][返回]