TO SCROLL A TEXT INSIDE PICTURE BOX

Madhu Mitha

Total Post:31

Points:217
Posted by  Madhu Mitha
VB.Net 
 906  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

    1. try below lines of code:

    2. Imports System.IO  
    3. Imports System.Drawing  
    4. Public Class Form1  
    5.     Private WithEvents Label1 As New System.Windows.Forms.Label  
    6.     Private WithEvents Label2 As New System.Windows.Forms.Label  
    7.     Private WithEvents label3 As New System.Windows.Forms.Label  
    8.     Private WithEvents newPictureBox1 As New System.Windows.Forms.PictureBox  
    9.     Private WithEvents newPictureBox2 As New System.Windows.Forms.PictureBox  
    10.     Private WithEvents newPictureBox3 As New System.Windows.Forms.PictureBox  
    11.           
    12.     Private Labels() As Label  
    13.     Private newPictureBoxs() As PictureBox  
    14.   
    15.     Dim x As Integer  
    16.   
    17.   
    18.     Dim newPictureBox As New PictureBox  
    19.   
    20.   
    21.     Private Sub Form1_Load(ByVal sender As ObjectByVal e As System.EventArgs) Handles MyBase.Load  
    22.   
    23.   
    24.         newPictureBox1.Image = Image.FromFile("C:\1.gif")  
    25.         newPictureBox2.Image = Image.FromFile("C:\2.gif")  
    26.         newPictureBox3.Image = Image.FromFile("C:\3.gif")  
    27.         Label1.Text = "11111 the first news"  
    28.         Label2.Text = "222222 the 2nd news"  
    29.         label3.Text = "33333 the 3rd news"  
    30.         newPictureBox1.Visible = True  
    31.         newPictureBox2.Visible = True  
    32.         newPictureBox3.Visible = True  
    33.         newPictureBox1.Top = 20  
    34.         newPictureBox1.Width = 43  
    35.         newPictureBox1.Height = 48  
    36.         newPictureBox2.Top = 20  
    37.         newPictureBox2.Width = 43  
    38.         newPictureBox2.Height = 48  
    39.         newPictureBox3.Top = 20  
    40.         newPictureBox3.Width = 43  
    41.         newPictureBox3.Height = 48  
    42.         newPictureBox1.Left = 40  
    43.         Label1.Left = newPictureBox1.Left + Label1.Width  
    44.         newPictureBox2.Left = Label1.Left + 60  
    45.         Label2.Left = newPictureBox2.Left + Label2.Width  
    46.         newPictureBox3.Left = Label2.Left + 60  
    47.         label3.Left = newPictureBox3.Left + label3.Width  
    48.         Label1.Top = 40  
    49.         Label2.Top = 40  
    50.         label3.Top = 40  
    51.   
    52.         'add control to form  
    53.         Controls.Add(newPictureBox1)  
    54.         Controls.Add(newPictureBox2)  
    55.         Controls.Add(newPictureBox3)  
    56.         Controls.Add(Label1)  
    57.         Controls.Add(Label2)  
    58.         Controls.Add(label3)  
    59.            
    60.     End Sub  
    61.   
    62.     Private Sub Timer1_Tick(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles Timer1.Tick  
    63.         If Me.newPictureBox1.Location.X + newPictureBox1.Width < 0 Then  
    64.             newPictureBox1.Location = New Point(Me.Width, newPictureBox1.Location.Y)  
    65.         Else  
    66.             newPictureBox1.Location = New Point(newPictureBox1.Location.X - 3, newPictureBox1.Location.Y)  
    67.         End If  
    68.         If Me.newPictureBox2.Location.X + newPictureBox2.Width < 0 Then  
    69.             newPictureBox2.Location = New Point(Me.Width, newPictureBox2.Location.Y)  
    70.         Else  
    71.             newPictureBox2.Location = New Point(newPictureBox2.Location.X - 3, newPictureBox2.Location.Y)  
    72.         End If  
    73.         If Me.newPictureBox3.Location.X + newPictureBox3.Width < 0 Then  
    74.             newPictureBox3.Location = New Point(Me.Width, newPictureBox3.Location.Y)  
    75.         Else  
    76.             newPictureBox3.Location = New Point(newPictureBox3.Location.X - 3, newPictureBox3.Location.Y)  
    77.         End If  
    78.         If Me.Label1.Location.X + Label1.Width < 0 Then  
    79.             Label1.Location = New Point(Me.Width, Label1.Location.Y)  
    80.         Else  
    81.             Label1.Location = New Point(Label1.Location.X - 3, Label1.Location.Y)  
    82.         End If  
    83.         If Me.Label2.Location.X + Label2.Width < 0 Then  
    84.             Label2.Location = New Point(Me.Width, Label2.Location.Y)  
    85.         Else  
    86.             Label2.Location = New Point(Label2.Location.X - 3, Label2.Location.Y)  
    87.         End If  
    88.         If Me.label3.Location.X + label3.Width < 0 Then  
    89.             label3.Location = New Point(Me.Width, label3.Location.Y)  
    90.         Else  
    91.             label3.Location = New Point(label3.Location.X - 3, label3.Location.Y)  
    92.         End If  
    93.     End Sub  
    94. End Class 

      Modified On Mar-22-2015 03:16:57 AM

Answer

NEWSLETTER

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