TButton/ja

From Free Pascal wiki
Revision as of 14:05, 3 June 2016 by Miyatakejiro (talk | contribs) (Created page with "{{TButton}} {{Japanese Menu}} >> LCL Components/ja >> TButton<br/> このページでは、TButton/ja コンポーネントの使い...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Deutsch (de) English (en) español (es) suomi (fi) français (fr) 日本語 (ja) русский (ru)

日本語版メニュー
メインページ - Lazarus Documentation日本語版 - 翻訳ノート - 日本語障害情報

>> LCL Components/ja >> TButton

このページでは、TButton/ja コンポーネントの使い方を説明します。 以下の記述で「○○をクリック」とあればそれは左クリックのことです。右クリックの場合は、When I mention to click on something, unless I explicitly say to right-click, you always left-click on the item in question.

IDE上の表示

「Standard」タブの4番目のコントロールであり、「押しボタン」のアイコンで表示されています。

TButtonStandardpalette.png

使い方

TButton/jaForm/ja におけるもっとも基本的なコントロールです。 ボタンをマウスでクリックすることで(または[Tab]キーを押してボタンが選択された状態にして[Enter]キーで押すことで)、アクションが実行されます。 この「クリックすること」は「イベント」と呼ばれます。 このため、For this you need event handler/jaが必要になります。 that are called after the jump.

「ボタン」コントロールをフォームに追加するには、Standard/ja コンポーネントパレットの左から4番目の TButton ("OK" と書かれた四角形のボタン) を押して選択し、ボタンを配置したいフォームの上でクリックしてください。

マウスクリックに対するイベントハンドラは、フォーム上に置いたボタンをダブルクリックすることで簡単に作ることができます。 The event handler for a mouse click can be quite easily reached in which a double-click on the pasted Button (or in the Object Inspector, select the event OnClick of your Button). Form1フォーム上のButton1 のイベントハンドラは、以下のような記述になります。:

procedure TForm1.Button1Click(Sender: TObject);
begin

end;

beginend の間に、Button1 をクリックしたときの処理を書きましょう。


ほとんどすべての初心者用チュートリアルでは、Almost all available beginner tutorials use TButtons as an easy entry into the Object Oriented Programming/ja with Lazarus。. 以下に示すチュートリアルも、初心者にとってボタンの使い方が理解できるように作ったつもりです。Following tutorials are well suited for beginners to understand the use of buttons:

簡単な例

  • Create a new application and drop a TButton on the form.
  • Doubleclick this Button1 on the form (the default handler: OnClick is created for Button1, the source text editor opens).
  • Add following code in the event handler:
procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowMessage('Lazarus makes my day');  //A message will be displayed with the content...
end;
  • Start your program (with Key <F9>).

ボタンの自動生成

Sometimes, instead of creating buttons (or other components) with the Lazarus form designer, it is easier to create them dynamically at run time. This approach is useful especially if you have continually repeated buttons on a form.

This can be achieved as in the the following example (a quick calculator):

  • Create a new blank GUI application with the form Form1 and add StdCtrls to the uses clause (here the TButton is).
  • Change caption Form1 to QuickAdd.
  • Create the OnCreate event handler of Form1 (go in the Object Inspector to the event OnCreate and click the button [...]).
  • Add following code:
procedure TForm1.FormCreate(Sender: TObject);
var
  i: Integer;
  aButton: TButton;
begin
  for i:=0 to 9 do begin              //create 10 Buttons 
    aButton:=TButton.Create(Self);    //create Button, Owner is Form1, where the button is released later
    aButton.Parent:=Self;             //determine where it is to be displayed
    aButton.Width:=aButton.Height;    //Width should correspond to the height of the buttons
    aButton.Left:=i*aButton.Width;    //Distance from left
    aButton.Caption:=IntToStr(i);     //Captions of the buttons (0.9)
    aButton.OnClick:=@aButtonClick;   //the event handler for the button -> will be created yet
  end;
  Self.Height:=aButton.Height;        //Height of the form should correspond to the height of the buttons
  Self.Width:=aButton.Width*10;       //Width of the form to match the width of all buttons
end;
  • Now you must create the event handler for the button clicks.
  • In the source editor, entering your class TForm1 in the section private.
  • Add procedure aButtonClick(Sender: TObject); and then press the keys [CTRL] + [Shift] + [c] (the code completion becomes active and creates the procedure TForm1.aButtonClick(Sender: TObject);.
  • Paste following code:
procedure TForm1.aButtonClick(Sender: TObject);
const
  Cnt: Integer = 0;
var
  i: Integer;
begin
  if (Sender is TButton)                            //called the event handler of a button out?
  and TryStrToInt(TButton(Sender).Caption, i) then  //then try to convert the label in a integer
    begin
      Cnt:=Cnt + i;                                 //the adding counter is incremented by the number of entrechende
      Caption:='QuickAdd: '+IntToStr(Cnt);          //write the result to the caption of the form
    end;
end;
  • Start your application.
Light bulb  Note: You can assign every imaginable event handlers to your buttons, as long as this the form procedure <class>.<name of procedure>(Sender: TObject); has. Thus, you can use one from another class!

See also

TBitBtn/ja
TSpeedButton/ja


Return To: LCL Components  — Previous: TPopupMenu Next: TLabel


LCL Components
Component Tab Components
Standard TMainMenu • TPopupMenu • TButton • TLabel • TEdit • TMemo • TToggleBox • TCheckBox • TRadioButton • TListBox • TComboBox • TScrollBar • TGroupBox • TRadioGroup • TCheckGroup • TPanel • TFrame • TActionList
Additional TBitBtn • TSpeedButton • TStaticText • TImage • TShape • TBevel • TPaintBox • TNotebook • TLabeledEdit • TSplitter • TTrayIcon • TControlBar • TFlowPanel • TMaskEdit • TCheckListBox • TScrollBox • TApplicationProperties • TStringGrid • TDrawGrid • TPairSplitter • TColorBox • TColorListBox • TValueListEditor
Common Controls TTrackBar • TProgressBar • TTreeView • TListView • TStatusBar • TToolBar • TCoolBar • TUpDown • TPageControl • TTabControl • THeaderControl • TImageList • TPopupNotifier • TDateTimePicker
Dialogs TOpenDialog • TSaveDialog • TSelectDirectoryDialog • TColorDialog • TFontDialog • TFindDialog • TReplaceDialog • TTaskDialog • TOpenPictureDialog • TSavePictureDialog • TCalendarDialog • TCalculatorDialog • TPrinterSetupDialog • TPrintDialog • TPageSetupDialog
Data Controls TDBNavigator • TDBText • TDBEdit • TDBMemo • TDBImage • TDBListBox • TDBLookupListBox • TDBComboBox • TDBLookupComboBox • TDBCheckBox • TDBRadioGroup • TDBCalendar • TDBGroupBox • TDBGrid • TDBDateTimePicker
Data Access TDataSource • TCSVDataSet • TSdfDataSet • TBufDataset • TFixedFormatDataSet • TDbf • TMemDataset
System TTimer • TIdleTimer • TLazComponentQueue • THTMLHelpDatabase • THTMLBrowserHelpViewer • TAsyncProcess • TProcessUTF8 • TProcess • TSimpleIPCClient • TSimpleIPCServer • TXMLConfig • TEventLog • TServiceManager • TCHMHelpDatabase • TLHelpConnector
Misc TColorButton • TSpinEdit • TFloatSpinEdit • TArrow • TCalendar • TEditButton • TFileNameEdit • TDirectoryEdit • TDateEdit • TTimeEdit • TCalcEdit • TFileListBox • TFilterComboBox • TComboBoxEx • TCheckComboBox • TButtonPanel • TShellTreeView • TShellListView • TXMLPropStorage • TINIPropStorage • TJSONPropStorage • TIDEDialogLayoutStorage • TMRUManager • TStrHolder
LazControls TCheckBoxThemed • TDividerBevel • TExtendedNotebook • TListFilterEdit • TListViewFilterEdit • TLvlGraphControl • TShortPathEdit • TSpinEditEx • TFloatSpinEditEx • TTreeFilterEdit • TExtendedTabControl •
RTTI TTIEdit • TTIComboBox • TTIButton • TTICheckBox • TTILabel • TTIGroupBox • TTIRadioGroup • TTICheckGroup • TTICheckListBox • TTIListBox • TTIMemo • TTICalendar • TTIImage • TTIFloatSpinEdit • TTISpinEdit • TTITrackBar • TTIProgressBar • TTIMaskEdit • TTIColorButton • TMultiPropertyLink • TTIPropertyGrid • TTIGrid
SQLdb TSQLQuery • TSQLTransaction • TSQLScript • TSQLConnector • TMSSQLConnection • TSybaseConnection • TPQConnection • TPQTEventMonitor • TOracleConnection • TODBCConnection • TMySQL40Connection • TMySQL41Connection • TMySQL50Connection • TMySQL51Connection • TMySQL55Connection • TMySQL56Connection • TMySQL57Connection • TSQLite3Connection • TIBConnection • TFBAdmin • TFBEventMonitor • TSQLDBLibraryLoader
Pascal Script TPSScript • TPSScriptDebugger • TPSDllPlugin • TPSImport_Classes • TPSImport_DateUtils • TPSImport_ComObj • TPSImport_DB • TPSImport_Forms • TPSImport_Controls • TPSImport_StdCtrls • TPSCustomPlugin
SynEdit TSynEdit • TSynCompletion • TSynAutoComplete • TSynMacroRecorder • TSynExporterHTML • TSynPluginSyncroEdit • TSynPasSyn • TSynFreePascalSyn • TSynCppSyn • TSynJavaSyn • TSynPerlSyn • TSynHTMLSyn • TSynXMLSyn • TSynLFMSyn • TSynDiffSyn • TSynUNIXShellScriptSyn • TSynCssSyn • TSynPHPSyn • TSynTeXSyn • TSynSQLSyn • TSynPythonSyn • TSynVBSyn • TSynAnySyn • TSynMultiSyn • TSynBatSyn • TSynIniSyn • TSynPoSyn
Chart TChart • TListChartSource • TRandomChartSource • TUserDefinedChartSource • TCalculatedChartSource • TDbChartSource • TChartToolset • TChartAxisTransformations • TChartStyles • TChartLegendPanel • TChartNavScrollBar • TChartNavPanel • TIntervalChartSource • TDateTimeIntervalChartSource • TChartListBox • TChartExtentLink • TChartImageList
IPro TIpFileDataProvider • TIpHtmlDataProvider • TIpHttpDataProvider • TIpHtmlPanel
Virtual Controls TVirtualDrawTree • TVirtualStringTree • TVTHeaderPopupMenu


--Michl 12:25, 15 May 2014 (CEST)