VB.Net by API/System/My

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

Содержание

My.Application.ChangeCulture

<source lang="vbnet"> 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


 </source>


My.Application.Info.CompanyName

<source lang="vbnet"> 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


 </source>


My.Application.Info.Copyright

<source lang="vbnet"> 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


 </source>


My.Application.Info.Description

<source lang="vbnet"> 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


 </source>


My.Application.Info.DirectoryPath

<source lang="vbnet"> 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


 </source>


My.Application.Info.Trademark

<source lang="vbnet"> 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


 </source>


My.Application.Info.Version

<source lang="vbnet"> 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


 </source>


My.Application.Log.DefaultFileLogWriter.FullLogFileName

<source lang="vbnet">


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


 </source>


My.Computer.Audio.Play

<source lang="vbnet"> Imports System Imports System.IO Public Class MainClass

  Shared Sub Main()
       My.ruputer.Audio.Play("Test.wav", AudioPlayMode.WaitToComplete)
  End Sub 

End Class


 </source>


My.Computer.Clipboard.Clear

<source lang="vbnet">

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


 </source>


My.Computer.Clipboard.ContainText

<source lang="vbnet">

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


 </source>


My.Computer.Clipboard.GetText

<source lang="vbnet">

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


 </source>


My.Computer.Clipboard.SetDataObject

<source lang="vbnet">

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


 </source>


My.Computer.FileSystem

<source lang="vbnet"> 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


 </source>


My.Computer.FileSystem.CombinePath

<source lang="vbnet"> 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


 </source>


My.Computer.FileSystem.CreateDirectory

<source lang="vbnet"> 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


 </source>


My.Computer.FileSystem.CurrentDirectory

<source lang="vbnet"> 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


 </source>


My.Computer.FileSystem.DirectoryExists

<source lang="vbnet">


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


 </source>


My.Computer.FileSystem.Drives

<source lang="vbnet"> 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


 </source>


My.Computer.FileSystem.FileExists

<source lang="vbnet"> Public Class Tester

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

End Class


 </source>


My.Computer.FileSystem.FindInFiles

<source lang="vbnet"> 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


 </source>


My.Computer.FileSystem.GetDirectories

<source lang="vbnet"> 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


 </source>


My.Computer.FileSystem.GetName

<source lang="vbnet"> 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


 </source>


My.Computer.FileSystem.GetParentPath

<source lang="vbnet"> 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


 </source>


My.Computer.FileSystem.OpenTextFileWriter

<source lang="vbnet"> 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


 </source>


My.Computer.FileSystem.SpecialDirectories.AllUsersApplicationData

<source lang="vbnet">

public class Test

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

End class


 </source>


My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData

<source lang="vbnet">

public class Test

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

End class


 </source>


My.Computer.FileSystem.SpecialDirectories.Desktop

<source lang="vbnet">

public class Test

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

End class


 </source>


My.Computer.FileSystem.SpecialDirectories.MyDocuments

<source lang="vbnet">

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


 </source>


My.Computer.FileSystem.SpecialDirectories.MyMusic

<source lang="vbnet">

public class Test

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

End class


 </source>


My.Computer.FileSystem.SpecialDirectories.MyPictures

<source lang="vbnet">

public class Test

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

End class


 </source>


My.Computer.FileSystem.SpecialDirectories.Programs

<source lang="vbnet">

public class Test

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

End class


 </source>


My.Computer.FileSystem.SpecialDirectories.Temp

<source lang="vbnet">

public class Test

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

End class


 </source>


My.Computer.FileSystem.WriteAllText

<source lang="vbnet"> 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


 </source>


My.Computer.Ports.SerialPortNames

<source lang="vbnet">

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


 </source>


My.Computer.Screen.Bounds

<source lang="vbnet"> 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


 </source>