TextBox Effekt - einlaufen

styler2go

Erfahrenes Mitglied
Hallo.
Ich habe da mal eine frage. Ich möchte eine TextBox erstellen die von der seite "einläuft".
Wie stelle ich das an? Noch besser wärs wenn es mit allem bzw. einer Richtextbox funktzioniert.

Gruß Styler
 
Einfach einen Timer erstellen der mit jedem Aufruf die Textbox einen Pixel oder so weitersetzt

Code:
        Timer timer;

        public Form1()
        {
           timer = new Timer();
            timer.Interval = 22;
            timer.Tick += new EventHandler(timer_Tick);
            timer.Start();
        }


        void timer_Tick(object sender, EventArgs e)
        {
           textbox1.X++;
        }
 
Das geht bei mir nicht... Könntes du ein Demo Projekt machen und uploaden? Wäre seht nett. ALso der Button soll dann auch in der mitte stehen bleiben...
 
Zuletzt bearbeitet:
Ok, stimmt da war ein kleiner Fehler in meinem Code:

Code:
        Timer timer;

        public Form1()
        {
           timer = new Timer();
            timer.Interval = 22;
            timer.Tick += new EventHandler(timer_Tick);
            timer.Start();
        }


        void timer_Tick(object sender, EventArgs e)
        {
           textBox1.Location = new Point(textBox1.Location.X+1, textBox1.Location.Y);
           if(textBox1.Location.X + textBox1.Width / 2 == Width / 2)
              timer.Stop();
        }
 
Also ok.. reden wir überhaupt von der gleichen Sprache? Ich nutze Virtual Basic 2005 Express Edition... ? Habe die vermutung dass das nicht VB ist... aber visual basic 2005 ist doch .net oder? Habe ich da jetzt ienen fehler gemacht und im falschen Forumabteil gepostet?
 
Das Forum ist schon richtig, aber du hast nicht gesagt, welche Sprache du benutzt.
Es sollte eigentlich nicht allzu schwer sein, den C#-Code da oben in VB-Syntax zu bringen.
Ich war mal so nett:

Code:
Public Class Form1
    Dim timer As Timer

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        timer = New Timer() With {.Interval = 22}
        AddHandler timer.Tick, AddressOf timer_Tick
        timer.Start()
    End Sub

    Private Sub timer_Tick(ByVal sender As Object, ByVal e As EventArgs)
        TextBox1.Location = New Point(TextBox1.Location.X + 1, TextBox1.Location.Y)
        If TextBox1.Location.X + TextBox1.Width / 2 = Width / 2 Then timer.Stop()
    End Sub
End Class
 
Zuletzt bearbeitet:
Also, ich habe deinen Code mal verbessert, wie es bei mri dann im endeffekt auch geht:

Code:
Public Class Form1
    Dim timer As Timer

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        timer = New Timer()
        With timer
            .Interval = 22
        End With
        AddHandler timer.Tick, AddressOf timer_Tick
        timer.Start()
    End Sub

    Private Sub timer_Tick(ByVal sender As Object, ByVal e As EventArgs)
        TextBox1.Location = New Point(TextBox1.Location.X + 1, TextBox1.Location.Y)
        If TextBox1.Location.X + TextBox1.Width / 2 = Width / 2 Then timer.Stop()
    End Sub
End Class

Vielen Vielen dank! War sehr hilfreich ich danke danke danke euch! ^^ :);-)
 
Mein Code war nicht falsch... aber du arbeitest mit einem älteren VB.Net... :)

In deinem Fall oben wäre es besser, anstatt des "With"-Blocks einfach "timer.Interval=22" zu schreiben...
 
es funktzioniert nicht :'( er stoppt nicht! Was muss ich machen dass es wieder stoppt? (Bei einem testprojekt gings, als ich es in mein halbfertiges projekt eingefügt hab gings nicht mehr.
 
Zurück