TO SCROLL A TEXT INSIDE PICTURE BOX

Madhu Mitha

Total Post:31

Points:217
Posted by  Madhu Mitha
VB.Net 
 1065  View(s)
Ratings:
Rate this:
hi thr,

          I want to scroll text inside a picturebox, from right to left can anyone help me in solving this problem..

My code is 

Public Class Form1
    Dim brush As New Drawing.SolidBrush(Color.Black)
    Dim g2 As System.Drawing.Graphics
    Dim img As New Bitmap(400, 100)
    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        g2 = Graphics.FromImage(img)
        PictureBox1.Image = img
        g2.Clear(Color.White)
        g2.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
        g2.TextRenderingHint = Drawing.Text.TextRenderingHint.ClearTypeGridFit
        g2.CompositingQuality = Drawing2D.CompositingQuality.HighQuality
        '
        g2.DrawString(TextBox1.Text, TextBox1.Font, Brushes.Red, 0, 0)
    End Sub
End Class

  1. John Smith

    Post:103

    Points:727
    Re: To scroll a text inside picture box

    try below lines of code:

    Imports System.IO  
    Imports System.Drawing  
    Public Class Form1  
        Private WithEvents Label1 As New System.Windows.Forms.Label  
        Private WithEvents Label2 As New System.Windows.Forms.Label  
        Private WithEvents label3 As New System.Windows.Forms.Label  
        Private WithEvents newPictureBox1 As New System.Windows.Forms.PictureBox  
        Private WithEvents newPictureBox2 As New System.Windows.Forms.PictureBox  
        Private WithEvents newPictureBox3 As New System.Windows.Forms.PictureBox  
              
        Private Labels() As Label  
        Private newPictureBoxs() As PictureBox  
      
        Dim x As Integer  
      
      
        Dim newPictureBox As New PictureBox  
      
      
        Private Sub Form1_Load(ByVal sender As ObjectByVal e As System.EventArgs) Handles MyBase.Load  
      
      
            newPictureBox1.Image = Image.FromFile("C:\1.gif")  
            newPictureBox2.Image = Image.FromFile("C:\2.gif")  
            newPictureBox3.Image = Image.FromFile("C:\3.gif")  
            Label1.Text = "11111 the first news"  
            Label2.Text = "222222 the 2nd news"  
            label3.Text = "33333 the 3rd news"  
            newPictureBox1.Visible = True  
            newPictureBox2.Visible = True  
            newPictureBox3.Visible = True  
            newPictureBox1.Top = 20  
            newPictureBox1.Width = 43  
            newPictureBox1.Height = 48  
            newPictureBox2.Top = 20  
            newPictureBox2.Width = 43  
            newPictureBox2.Height = 48  
            newPictureBox3.Top = 20  
            newPictureBox3.Width = 43  
            newPictureBox3.Height = 48  
            newPictureBox1.Left = 40  
            Label1.Left = newPictureBox1.Left + Label1.Width  
            newPictureBox2.Left = Label1.Left + 60  
            Label2.Left = newPictureBox2.Left + Label2.Width  
            newPictureBox3.Left = Label2.Left + 60  
            label3.Left = newPictureBox3.Left + label3.Width  
            Label1.Top = 40  
            Label2.Top = 40  
            label3.Top = 40  
      
            'add control to form  
            Controls.Add(newPictureBox1)  
            Controls.Add(newPictureBox2)  
            Controls.Add(newPictureBox3)  
            Controls.Add(Label1)  
            Controls.Add(Label2)  
            Controls.Add(label3)  
               
        End Sub  
      
        Private Sub Timer1_Tick(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles Timer1.Tick  
            If Me.newPictureBox1.Location.X + newPictureBox1.Width < 0 Then  
                newPictureBox1.Location = New Point(Me.Width, newPictureBox1.Location.Y)  
            Else  
                newPictureBox1.Location = New Point(newPictureBox1.Location.X - 3, newPictureBox1.Location.Y)  
            End If  
            If Me.newPictureBox2.Location.X + newPictureBox2.Width < 0 Then  
                newPictureBox2.Location = New Point(Me.Width, newPictureBox2.Location.Y)  
            Else  
                newPictureBox2.Location = New Point(newPictureBox2.Location.X - 3, newPictureBox2.Location.Y)  
            End If  
            If Me.newPictureBox3.Location.X + newPictureBox3.Width < 0 Then  
                newPictureBox3.Location = New Point(Me.Width, newPictureBox3.Location.Y)  
            Else  
                newPictureBox3.Location = New Point(newPictureBox3.Location.X - 3, newPictureBox3.Location.Y)  
            End If  
            If Me.Label1.Location.X + Label1.Width < 0 Then  
                Label1.Location = New Point(Me.Width, Label1.Location.Y)  
            Else  
                Label1.Location = New Point(Label1.Location.X - 3, Label1.Location.Y)  
            End If  
            If Me.Label2.Location.X + Label2.Width < 0 Then  
                Label2.Location = New Point(Me.Width, Label2.Location.Y)  
            Else  
                Label2.Location = New Point(Label2.Location.X - 3, Label2.Location.Y)  
            End If  
            If Me.label3.Location.X + label3.Width < 0 Then  
                label3.Location = New Point(Me.Width, label3.Location.Y)  
            Else  
                label3.Location = New Point(label3.Location.X - 3, label3.Location.Y)  
            End If  
        End Sub  
    End Class 

      Modified On Apr-09-2018 02:27:08 AM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!