テキストを左から流して表示するには?

解決


ちょこぼ  2005-04-25 06:43:53  No: 121238

サウンドノベルゲームのように、テキストを一文ずつ、左から順番に流して表示するにはどうしたらいいでしょうか?

後、指定の場所で流れてる文章が止まり、クリックするとまた流れ始めるようにしたいのですが・・・。

どなたか教えてくださいm_ _m


3−t  2005-04-25 08:18:14  No: 121239

テキストボックスに文字を表示するにはどうすればいいですか?


あんび  2005-04-25 19:25:47  No: 121240

画面にコマンドボタン(Command1)、ラベル(Label1)をはりつけて

以下をコードにはりつけてやってみてください。
あとは頑張って、内容を理解していってください。

Option Explicit

Private Sub Command1_Click()
Dim i       As Integer
Dim txtMsg  As String
    Label1 = ""
    txtMsg = "あいうえお|@@@かきくけこ"
    For i = 1 To Len(txtMsg)
        If Mid(txtMsg, i, 1) = "@" Then
            Call TimeWait(0.3)
        ElseIf Mid(txtMsg, i, 1) = "|" Then
            Label1 = Label1 & vbCrLf
        Else
            Label1 = Label1 & Mid(txtMsg, i, 1)
            Call TimeWait(0.1)
        End If
    Next i

    'ここで
    '後、指定の場所で流れてる文章が止まり、クリックするとまた流れ始めるようにしたいのですが・・・。
    'を頑張っていれてね。
    'そんなに難しくないですが。

End Sub

Private Sub TimeWait(wait As Single)
Dim wrktime As Single
    wrktime = Timer + wait
    Do Until Timer >= wrktime
        DoEvents
    Loop
End Sub


  2005-04-25 22:00:08  No: 121241

あんびさんのを改良
Option Explicit
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Private Sub Command1_Click()
  Dim i As Long
  Dim txtMSG As String
  Dim lngLen As Long
  Dim str As String
  
  
  Label1.Caption = "あいうえお        "
  lngLen = Len(Label1.Caption)
  i = 1
  Do
    Label1.Caption = Mid$(Label1.Caption, 2, lngLen) & Mid$(Label1.Caption, 1, 1)
    Sleep 500
    DoEvents
  Loop
  
End Sub
で、どうですか?


  2005-04-25 22:06:13  No: 121242

改の改良です
Option Explicit
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Private blnStop As Boolean
Private strLabel As String
Private lngLen As Long

Private Sub Command1_Click()
  
  blnStop = False
  If strLabel <> vbNullString Then
    Label1.Caption = strLabel
  End If
  
  Do
    Label1.Caption = Mid$(Label1.Caption, 2, lngLen) & Mid$(Label1.Caption, 1, 1)
    Sleep 500
    DoEvents
    If blnStop = True Then
      strLabel = Label1.Caption
      Exit Do
    End If
  Loop
  
End Sub

Private Sub Command2_Click()
  blnStop = True
End Sub

Private Sub Form_Load()
  Label1.Caption = "あいうえお        "
  lngLen = Len(Label1.Caption)
End Sub


ちょこぼ  2005-04-26 22:13:15  No: 121243

みなさん有難うございますm_ _m
やってみますね。


ちょこぼ  2005-04-26 22:31:39  No: 121244

すいません。質問の仕方が間違っていました・・・。

一文ずつではなく、一文字ずつと書くつもりでした。
例えば「あいうえお、かきくけこ」という文だと、

「あ→い→う→え→お」と流れ、ここで一回止まり、画面をクリックすると「か→き→く→け→こ」と読み進めるようにしたいんです。

コマンドボタンを使用せず、画面をクリックすることで読み進めたい場合は、直接Form1に記述すれば良いのでしょうか?

何度も申し訳ありませんm_ _m


ねろ  2005-04-27 01:41:41  No: 121245

今ひとつ動きが判らないけど。。
Labelを一つ貼り付けて、index プロパティを0にする。

Option Explicit
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Sub MoveStart()
    Dim LabelPos As Long
    LabelPos = Label1(2).Left + Label1(2).Width
    Do
        Label1(1) = Left(Trim(Label1(2)), 1)
        Label1(2) = Right(Label1(2), Len(Label1(2)) - 1)
        Label1(1).Left = Label1(2).Left - Label1(1).Width
        Label1(2).Left = LabelPos - Label1(2).Width
        MoveLabel
    Loop While Trim(Label1(2)) <> "" And Label1(1) <> "お"
    Label1(1) = ""
End Sub
Private Function MoveLabel()
    Do
        Sleep (10)
        Label1(1).Left = Label1(1).Left - 100
        DoEvents
    Loop While (Label1(0).Left + Label1(0).Width) < Label1(1).Left
    Label1(0) = Label1(0) + Label1(1)
    Label1(1).Left = Label1(2).Left - Label1(1).Width
End Function
Private Sub Form_Click()
    MoveStart
End Sub
Private Sub Form_Load()
    Dim i As Integer
   
    For i = 1 To 2
        Load Label1(i)
    Next
    For i = 0 To 2
        With Label1(i)
            .AutoSize = True
            .Caption = ""
            .Left = i * 3000 + 200
            .Top = 1000
            .Visible = True
        End With
    Next
    Label1(2).Caption = "あいうえおかきくけこ"
    Me.Show
    MoveStart
End Sub
こんなことですかね。


ねろ  2005-04-27 01:57:52  No: 121246

連続で失礼。
>Private Sub Form_Click()
>   MoveStart
>End Sub

Private Sub Form_Click()
    If Len(Label1(2)) <> 0 Then
        MoveStart
    End If
End Sub
の方がいいかな。


あの  2005-04-27 02:44:16  No: 121247

というか改さんがこれだけサンプルを出してくれているんだから
それを先ず理解してみてはどうですか?
動かしてみてちがう動きだからこうして欲しいとかじゃ
質問じゃなくて作成依頼じゃないですか。
改さんのサンプルでどうやって文字を流しているのか理解できたなら
後から言っている仕様も自分で作れるはずですよ。


LESIA  2005-04-27 03:26:53  No: 121248

私も、作ってみました。

Option Explicit

Private Const MAX_LENGTH As Integer = 40 '一行に表示可能な文字数
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Private Sub Form_Load()
    Label1.Caption = ""
    
    Me.Show
    
    Call MoveStart("あいうえお")
End Sub

Private Sub Form_Click()
    Call MoveStart("かきくけこ")
End Sub

Private Sub MoveStart(strText As String)
    Dim i As Integer
    
    With Label1
        For i = 1 To Len(strText)
            .Caption = .Caption & _
                       Space$(MAX_LENGTH - Len(.Caption) - 1) & _
                       Mid$(strText, i, 1)
            Do Until InStr(.Caption, " ") = 0
                .Caption = Replace(.Caption, " ", "", 1, 1)
                Sleep 10
                DoEvents
            Loop
        Next i
    End With
End Sub


マグ  2005-04-28 03:34:03  No: 121249

このような動きでしょうか?

VB.NETで作りました。
ちょっと長いですが・・・

    'Labelに表示する文字を格納する変数
    Dim MoziString(3) As String

    'コントロールを定義
    Dim timer1 As Timer

    Dim flg As Boolean

    'カウント
    Dim count As Integer, place As Integer

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        '初期化
        count = 1
        place = 0
        flg = True

        'インスタンスを設定
        timer1 = New Timer
        timer2 = New Timer

        'パラメータの設定
        With timer1
            .Interval = 100
        End With
        With timer2
            .Interval = 1000
        End With

        'Labelの設定
        With Label1
            '各パラメータを設定
            Dim kankaku As Integer
            Dim height As Integer

            kankaku = 20
            height = 40

            'テキストを初期化
            .Text = ""
            'X、Y座標を設定
            .Location = New Point(kankaku, Me.Height - (kankaku * 2 + height))
            .Size = New Size(Me.Width - (kankaku * 2), height)
            '背景色の変更
            .BackColor = Color.FromArgb(128, 0, 0, 255)
            '文字色の設定
            .ForeColor = Color.FromArgb(255, 255, 255)
        End With

        'イベントハンドラーの作成
        AddHandler timer1.Tick, AddressOf timer1_Tick

        'Labelに表示される文字の設定
        MoziString(0) = "あいうえお"
        MoziString(1) = "かきくけこ"
        MoziString(2) = "さしすせそ"

        'TimerをStart
        timer1.Start()

    End Sub

    Private Sub timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)
        'Labelに文字を表示
        If flg Then
            Label1.Text &= GetChar(MoziString(place), count)
            If count >= MoziString(place).Length Then
                count = 0
                place += 1
                flg = False
            End If

            If place >= UBound(MoziString) Then
                Label1.Text &= vbCrLf & "Finish"
                timer1.Stop()
            End If

            count += 1
        End If
    End Sub

    Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
        'イベントハンドラーの破棄
        'コントロールの破棄
        timer1.Dispose()
        timer2.Dispose()
    End Sub

    Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
        If e.KeyCode = Keys.Enter Then
            flg = True
            Label1.Text &= vbCrLf
            timer1.Start()
        End If
    End Sub


ちょこぼ  2005-04-28 07:56:23  No: 121250

みなさん、いろいろ本当にありがとうございます。
まず、挙げていただいた文を理解する事から始めたいと思います。

自分の質問の仕方がどうも悪かったみたいで・・・。
「流す」というか「読み進める」というかなんと表現すればいいのか・・・。

サウンドノベルゲームのような文字表現がしたいんです。

Option Explicit
Dim CRLF$

Private Sub Form_Click()
CRLF$ = Chr$(13) + Chr$(10)
Form1.Print "それは夏の暑い深夜に起こった。" + CRLF$
Form1.Print "別に特別何かを感じたわけではない。 " + CRLF$
Form1.Print "ベッドから目覚めた僕は、その異変に気づいた。"
End Sub

ここで「読み進める」という表現が出来なくて困っているんです。
最初からこう聞けばよかったのに何度も手間をかけてごめんなさい。


あんび  2005-04-28 18:47:46  No: 121251

画面にLabel1(ラベル)を用意してから実行してみてください。
タイトルが「テキストを左から流して表示するには?」なのに
聞きたいことが違ったみたいで、いろんな方がサンプル作ってくれてますが
いろんな方のサンプルをみて何をしているか理解されることを期待します。

CRLF$ = Chr$(13) + Chr$(10)
の表現は vbcrlf  で標準定義されてます。

Option Explicit
Private strMSG(3)   As String
Private intP        As Integer

Private Sub Form_Load()
    strMSG(0) = "あああああ"
    strMSG(1) = "いいいいい"
    strMSG(2) = "ううううう"
    strMSG(3) = "えええええ" & vbCrLf & "おおおおお"
    intP = 0
    Label1 = strMSG(intP)
End Sub

Private Sub Form_Click()
    intP = intP + 1
    If intP > UBound(strMSG()) Then Exit Sub
    Label1 = strMSG(intP)
End Sub


LESIA  2005-04-28 20:25:25  No: 121252

もしかしてこういう事?

Option Explicit

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Private Sub Form_Click()
    Call DisplayText("それは夏の暑い深夜に起こった。" & vbCrLf)
    Call DisplayText("別に特別何かを感じたわけではない。 " & vbCrLf)
    Call DisplayText("ベッドから目覚めた僕は、その異変に気づいた。")
End Sub

Private Sub DisplayText(strText As String)
    Dim i As Integer
    
    For i = 1 To Len(strText)
        Form1.Print Mid$(strText, i, 1);
        Sleep 100
    Next i
End Sub


ねろ  2005-04-28 21:00:01  No: 121253

>>LESIAさん
こうじゃない?

Option Explicit
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Private Sub Form_Click()
    Static no As Integer
    Dim text(0 To 2) As String
    text(0) = "それは夏の暑い深夜に起こった。" & vbCrLf
    text(1) = "別に特別何かを感じたわけではない。 " & vbCrLf
    text(2) = "ベッドから目覚めた僕は、その異変に気づいた。"
    If no > 2 Then
        Form1.Cls
        no = 0
    End If
    DisplayText (text(no))
    no = no + 1
End Sub

Private Sub DisplayText(strText As String)
    Dim i As Integer
    For i = 1 To Len(strText)
        Form1.Print Mid$(strText, i, 1);
        Sleep 100
    Next i
End Sub


ちょこぼ  2005-04-28 21:13:23  No: 121254

あ!まさにその通りです!本当にありがとうございました。
上記で挙げていただいた文も理解できるように頑張ります。

本当に、みなさんありがとうございました。


※返信する前に利用規約をご確認ください。

※Google reCAPTCHA認証からCloudflare Turnstile認証へ変更しました。






  このエントリーをはてなブックマークに追加