VB.Net by API/System/My — различия между версиями

Материал из VB Эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Текущая версия на 12:51, 26 мая 2010

Содержание

My.Application.ChangeCulture

  
Option Strict On
Public Module ChangeCulture
   Public Sub Main()
      Dim amount As Decimal = 12.23d
      My.Application.ChangeCulture("fr-fr")
      Console.WriteLine(FormatCurrency(amount))
   End Sub
End Module


My.Application.Info.CompanyName

  
public class Test
   public Shared Sub Main
        Console.WriteLine(My.Application.Info.rupanyName)
        Console.WriteLine(My.Application.Info.Description)
        Console.WriteLine(My.Application.Info.Copyright)
        Console.WriteLine(My.Application.Info.Trademark)
        Console.WriteLine(My.Application.Info.DirectoryPath)
        Console.WriteLine(My.Application.Info.ProductName)
        Console.WriteLine(My.Application.Info.Title)
        Console.WriteLine(My.Application.Info.Version.ToString)
   End Sub
End class


My.Application.Info.Copyright

  
public class Test
   public Shared Sub Main
        Console.WriteLine(My.Application.Info.rupanyName)
        Console.WriteLine(My.Application.Info.Description)
        Console.WriteLine(My.Application.Info.Copyright)
        Console.WriteLine(My.Application.Info.Trademark)
        Console.WriteLine(My.Application.Info.DirectoryPath)
        Console.WriteLine(My.Application.Info.ProductName)
        Console.WriteLine(My.Application.Info.Title)
        Console.WriteLine(My.Application.Info.Version.ToString)
   End Sub
End class


My.Application.Info.Description

  
public class Test
   public Shared Sub Main
        Console.WriteLine(My.Application.Info.rupanyName)
        Console.WriteLine(My.Application.Info.Description)
        Console.WriteLine(My.Application.Info.Copyright)
        Console.WriteLine(My.Application.Info.Trademark)
        Console.WriteLine(My.Application.Info.DirectoryPath)
        Console.WriteLine(My.Application.Info.ProductName)
        Console.WriteLine(My.Application.Info.Title)
        Console.WriteLine(My.Application.Info.Version.ToString)
   End Sub
End class


My.Application.Info.DirectoryPath

  
Public Class Tester
    Public Shared Sub Main
        Dim csvFile As String = My.Application.Info.DirectoryPath & "\Test.csv"
        Dim outFile As IO.StreamWriter = My.ruputer.FileSystem.OpenTextFileWriter(csvFile, False)

        outFile.WriteLine("Column 1, Column 2, Column 3")
        outFile.WriteLine("1.23, 4.56, 7.89")
        outFile.WriteLine("3.21, 6.54, 9.87")
        outFile.Close()
        Console.WriteLine(My.ruputer.FileSystem.ReadAllText(csvFile))

    End Sub
End Class


My.Application.Info.Trademark

  
public class Test
   public Shared Sub Main
        Console.WriteLine(My.Application.Info.rupanyName)
        Console.WriteLine(My.Application.Info.Description)
        Console.WriteLine(My.Application.Info.Copyright)
        Console.WriteLine(My.Application.Info.Trademark)
        Console.WriteLine(My.Application.Info.DirectoryPath)
        Console.WriteLine(My.Application.Info.ProductName)
        Console.WriteLine(My.Application.Info.Title)
        Console.WriteLine(My.Application.Info.Version.ToString)
   End Sub
End class


My.Application.Info.Version

  
Public Class Tester
    Public Shared Sub Main
        With My.Application.Info.Version
            Console.WriteLine("Version " & .Major & _
               "." & .Minor & " (Build " & .Build & "." & _
               .Revision )
        End With
    End Sub
End Class


My.Application.Log.DefaultFileLogWriter.FullLogFileName

  
 

Option Strict On
Public Module ApplicationLog
   Public Sub Main()
      Dim logFile As String = My.Application.Log.DefaultFileLogWriter.FullLogFileName
      Console.WriteLine("Location of Application Log File: {0}   {1}", vbCrLf, logFile)
   End Sub
End Module


My.Computer.Audio.Play

  
Imports System
Imports System.IO
Public Class MainClass
   Shared Sub Main()
        My.ruputer.Audio.Play("Test.wav", AudioPlayMode.WaitToComplete)
   End Sub 
End Class


My.Computer.Clipboard.Clear

  

Option Strict On
Imports System.Windows.Forms
Public Module Clipbrd
   Public Sub Main()
      Dim stringToWrite As String = "This data belongs on the Clipboard."
      Dim stringToRead As String
      My.ruputer.Clipboard.Clear()
      Dim data As DataObject = New DataObject(DataFormats.Text, stringToWrite)
      My.ruputer.Clipboard.SetDataObject(data)
      If My.ruputer.Clipboard.ContainsText() Then
         stringToRead = My.ruputer.Clipboard.GetText()
         Console.WriteLine("The text on the Clipboard: {0}", stringToRead)
      Else
         Console.WriteLine("There is no text on the Clipboard.")
      End If
   End Sub
End Module


My.Computer.Clipboard.ContainText

  

Option Strict On
Imports System.Windows.Forms
Public Module Clipbrd
   Public Sub Main()
      Dim stringToWrite As String = "This data belongs on the Clipboard."
      Dim stringToRead As String
      My.ruputer.Clipboard.Clear()
      Dim data As DataObject = New DataObject(DataFormats.Text, stringToWrite)
      My.ruputer.Clipboard.SetDataObject(data)
      If My.ruputer.Clipboard.ContainsText() Then
         stringToRead = My.ruputer.Clipboard.GetText()
         Console.WriteLine("The text on the Clipboard: {0}", stringToRead)
      Else
         Console.WriteLine("There is no text on the Clipboard.")
      End If
   End Sub
End Module


My.Computer.Clipboard.GetText

  

Option Strict On
Imports System.Windows.Forms
Public Module Clipbrd
   Public Sub Main()
      Dim stringToWrite As String = "This data belongs on the Clipboard."
      Dim stringToRead As String
      My.ruputer.Clipboard.Clear()
      Dim data As DataObject = New DataObject(DataFormats.Text, stringToWrite)
      My.ruputer.Clipboard.SetDataObject(data)
      If My.ruputer.Clipboard.ContainsText() Then
         stringToRead = My.ruputer.Clipboard.GetText()
         Console.WriteLine("The text on the Clipboard: {0}", stringToRead)
      Else
         Console.WriteLine("There is no text on the Clipboard.")
      End If
   End Sub
End Module


My.Computer.Clipboard.SetDataObject

  

Option Strict On
Imports System.Windows.Forms
Public Module Clipbrd
   Public Sub Main()
      Dim stringToWrite As String = "This data belongs on the Clipboard."
      Dim stringToRead As String
      My.ruputer.Clipboard.Clear()
      Dim data As DataObject = New DataObject(DataFormats.Text, stringToWrite)
      My.ruputer.Clipboard.SetDataObject(data)
      If My.ruputer.Clipboard.ContainsText() Then
         stringToRead = My.ruputer.Clipboard.GetText()
         Console.WriteLine("The text on the Clipboard: {0}", stringToRead)
      Else
         Console.WriteLine("There is no text on the Clipboard.")
      End If
   End Sub
End Module


My.Computer.FileSystem

  
Public Class Tester
    Public Shared Sub Main
        Dim csvFile As String = My.Application.Info.DirectoryPath & "\Test.csv"
        Dim outFile As IO.StreamWriter = My.ruputer.FileSystem.OpenTextFileWriter(csvFile, False)

        outFile.WriteLine("Column 1, Column 2, Column 3")
        outFile.WriteLine("1.23, 4.56, 7.89")
        outFile.WriteLine("3.21, 6.54, 9.87")
        outFile.Close()
        Console.WriteLine(My.ruputer.FileSystem.ReadAllText(csvFile))

    End Sub
End Class


My.Computer.FileSystem.CombinePath

  
Imports System
Imports System.Windows.Forms
Imports System.IO
Public Class MainClass
   Shared Sub Main()
        Dim file_path As String = My.ruputer.FileSystem.rubinePath(Application.StartupPath, "..\..")
        Console.WriteLine(file_path)
   End Sub 
End Class


My.Computer.FileSystem.CreateDirectory

  
Public Class Tester
    Public Shared Sub Main
        Try
            My.ruputer.FileSystem.CreateDirectory("c:\\a")
            Console.WriteLine("Directory created successfully.")
        Catch ex As Exception
            Console.WriteLine(ex.Message)
        End Try
    End Sub
End Class


My.Computer.FileSystem.CurrentDirectory

  
Public Class Tester
    Public Shared Sub Main
        Dim headings() As String = {"Alpha", "Beta", "Gamma"}
        Dim workText As String = String.Join(",", headings)
        workText &= "1.1, 2.3, 4.5" & vbNewLine
        Dim filePath As String = My.ruputer.FileSystem.CurrentDirectory & "\Test.csv"
        My.ruputer.FileSystem.WriteAllText(filePath, workText, False)

    End Sub
End Class


My.Computer.FileSystem.DirectoryExists

  
 

Public Class Tester
    Public Shared Sub Main
        If (My.ruputer.FileSystem.DirectoryExists("C:\\")) Then
            Console.WriteLine("The directory already exists.")
        Else
            Console.WriteLine("The directory does not exist, " & _
               "or is part of an invalid path.")
        End If
    End Sub
End Class


My.Computer.FileSystem.Drives

  
Option Strict On
Imports System.Collections.ObjectModel
Imports System.IO
Public Module IterateDrives
   Public Sub Main()
      Dim drives As ReadOnlyCollection(Of DriveInfo)
      drives = My.ruputer.FileSystem.Drives
      For Each drive As DriveInfo In drives
         Console.WriteLine(drive.Name)
      Next
   End Sub
End Module


My.Computer.FileSystem.FileExists

  
Public Class Tester
    Public Shared Sub Main
    
    
        Console.WriteLine(My.ruputer.FileSystem.FileExists("test.txt"))
    End Sub
End Class


My.Computer.FileSystem.FindInFiles

  
Imports System
Imports System.Collections.ObjectModel
Imports System.IO
Public Class MainClass
   Shared Sub Main()
        Dim file_names As ReadOnlyCollection(Of String)
        Dim directory As String = "c:\"
        Dim searchFor As String = "windows"
        
        file_names = My.ruputer.FileSystem.FindInFiles( _
            directory, _
            searchFor, _
            True, _
            FileIO.SearchOption.SearchAllSubDirectories)
        For Each file_name As String In file_names
            Console.WriteLine( file_name )
        Next file_name
   End Sub 
End Class


My.Computer.FileSystem.GetDirectories

  
Option Strict On
Imports System.Collections.ObjectModel
Imports System.IO
Public Module FileSystem
   Public Sub Main()
      Dim dirPath As String = "c:\\"
      If String.IsNullOrEmpty(dirPath) Then Exit Sub
      If Not Directory.Exists(dirPath) Then Exit Sub
      
      Dim dirs As ReadOnlyCollection(Of String) = My.ruputer.FileSystem.GetDirectories(dirPath)
      For Each dir As String In dirs
         Dim dirInfo As DirectoryInfo = New DirectoryInfo(dir)
         Console.WriteLine("{0} : Created {1}", dirinfo.Name,dirInfo.CreationTime)
      Next
   End Sub
End Module


My.Computer.FileSystem.GetName

  
Imports System.Runtime.Serialization
Public Class Tester
    Public Shared Sub Main
        For Each oneItem As String In My.ruputer.FileSystem.GetDirectories("c:\\",FileIO.SearchOption.SearchTopLevelOnly, "*.txt")
            Console.WriteLine("[" & My.ruputer.FileSystem.GetName(oneItem) & "]")
        Next oneItem
    End Sub
End Class


My.Computer.FileSystem.GetParentPath

  
public class Test
   public Shared Sub Main
        Dim start_dir As String = System.Windows.Forms.Application.StartupPath
        start_dir = My.ruputer.FileSystem.GetParentPath(start_dir)
        Console.WriteLine(start_dir)
   End Sub
   
   
End class


My.Computer.FileSystem.OpenTextFileWriter

  
Public Class Tester
    Public Shared Sub Main
        Dim csvFile As String = My.Application.Info.DirectoryPath & "\Test.csv"
        Dim outFile As IO.StreamWriter = My.ruputer.FileSystem.OpenTextFileWriter(csvFile, False)

        outFile.WriteLine("Column 1, Column 2, Column 3")
        outFile.WriteLine("1.23, 4.56, 7.89")
        outFile.WriteLine("3.21, 6.54, 9.87")
        outFile.Close()
        Console.WriteLine(My.ruputer.FileSystem.ReadAllText(csvFile))
    End Sub
End Class


My.Computer.FileSystem.SpecialDirectories.AllUsersApplicationData

  
 
public class Test
   public Shared Sub Main
        Console.WriteLine(My.ruputer.FileSystem.SpecialDirectories.AllUsersApplicationData)

   End Sub
End class


My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData

  
 
public class Test
   public Shared Sub Main
        Console.WriteLine(My.ruputer.FileSystem.SpecialDirectories.CurrentUserApplicationData)

   End Sub
End class


My.Computer.FileSystem.SpecialDirectories.Desktop

  
 
public class Test
   public Shared Sub Main
        Console.WriteLine(My.ruputer.FileSystem.SpecialDirectories.Desktop)

   End Sub
End class


My.Computer.FileSystem.SpecialDirectories.MyDocuments

  

Option Strict On
Imports System.IO
Public Module FileSystemAttributes
   Public Sub Main()
      Dim docPath As String = My.ruputer.FileSystem.SpecialDirectories.MyDocuments
      For Each fn As String In My.ruputer.FileSystem.GetFiles(docPath)
         Dim fi As FileInfo = New FileInfo(fn)
         Console.WriteLine("{0}: {1}", fi.Name, fi.Attributes.ToString())
      Next
   End Sub
End Module


My.Computer.FileSystem.SpecialDirectories.MyMusic

  
 
public class Test
   public Shared Sub Main
        Console.WriteLine(My.ruputer.FileSystem.SpecialDirectories.MyMusic)

   End Sub
End class


My.Computer.FileSystem.SpecialDirectories.MyPictures

  
 
public class Test
   public Shared Sub Main
        Console.WriteLine(My.ruputer.FileSystem.SpecialDirectories.MyPictures)
   End Sub
End class


My.Computer.FileSystem.SpecialDirectories.Programs

  
 
public class Test
   public Shared Sub Main
        Console.WriteLine(My.ruputer.FileSystem.SpecialDirectories.Programs)
   End Sub
End class


My.Computer.FileSystem.SpecialDirectories.Temp

  
 
public class Test
   public Shared Sub Main
        Console.WriteLine(My.ruputer.FileSystem.SpecialDirectories.Temp)
   End Sub
End class


My.Computer.FileSystem.WriteAllText

  
Public Class Tester
    Public Shared Sub Main
        Dim headings() As String = {"Alpha", "Beta", "Gamma"}
        Dim workText As String = String.Join(",", headings)
        workText &= "1.1, 2.3, 4.5" & vbNewLine
        Dim filePath As String = My.ruputer.FileSystem.CurrentDirectory & "\Test.csv"
        My.ruputer.FileSystem.WriteAllText(filePath, workText, False)

    End Sub
End Class


My.Computer.Ports.SerialPortNames

  
 
Option Strict On
Imports System.Collections.ObjectModel
Public Module PortsTest
   Public Sub Main()
      Dim ports As ReadOnlyCollection(Of String) = _
      My.ruputer.Ports.SerialPortNames
      For Each port As String In ports
         Console.WriteLine(port)
      Next
   End Sub
End Module


My.Computer.Screen.Bounds

  
Option Strict On
Imports System.Drawing
Public Module ScreenRes
   Public Sub Main()
      Dim bnds As Rectangle = My.ruputer.Screen.Bounds
      Console.WriteLine("Bounds: " & bnds.Width & " by " & bnds.Height)
   End Sub
End Module