掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
表示だけファイル名にするには? (ID:118548)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
おせっかいかも知れませんがサンプルを作ってみました。 Option Strict On Public Class Form1 Inherits System.Windows.Forms.Form #Region " Windows フォーム デザイナで生成されたコード " Public Sub New() MyBase.New() ' この呼び出しは Windows フォーム デザイナで必要です。 InitializeComponent() ' InitializeComponent() 呼び出しの後に初期化を追加します。 End Sub ' Form は、コンポーネント一覧に後処理を実行するために dispose をオーバーライドします。 Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub ' Windows フォーム デザイナで必要です。 Private components As System.ComponentModel.IContainer ' メモ : 以下のプロシージャは、Windows フォーム デザイナで必要です。 'Windows フォーム デザイナを使って変更してください。 ' コード エディタを使って変更しないでください。 Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem Friend WithEvents MenuItem2 As System.Windows.Forms.MenuItem Friend WithEvents MenuItem3 As System.Windows.Forms.MenuItem Friend WithEvents MenuItem4 As System.Windows.Forms.MenuItem Friend WithEvents FolderBrowserDialog1 As System.Windows.Forms.FolderBrowserDialog <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() Me.MainMenu1 = New System.Windows.Forms.MainMenu Me.MenuItem1 = New System.Windows.Forms.MenuItem Me.MenuItem3 = New System.Windows.Forms.MenuItem Me.MenuItem4 = New System.Windows.Forms.MenuItem Me.MenuItem2 = New System.Windows.Forms.MenuItem Me.FolderBrowserDialog1 = New System.Windows.Forms.FolderBrowserDialog ' 'MainMenu1 ' Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem1}) ' 'MenuItem1 ' Me.MenuItem1.Index = 0 Me.MenuItem1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem2, Me.MenuItem3, Me.MenuItem4}) Me.MenuItem1.Text = "File(&F)" ' 'MenuItem2 ' Me.MenuItem2.Index = 0 Me.MenuItem2.Text = "Select Folder(&S)" ' 'MenuItem3 ' Me.MenuItem3.Index = 1 Me.MenuItem3.Text = "-" ' 'MenuItem4 ' Me.MenuItem4.Index = 2 Me.MenuItem4.Text = "Close(&X)" ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 12) Me.ClientSize = New System.Drawing.Size(292, 273) Me.Menu = Me.MainMenu1 Me.Name = "Form1" Me.Text = "Form1" End Sub #End Region Public Sub CreateMenu(ByRef ParentMenu As MyMenuItem) Dim addMenu As MyMenuItem = Nothing 'サブディレクトリをメニューに追加 For Each subDir As String In System.IO.Directory.GetDirectories(ParentMenu.FullPath) addMenu = New MyMenuItem addMenu.FullPath = subDir 'ディレクトリはイベントハンドラーはいらない? CreateMenu(addMenu) 'サブディレクトリ内のフォルダ及びファイルをメニューに追加する再帰処理 ParentMenu.MenuItems.Add(addMenu) Next For Each dirFile As String In System.IO.Directory.GetFiles(ParentMenu.FullPath) addMenu = New MyMenuItem addMenu.FullPath = dirFile AddHandler addMenu.Click, AddressOf addPath_Click ParentMenu.MenuItems.Add(addMenu) Next End Sub '追加したメニューのイベントハンドラー Private Sub addPath_Click(ByVal sender As Object, ByVal e As System.EventArgs) '選択されたファイルのフルパスの表示 MsgBox(CType(sender, MyMenuItem).FullPath) End Sub 'SelectFolderの処理 Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.Click FolderBrowserDialog1.SelectedPath = "" FolderBrowserDialog1.ShowDialog() If FolderBrowserDialog1.SelectedPath <> "" Then Dim TopMenu As New MyMenuItem TopMenu.FullPath = FolderBrowserDialog1.SelectedPath CreateMenu(TopMenu) MainMenu1.MenuItems.Add(TopMenu) End If End Sub 'Closeメニュー Private Sub MenuItem4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem4.Click Me.Close() End Sub End Class 'MenuItemの派生クラス Public Class MyMenuItem Inherits System.Windows.Forms.MenuItem Private m_FullPath As String Public Property FullPath() As String Get Return m_FullPath End Get Set(ByVal Value As String) 'フルパスをセットしたときはTextの内容をファイル名(拡張子無し)にする m_FullPath = Value Me.Text = System.IO.Path.GetFileNameWithoutExtension(Value) End Set End Property End Class
←解決時は質問者本人がここをチェックしてください。
戻る
掲示板システム
Copyright 2020 Takeshi Okamoto All Rights Reserved.