📄 fcustomizebuttons.pas
字号:
else
if (tbxToolbar.Items[I] is TTBXItem)
or (tbxToolbar.Items[I] is TTBXSubmenuItem)
or (tbxToolbar.Items[I] is TTBXVisibilityToggleItem) then
lstItem := lstAvailable.FindCaption(0, tbxToolbar.Items[I].Caption, False, True, False);
If (lstItem <> Nil) Then begin
lstAvailable.Selected := lstItem;
btnInsertClick(btnInsert);
end;
end;
end;
lstSelected.Items.EndUpdate;
lstAvailable.Items.EndUpdate;
end;
procedure TfrmToolbarEdit.lstAvailableDblClick(Sender: TObject);
begin
btnInsertClick(btnInsert);
end;
procedure TfrmToolbarEdit.lstSelectedDblClick(Sender: TObject);
begin
btnRemoveClick(lstSelected);
end;
function TBXFindToolbarButton(Toolbar : TTBXToolbar; BtnCaption : String) : Integer;
var
i : Integer;
begin
Result := -1;
//B.T.->
for i := Toolbar.Items.Count - 1 downto 0 do
if ((Toolbar.Items[I] is TTBXSeparatorItem) and (BtnCaption = 'Separator'))
or (Toolbar.Items[I].Caption = BtnCaption) then begin
Result := i;
break;
end;
//B.T.|
end;
procedure TBXUpdateToolbarDisplay(Toolbar : TTBXToolbar;
SelectedCommands : TStrings; CaptionState, ImageListID : Integer);
var
I : Integer;
BtnNum : Integer;
NewSep : TTBXSeparatorItem;
MinCaptionWidth : Integer;
begin
(*case ImageListID of
0: Toolbar.Images := Form1.ImageList1; // Large Icons
1: Toolbar.Images := Form1.ImageList2; // Small Icons
2: Toolbar.Images := Form1.ImageList3; // Large Icons XP
3: Toolbar.Images := Form1.ImageList4; // Small Icons XP
else
end;
*)
With Toolbar Do begin
BeginUpdate;
Items.ViewBeginUpdate;
// Remove all existing separators from the toolbar
For I := Toolbar.Items.Count - 1 DownTo 0 Do begin
If (Toolbar.Items[I] is TTBXSeparatorItem) Then
Toolbar.Items[I].Free;
end;
// Start by hiding all existing buttons on the toolbar
For I := 0 to Toolbar.Items.Count - 1 Do
Toolbar.Items[I].Visible := False;
// toolbar settings
case CaptionState of
0: begin //display Image above Caption
Options := [tboImageAboveCaption];
// adjust MinCaptionWidth according to the image size
// you can select this increment value (+20) yourself
MinCaptionWidth := Toolbar.Images.Height + 20;
end;
else
Options := [];
MinCaptionWidth := 0; // fit image(+caption) size automatically
end;
for i := 0 to Toolbar.Items.Count - 1 do begin
if (tbxToolbar.Items[i] is TTBXItem) then
(tbxToolbar.Items[i] as TTBXItem).MinWidth:=MinCaptionWidth else
if (tbxToolbar.Items[i] is TTBXSubmenuItem) then begin
// adjust button width for extra arrow space
with (tbxToolbar.Items[i] as TTBXSubmenuItem) do
if DropdownCombo
then MinWidth:=MinCaptionWidth + 20
else MinWidth:=MinCaptionWidth + 5;
end else
if (tbxToolbar.Items[i] is TTBXVisibilityToggleItem) then
(tbxToolbar.Items[i] as TTBXVisibilityToggleItem).MinWidth:=MinCaptionWidth;
end;
For I := 0 To SelectedCommands.Count - 1 Do begin
If (SelectedCommands[I] = 'Separator') Then begin
NewSep := TTBXSeparatorItem.Create(Toolbar);
NewSep.Name := 'ToolbarSepTBX' + IntToStr(I);
NewSep.ParentComponent := Toolbar;
NewSep.Blank := False;
NewSep.Visible := True;
Toolbar.Items.Insert(I, NewSep);
end
Else
begin
BtnNum := TBXFindToolbarButton(Toolbar, SelectedCommands[I]);
If (BtnNum >= 0) Then begin
With (Toolbar.Items[BtnNum]) Do begin
If (I < Toolbar.Items.Count)
Then Toolbar.Items.Move(BtnNum, I)
Else Toolbar.Items.Move(BtnNum, I - 1);
Visible := True;
end;
with Toolbar.Items[BtnNum] do
case CaptionState of
0: begin //display Image above Caption
DisplayMode := nbdmDefault;
Hint:=''; //no Hint when caption displayed
end;
1: begin // captions to selected buttons only
//set Tag > 0 to indicate a 'selected' button
if Tag > 0
then DisplayMode := nbdmImageAndText
else DisplayMode := nbdmDefault;
if Tag > 0
then Hint:='' //no Hint if caption displayed
else Hint:=Caption; //show Hints if no caption
end;
2: begin // icon only, no captions
DisplayMode := nbdmDefault;
Hint:=Caption; //show Hint
end;
end;
end;//(BtnNum >= 0)
end;
end;
Items.ViewEndUpdate;//B.T.
View.RecreateAllViewers;//self-click all items-else order is broken!
EndUpdate;
end;
end;
procedure ReadDefaultButtonOptions;
begin // get existing Caption and Icon style
BakCaptionState := 0; // default values
BakImageListID := 0;
// read new values if available from Register or INI file else use default
if (sRegistryKey <> EmptyStr) then
with TRegistry.Create do begin
Access := KEY_READ;// or KEY_WRITE;
RootKey := HKEY_CURRENT_USER;
if OpenKey(sRegistryKey + '\Options', False) then begin
if ValueExists('Show Captions') then BakCaptionState:= ReadInteger('Show Captions');
if ValueExists('Image Style') then BakImageListID := ReadInteger('Image Style');
end;
Free;
end;
if (sIniFileName <> EmptyStr) then
with TIniFile.Create(sIniFileName) do begin
BakCaptionState:= ReadInteger(tbxToolbar.Name + 'Options', 'Show Captions', BakCaptionState);
BakImageListID := ReadInteger(tbxToolbar.Name + 'Options', 'Image Style', BakImageListID);
Free;
end;
end;
procedure TBXGetDefaultToolbarButtons(Toolbar : TTBXToolbar);
var
i: Integer;
begin
//get BakCaptionState, BakImageListID
ReadDefaultButtonOptions;
BakImageList := TImageList.Create(frmToolbarEdit);
BakImageList.Assign(Toolbar.Images);
BakCommands := TStringList.Create;
BakCommands.Clear;
// Backup Command names in BakCommands list
for i := 0 to Toolbar.Items.Count - 1 do
if (Toolbar.Items[I].Visible) then begin
if (Toolbar.Items[I] is TTBXSeparatorItem) then
BakCommands.Add('Separator')
else
if (Toolbar.Items[I] is TTBXItem)
or (Toolbar.Items[I] is TTBXSubmenuItem)
or (Toolbar.Items[I] is TTBXVisibilityToggleItem) then
BakCommands.Add(Toolbar.Items[I].Caption);
end;
end;
procedure TBXSaveToolbarButtons(Toolbar: TTBXToolbar; CaptionState, ImageListID: Integer);
var
i : integer;
tmpButtonList : TStringList;
SecName: string;
begin
if (sRegistryKey <> EmptyStr) then
with TRegistry.Create do
try
Access := KEY_READ or KEY_WRITE;
RootKey := HKEY_CURRENT_USER;
OpenKey(sRegistryKey + '\Options', True);
WriteInteger('Show Captions', CaptionState);
WriteInteger('Image Style', ImageListID);
OpenKey(sRegistryKey + '\Buttons', True);
// Delete any existing button keys first
tmpButtonList := TStringList.Create;
tmpButtonList.Clear;
GetValueNames(tmpButtonList);
for i := 0 to tmpButtonList.Count - 1 do
DeleteValue(tmpButtonList[I]);
tmpButtonList.Free;
// Now add the list of currently displayed (visible) buttons only.
for I := 0 to Toolbar.Items.Count - 1 do
if (Toolbar.Items[I].Visible) then begin
if (Toolbar.Items[I] is TTBXSeparatorItem) then
WriteString('Button'+Format('%.2d', [I]), 'Separator')
else
if (Toolbar.Items[I] is TTBXItem)
or (Toolbar.Items[I] is TTBXSubmenuItem)
or (Toolbar.Items[I] is TTBXVisibilityToggleItem) then
WriteString('Button'+Format('%.2d', [I]), Toolbar.Items[I].Caption);
end;
finally
Free;
end;
if (sIniFileName <> EmptyStr) then
with TIniFile.Create(sIniFileName) do
try
WriteInteger(tbxToolbar.Name + 'Options', 'Show Captions', CaptionState);
WriteInteger(tbxToolbar.Name + 'Options', 'Image Style', ImageListID);
// Delete any existing button keys first
SecName := tbxToolbar.Name + 'Buttons';
EraseSection(SecName);
// Now add the list of currently displayed (visible) buttons only.
For I := 0 to Toolbar.Items.Count - 1 Do
If (Toolbar.Items[I].Visible) Then begin
if (Toolbar.Items[I] is TTBXSeparatorItem) then
WriteString(SecName, 'Button'+Format('%.2d', [I]), 'Separator')
else
if (Toolbar.Items[I] is TTBXItem)
or (Toolbar.Items[I] is TTBXSubmenuItem)
or (Toolbar.Items[I] is TTBXVisibilityToggleItem) then
WriteString(SecName, 'Button'+Format('%.2d', [I]), Toolbar.Items[I].Caption);
end;
finally
Free;
end;
end;
procedure TBXRestoreToolbarButtons(Toolbar : TTBXToolbar; var CaptionState,
ImageListID: Integer);
var
i : integer;
ButtonList : TStringList;
begin
ButtonList := TStringList.Create;
ButtonList.Clear;
if (sRegistryKey <> EmptyStr) then
with TRegistry.Create do
try
Access := KEY_READ or KEY_WRITE;
RootKey := HKEY_CURRENT_USER;
//if no setting to restore then assume current by default
if not OpenKey(sRegistryKey + '\Options', False) then
TBXSaveToolbarButtons(Toolbar, CaptionState, ImageListID);
// read new values or use default
if ValueExists('Show Captions') then CaptionState:= ReadInteger('Show Captions');
if ValueExists('Image Style') then ImageListID := ReadInteger('Image Style');
if OpenKey(sRegistryKey + '\Buttons', False) then begin
GetValueNames(ButtonList); // Get the list of buttons
for i := 0 to ButtonList.Count - 1 do // read button names
ButtonList[I] := ReadString(ButtonList[I]);
end;
finally
Free;
end;
if (sIniFileName <> EmptyStr) then
with TIniFile.Create(sIniFileName) do
try
//if no setting to restore then assume CURRENT by default
if not SectionExists(tbxToolbar.Name + 'Options') then
TBXSaveToolbarButtons(Toolbar, CaptionState, ImageListID);
// read new values or use default
CaptionState:= ReadInteger(tbxToolbar.Name + 'Options', 'Show Captions', CaptionState);
ImageListID := ReadInteger(tbxToolbar.Name + 'Options', 'Image Style', ImageListID);
ButtonList.Clear;
//read section keys
ReadSectionValues(tbxToolbar.Name + 'Buttons', ButtonList);
// read button names
for i := 0 to ButtonList.Count - 1 do
ButtonList[I] := ReadString(tbxToolbar.Name + 'Buttons', ButtonList.Names[I], EmptyStr);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -