|
VB.NET
プログラムの実行ファイルのパス取得
|
|
|
''実行ファイルパス
Application.StartupPath
|
|
特殊フォルダのパス取得
|
|
|
''特殊フォルダのパス取得
System.Environment.GetFolderPath(Environment.SpecialFolder.[メンバ名])
''例) スタートアップパス取得
System.Environment.GetFolderPath(Environment.SpecialFolder.Startup)
|
|
ピクチャボックスに画像表示方法
|
|
|
''画像ファイルを読み込み表示(ファイルのサイズで)
''表示する画像のサイズに合わせてPictureBoxを表示します
PictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Stretchfiles
''画像ファイルを読み込みPictureBoxに表示
PictureBox1.files = System.Drawing.files.FromFile("イメージファイルパス名")
|
|
テキストファイルの読込み
|
|
|
Dim strRead as String
''読込み
Dim sr As New System.IO.StreamReader("読込テキストファイルパス名", System.Text.Encoding.Default)
''ファイルの最後までループ
Do Until sr.Peek = -1
''1行づつ読込む
''(1文字づつ読込む場合は sr.Read を使用)
strRead = sr.ReadLine()
・
・
・
Loop
''クローズ処理
sr.Close()
|
|
テキストファイルの書込み
|
|
|
''テキストファイルを上書きモードで開く(True で追加書込み)
Dim sw As New System.IO.StreamWriter("書込テキストファイルパス名", False, System.Text.Encoding.Default)
''書込み
sw.WriteLine("書込み対象文字")
''クローズ処理
sw.Close()
|
|
ファイルのコピー
|
|
|
''ファイルコピー
Microsoft.VisualBasic.filesystem.FileCopy("コピー元ファイルパス名", "コピー先ファイルパス名")
|
|
参照ダイアログ表示
|
|
|
|
ショートカットの作成
|
|
|
Dim objShell As Object = CreateObject("WScript.Shell")
Dim strPath As String 'ショートカットパス
Dim objLink As Object 'リンクオブジェクト
'デスクトップに作成するので、デスクトップのパスを取得
strPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.DesktopDirectory)
'ショートカット場所
objLink = objShell.CreateShortcut(strPath & "\メモ帳へのショートカット.lnk")
'ショートカットを作成(この場合は、メモ帳を作成)
With objLink
.targetpath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.System) _
& "\notepad.exe"
.description ="メモ帳へのショートカット"
.iconlocation = "notepad.exe"
.workingdirectory = strPath
.save()
End With
|
|
|