200分求解:就是Toolbutton的Size问题。(20分)

  • 主题发起人 主题发起人 歪就歪
  • 开始时间 开始时间

歪就歪

Unregistered / Unconfirmed
GUEST, unregistred user!
对不起,我无论怎样RELOAD,我那个《200分求解:就是Toolbutton的
Size问题》都看不到最后的回答,麻烦请在本栏中继续讨论,并请
哪位帮我把最后的回答贴在这里。

奇怪,为什么?
 
用我这招肯定没问题,exex上的分也给我吧
另外,y9y拜托给我写一个追mm的step by step ,求你了
toolbar1.Perform(TB_SETBUTTONSIZE, 0, MakeLParam(50, 50));
 
对了,step by step要发到我信箱里,别让别人知道了
 
吓死我了……哪儿有被逼无奈的教唆犯?


……
 
hubdog这也算一行解决啊。
 
可以的。我用的是D4你用的是那个版本的?
我把原代码给你。
dfm File
____________________________________________________________________
object Form1: TForm1
Left = 192
Top = 107
Width = 544
Height = 375
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object btnShowCaption: TButton
Left = 232
Top = 160
Width = 75
Height = 25
Caption = 'ShowCaption'
ParentShowHint = False
ShowHint = True
TabOrder = 0
OnClick = btnShowCaptionClick
end
object btnChangeSize: TButton
Left = 88
Top = 56
Width = 75
Height = 25
Caption = 'ChangeSize'
TabOrder = 1
OnClick = btnChangeSizeClick
end
object ToolBar1: TToolBar
Left = 0
Top = 0
Width = 536
Height = 25
ButtonHeight = 21
ButtonWidth = 65
Caption = 'ToolBar1'
ShowCaptions = True
TabOrder = 2
object ToolButton1: TToolButton
Left = 0
Top = 2
Caption = 'ToolButton1'
ImageIndex = 0
end
object ToolButton2: TToolButton
Left = 65
Top = 2
Caption = 'ToolButton2'
ImageIndex = 1
end
object ToolButton3: TToolButton
Left = 130
Top = 2
Width = 8
Caption = 'ToolButton3'
ImageIndex = 2
Style = tbsSeparator
end
object ToolButton4: TToolButton
Left = 138
Top = 2
Caption = 'ToolButton4'
ImageIndex = 2
end
object ToolButton5: TToolButton
Left = 203
Top = 2
Caption = 'ToolButton5'
ImageIndex = 3
end
object ToolButton6: TToolButton
Left = 268
Top = 2
Caption = 'ToolButton6'
ImageIndex = 4
end
end
object Edit1: TEdit
Left = 168
Top = 56
Width = 105
Height = 21
TabOrder = 3
end
object btnAutoSize: TButton
Left = 232
Top = 192
Width = 75
Height = 25
Caption = 'AutoSize False'
TabOrder = 4
OnClick = btnAutoSizeClick
end
end
_____________________________________________________________________
pas File

_____________________________________________________________________
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ComCtrls, ToolWin;

type
TForm1 = class(TForm)
btnShowCaption: TButton;
btnChangeSize: TButton;
ToolBar1: TToolBar;
ToolButton1: TToolButton;
ToolButton2: TToolButton;
ToolButton3: TToolButton;
ToolButton4: TToolButton;
ToolButton5: TToolButton;
ToolButton6: TToolButton;
Edit1: TEdit;
btnAutoSize: TButton;
procedure FormCreate(Sender: TObject);
procedure btnShowCaptionClick(Sender: TObject);
procedure btnChangeSizeClick(Sender: TObject);
procedure btnAutoSizeClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
form1.Canvas.Brush.Style := bsClear;
end;

procedure TForm1.btnShowCaptionClick(Sender: TObject);
begin
ToolBar1.ShowCaptions := not ToolBar1.ShowCaptions;
end;

procedure TForm1.btnChangeSizeClick(Sender: TObject);
begin
ToolBar1.ButtonWidth := StrToInt(edit1.Text);
end;

procedure TForm1.btnAutoSizeClick(Sender: TObject);
begin
ToolBar1.AutoSize := not ToolBar1.AutoSize;
if ToolBar1.AutoSize then
btnAutoSize.Caption := 'AutoSize True'
else
btnAutoSize.Caption := 'AutoSize False';
end;


end.
____________________________________________________________________
当你按ShowCaption把Caption去掉时再在edit框中输入一个数字按ChangSize键
就可以了。你编译试试。呵呵。

 
To SmileSnake:

Thanks, I copy your code, and run it, it is not work as I imaged.

When ShowCaption is set on, Toolbar's button will change its size to fit his caption and do not allow you modify the size with buttonWidth property. That is what touble I meet at here.

Hubdog has an excellent way to solve this problem, and it work. He use perform method, which seems By-Pass the Toolbar's size control.

Thanks for your help.
 
谢谢各位
 
yy哥,step by step 在那呀,我还没收到呀,还没写完。我好急呀
 
后退
顶部