Языки

PHP
Функции  Добавить  Пользователи  Регистрация  Вход   Ресурс  Таблица ASCII  Помощь

VB.Net


1 Building a News Ticker Using VB.Net

2 Why XML?

3 Application Basics

4 Code

5 Conclusion

Code



(Page 4 of 5 )

  • Open Visual Studio.Net
  • Select the windows application template and enter NewsTicker as its name
  • Change the name of  form1.vb to NewsTicker.vb
  • In the design view, drag the timer control and drop it on the form
  • Decrease the height of the form such that it accommodates only the news string.  In my app width = 710 and height = 70
  • Drag the context menu control and drop it on the component tray.  I use it to code an alternate method to dismiss the form when the user right clicks on the form
  • Type &Exit in the context menu item, so that it might display Exit when the user right clicks it
  • Associate the context menu by using the form’s property page
  • Switch to code view and code it as given below:


I’ve omitted form designer generated code

Imports System.Text    _used for string manipulations
Imports System.Xml     _ used for XML reading
Public Class NewsTicker
    Inherits System.Windows.Forms.Form

Dim widthX As Single
    Dim heightY As Single = 0
    Dim g As Graphics
    Dim xmlst As String      _string from the xml file
    Dim fo As Font
    Dim str As String
    Dim strwidth As SizeF    _gets the xml string_s width and height
    Dim douX As Double       _stores the xmlstring_s width     

    Private Sub NewsTicker_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        g = Me.CreateGraphics()  ‘get the graphics object of the form
        widthX = Me.Width        _ x co- ordinate or width
        _ Debug.Write(String.Format("The width is {0}", ‘CStr(Me.Width)))
        Me.loadthenews()        
        Dim gr As Graphics
        Timer1.Interval = 100
        Timer1.Start()
        fo = New Font("Times New Roman", 14, FontStyle.Bold, GraphicsUnit.Point)
        strwidth = g.MeasureString(str, fo)
        douX = strwidth.Width
    End Sub

    Private Sub loadthenews()
        Dim readXML As New XmlTextReader("G:vbappsdr ews.xml")
        While readXML.Read()
            If readXML.NodeType = XmlNodeType.Text Then
                str += "   " & readXML.Value
            End If
        End While
    End Sub
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        _Debug.Write(vbCr & strwidth.Width & vbCr)
        _Debug.Write(String.Format("widthX = {0}", CStr(widthX) & vbCr))
        g.Clear(Me.BackColor) 
        g.DrawString(str, fo, Brushes.Black, widthX, heightY)
        _ Debug.Write(String.Format("the string width is {0}", CStr(strwidth.Width)))
        If widthX <= (0 - douX) Then
            widthX = Me.Width
        Else
            widthX -= 5
        End If
    End Sub
    Private Sub NewsTicker_hover(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.MouseHover
        Timer1.Stop()
        Debug.Write(String.Format("The string width is {0}", CStr(douX)))
    End Sub
    Private Sub NewsTicker_leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.MouseLeave
        Timer1.Start()
    End Sub

    Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem1.Click
        Application.Exit()
    End Sub
End Class


1 2 3 4 5
Feasts at a Funeral

Photo of woman excavating and the words Photo Gallery

Whether the occasion is a wedding reception or another milestone in life, the feast is a time-honored ritual in which a large meal marks a significant occasion. We know that the Romans, Greeks and Vikings did it, and today it's still an active part of occasions such as birthdays, weddings and anniversaries. Now a University of Connecticut (UConn) anthropologist says there is new evidence that nearly 12,000 years ago, feasts were used to celebrate burial of the dead, bringing about the ...

More at http://www.nsf.gov/news/news_summ.jsp?cntn_id=117600&WT.mc_id=USNSF_51&WT.mc_ev=click


This is an NSF News item.

English
version


Статьи
Articles


Книги
Library


Скачать
Downloads

 © Internet, books, teachers and Rudevich Alexander brains.