Gadget ›› TextGadget

プログラム言語 FreeBasic


TextGadget

構文

ID= TextGadget(Number, x , y , Width , Height , [String=0] , [Style=0])

Function TextGadget (ByVal gadget As Long, ByVal x As Long, ByVal y As Long, ByVal w As Long, ByVal h As Long, ByRef text As String="", ByVal style As Long=SS_NOTIFY) As HWND

説明

テキストを表示するガジェット

関数 SetGadgetText を使ってガジェット内のテキストを設定できます

関数 GetGadgetText を使ってガジェットからテキストを取得できます

関数 SetGadgetColor を使ってガジェットの色を設定できます

関数 GetGadgetColor を使ってガジェットの色を取得できます

関数 SetGadgetFont を使ってガジェットのフォントを設定できます


オプション

ID - ガジェット・ハンドル

gadget(Number) - 識別子 (ゼロより大きい任意の自然数。1、2、3、4 など)

x,y,Width,Height - 位置とサイズ

text(string) - ガジェット内の任意の文字列

Style - スタイルを選択します(下記参照

プラットホーム

Windows , Linux



足し算と引き算

例1:

#Include "window9.bi"

Dim As integer hwnd,event
hwnd=OpenWindow("1",300,10,500,500)
TextGadget(1,10,10,180,30,"Hello World")

Do
  event=WaitEvent()
  If event=EventClose Then End
Loop


例2:

足し算と引き算の問題を自動生成します。画面のボタンで入力して回答します。
'AdditionSubtraction10key
'Makoto WATANBE
'2020/04/24 update 2020/05/08
'Creative Commons 4.0 Attribution-NonCommercial-ShareAlike

#Include "Window9.bi"
#include "vbcompat.bi"

Dim Shared event9 As Integer
Dim Shared Counter As Integer
Dim Shared LeftString As String
Dim Shared RightString As String
Dim Shared Wrong As Integer
Dim Shared TimeStart As Double
Dim Shared TimeEnd As Double
Dim Shared AnswerTime  As String
Dim Shared KeyIn As String
Dim Shared KeyP As String
Dim Shared Answer As String

Enum
   'Gadgets:
   Button_1 = 1
   Button_2
   Button_3
   Button_4
   Button_5
   Button_6
   Button_7
   Button_8
   Button_9
   Button_0  'Set to 10
   Title_1
   Title_2
   Text_Left
   Text_Right
   Text_Formula
   Text_Answer
   Text_User
   Button_Repeat
   Button_End
End Enum


Sub OpenWindow_Main()
  'Window
  SetGadgetFont(,LoadFont("Consolas",20)) 'Default font

  CenterWindow(OpenWindow("Addition & Subtraction", 0, 0, 1000, 610))
  TextGadget(Title_1, 15, 10, 990, 30, "A total of 20 questions will be generated alternating between addition and subtraction up to 2 digits.")
  TextGadget(Title_2, 15, 50, 700, 30, "Please answer by clicking the numeric keypad in the center with your mouse.")
  SetGadgetFont(Title_1,LoadFont("Cambria",16)) 'Title font
  SetGadgetFont(Title_2,LoadFont("Cambria",16)) 'Title font

  ButtonGadget(7, 320, 100, 120, 120, "7")
  ButtonGadget(8, 440, 100, 120, 120, "8")
  ButtonGadget(9, 560, 100, 120, 120, "9")

  ButtonGadget(4, 320, 220, 120, 120, "4")
  ButtonGadget(5, 440, 220, 120, 120, "5")
  ButtonGadget(6, 560, 220, 120, 120, "6")

  ButtonGadget(1, 320, 340, 120, 120, "1")
  ButtonGadget(2, 440, 340, 120, 120, "2")
  ButtonGadget(3, 560, 340, 120, 120, "3")

  ButtonGadget(Button_0, 320, 460, 360, 100, "0")

  ButtonGadget(Button_Repeat, 720, 40, 120, 50, "Repeat")
  ButtonGadget(Button_End, 850, 40, 120, 50, "End")
  TextGadget(Text_Left, 10, 100, 300, 500, "")
  TextGadget(Text_Right, 700, 100, 300, 500, "")

End Sub


Function CalculationProblem (AorS As String) As String
   'Automatically generate addition and subtraction up to 2 digits.

   Dim A As Integer
   Dim B As Integer
   Dim S As Integer

   Randomize

   Do
      A = Rnd * 99.4
      B = Rnd * 99.4
      S = A+B
   Loop While S >= 100 Or A = 0 Or B = 0
   'Loop While S >= 10

   If AorS = "Add" Then
      CalculationProblem = Space(2- Len(Str(A))) & Str(A) & " + " & Space(2- Len(Str(B))) & Str(B) & _
      " = " & Space(2- Len(Str(S))) & Str(S)
   Else
      CalculationProblem = Space(2- Len(Str(S))) & Str(S) & " - " & Space(2- Len(Str(A))) & Str(A) & _
      " = " & Space(2- Len(Str(B))) & Str(B)
   End If

End Function


Sub NumericKeypad()

   KeyP = ""

   Do
      event9 = WaitEvent
      Select Case EventNumber
         Case 1
            KeyP = "1"
            Print KeyP
         Case 2
            KeyP = "2"
            Print KeyP
         Case 3
            KeyP = "3"
            Print KeyP
         Case 4
            KeyP = "4"
            Print KeyP
         Case 5
            KeyP = "5"
            Print KeyP
         Case 6
            KeyP = "6"
            Print KeyP
         Case 7
            KeyP = "7"
            Print KeyP
         Case 8
            KeyP = "8"
            Print KeyP
         Case 9
            KeyP = "9"
            Print KeyP
         Case 10
            KeyP = "0"
            Print KeyP
         Case Button_End
            End
      End Select

      Print "NumericKeypad Loop"
   Loop Until KeyP <> ""

End Sub


Sub Check()

   If Answer = KeyIn Then
      If Len(Answer) = 1 Then
         Answer = Space(1) & Answer
      End If

      If Counter > 10 Then
         RightString = RightString & Answer & " OK"
      Else
         LeftString = LeftString & Answer & " OK"
      EndIf
   Else
      Wrong = Wrong + 1

      If Len(Answer) = 1 Then
         Answer = Space(1) & Answer
      End If

      If Counter > 10 Then
         RightString = RightString & Answer & " NG:" & KeyIn
      Else
         LeftString = LeftString & Answer & " NG:" & KeyIn
      EndIf
   EndIf

   If Counter = 20 Then
      SetGadgetText(Text_Right,RightString)
      TimeEnd = Now
   ElseIf Counter < 10 Then
      If Counter Mod 2 = 0 Then LeftString = LeftString &  Chr(13) & Chr(10)
   Else
      If Counter Mod 2 = 0 Then RightString = RightString &  Chr(13) & Chr(10)
   End If

End Sub


' Main program:

   OpenWindow_Main()

backagain:

   TimeStart = Now

   Do While Counter < 20

      Dim Calculation As String
      Dim Mojiretsu As String
      Dim Formula As String

      Counter = Counter + 1

      If Counter Mod 2 =1 Then
         Calculation = "Add"
      Else
         Calculation = "Subt"
      End If

      Mojiretsu = CalculationProblem (Calculation)
      Formula = Left(Mojiretsu,10)
      Answer = Trim(Right(Mojiretsu,3))

      If  Counter = 1 Then
         LeftString = Formula
      ElseIf Counter = 11 Then
         RightString = Formula
      ElseIf Counter > 11 Then
         RightString = RightString & Chr(13) & Chr(10) & Formula
      Else
         LeftString = LeftString & Chr(13) & Chr(10) & Formula
      End If

      SetGadgetText(Text_Left,LeftString)
      SetGadgetText(Text_Right,RightString)

      KeyIn = ""

      Do While Len(KeyIn) < Len(Answer)
         NumericKeypad()
         KeyIn = KeyIn & KeyP
      Loop

      Check()

   Loop

   AnswerTime = Format (TimeEnd - TimeStart, "hh:mm:ss")

   SetGadgetText(Title_2, "Correct = " & Str(20-Wrong) & " ,  Wrong = " & Str(Wrong) & " .    Answer time : " & AnswerTime)
   SetGadgetColor(Title_2, 0, &h0000ff, 2)

   Do
      event9 = WaitEvent
      Select Case EventNumber
         Case Button_Repeat
            Counter = 0
            Wrong = 0
            LeftString = ""
            RightString = ""
            SetGadgetText(Title_2, "Please answer by clicking the numeric keypad in the center with your mouse.")
            SetGadgetColor(Title_2, 0, &h000000, 2)
            GoTo  backagain
            event9 = EventClose
         Case Button_End
            End
      End Select
      Print "Repeat or End Loop"
   Loop Until event9 = EventClose
End

Style:

Windows と Linux:

Windows のみ:



http://mneniya.ucoz.ru/

←リンク元に戻る Window9 トップに戻る FreeBASIC マニュアル トップに戻る
ロシア語オリジナル:https://users.freebasic-portal.de/freebasicru/window9lib/window9.html