VB.Net by API/System/My
Содержание
- 1 My.Application.ChangeCulture
- 2 My.Application.Info.CompanyName
- 3 My.Application.Info.Copyright
- 4 My.Application.Info.Description
- 5 My.Application.Info.DirectoryPath
- 6 My.Application.Info.Trademark
- 7 My.Application.Info.Version
- 8 My.Application.Log.DefaultFileLogWriter.FullLogFileName
- 9 My.Computer.Audio.Play
- 10 My.Computer.Clipboard.Clear
- 11 My.Computer.Clipboard.ContainText
- 12 My.Computer.Clipboard.GetText
- 13 My.Computer.Clipboard.SetDataObject
- 14 My.Computer.FileSystem
- 15 My.Computer.FileSystem.CombinePath
- 16 My.Computer.FileSystem.CreateDirectory
- 17 My.Computer.FileSystem.CurrentDirectory
- 18 My.Computer.FileSystem.DirectoryExists
- 19 My.Computer.FileSystem.Drives
- 20 My.Computer.FileSystem.FileExists
- 21 My.Computer.FileSystem.FindInFiles
- 22 My.Computer.FileSystem.GetDirectories
- 23 My.Computer.FileSystem.GetName
- 24 My.Computer.FileSystem.GetParentPath
- 25 My.Computer.FileSystem.OpenTextFileWriter
- 26 My.Computer.FileSystem.SpecialDirectories.AllUsersApplicationData
- 27 My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData
- 28 My.Computer.FileSystem.SpecialDirectories.Desktop
- 29 My.Computer.FileSystem.SpecialDirectories.MyDocuments
- 30 My.Computer.FileSystem.SpecialDirectories.MyMusic
- 31 My.Computer.FileSystem.SpecialDirectories.MyPictures
- 32 My.Computer.FileSystem.SpecialDirectories.Programs
- 33 My.Computer.FileSystem.SpecialDirectories.Temp
- 34 My.Computer.FileSystem.WriteAllText
- 35 My.Computer.Ports.SerialPortNames
- 36 My.Computer.Screen.Bounds
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