Click here to Skip to main content
15,893,401 members
Articles / Programming Languages / C#

Extend OpenFileDialog and SaveFileDialog the Easy Way

Rate me:
Please Sign up or sign in to vote.
4.82/5 (81 votes)
19 Jun 2015CPOL10 min read 1.5M   13.3K   287  
Customize OpenFileDialog and SaveFileDialog using a User Control
Imports Microsoft.VisualBasic
Imports System
Namespace CustomControls
	Partial Public Class FormMain
		''' <summary>
		''' Required designer variable.
		''' </summary>
		Private components As System.ComponentModel.IContainer = Nothing

		''' <summary>
		''' Clean up any resources being used.
		''' </summary>
		''' <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
		Protected Overrides Sub Dispose(ByVal disposing As Boolean)
			If disposing AndAlso (components IsNot Nothing) Then
				components.Dispose()
			End If
			MyBase.Dispose(disposing)
		End Sub

		#Region "Windows Form Designer generated code"

		''' <summary>
		''' Required method for Designer support - do not modify
		''' the contents of this method with the code editor.
		''' </summary>
		Private Sub InitializeComponent()
			Me._btnSelect = New System.Windows.Forms.Button()
			Me._FileSize = New System.Windows.Forms.Label()
			Me._btnSave = New System.Windows.Forms.Button()
			Me.lblFilePath = New System.Windows.Forms.Label()
			Me._btnAbout = New System.Windows.Forms.Button()
			Me._btnExtension = New System.Windows.Forms.Button()
			Me._btnSaveExt = New System.Windows.Forms.Button()
			Me.groupBox1 = New System.Windows.Forms.GroupBox()
			Me.groupBox2 = New System.Windows.Forms.GroupBox()
			Me._btnExit = New System.Windows.Forms.Button()
			Me.SuspendLayout()
			' 
			' _btnSelect
			' 
			Me._btnSelect.Location = New System.Drawing.Point(68, 17)
			Me._btnSelect.Name = "_btnSelect"
			Me._btnSelect.Size = New System.Drawing.Size(75, 23)
			Me._btnSelect.TabIndex = 24
			Me._btnSelect.Text = "Se&lect"
			Me._btnSelect.UseVisualStyleBackColor = True
'			Me._btnSelect.Click += New System.EventHandler(Me.button1_Click)
			' 
			' _FileSize
			' 
			Me._FileSize.AutoSize = True
			Me._FileSize.Location = New System.Drawing.Point(138, 446)
			Me._FileSize.Name = "_FileSize"
			Me._FileSize.Size = New System.Drawing.Size(16, 13)
			Me._FileSize.TabIndex = 31
			Me._FileSize.Text = "   "
			' 
			' _btnSave
			' 
			Me._btnSave.Location = New System.Drawing.Point(311, 28)
			Me._btnSave.Name = "_btnSave"
			Me._btnSave.Size = New System.Drawing.Size(75, 23)
			Me._btnSave.TabIndex = 24
			Me._btnSave.Text = "&Save"
			Me._btnSave.UseVisualStyleBackColor = True
'			Me._btnSave.Click += New System.EventHandler(Me.button1_Click)
			' 
			' lblFilePath
			' 
			Me.lblFilePath.AutoSize = True
			Me.lblFilePath.Location = New System.Drawing.Point(12, 121)
			Me.lblFilePath.Name = "lblFilePath"
			Me.lblFilePath.Size = New System.Drawing.Size(50, 13)
			Me.lblFilePath.TabIndex = 34
			Me.lblFilePath.Text = "File path:"
			' 
			' _btnAbout
			' 
			Me._btnAbout.Location = New System.Drawing.Point(311, 151)
			Me._btnAbout.Name = "_btnAbout"
			Me._btnAbout.Size = New System.Drawing.Size(75, 23)
			Me._btnAbout.TabIndex = 35
			Me._btnAbout.Text = "&About"
			Me._btnAbout.UseVisualStyleBackColor = True
'			Me._btnAbout.Click += New System.EventHandler(Me._btnAbout_Click)
			' 
			' _btnExtension
			' 
			Me._btnExtension.Location = New System.Drawing.Point(68, 60)
			Me._btnExtension.Name = "_btnExtension"
			Me._btnExtension.Size = New System.Drawing.Size(167, 23)
			Me._btnExtension.TabIndex = 24
			Me._btnExtension.Text = "Select (&Extension method)"
			Me._btnExtension.UseVisualStyleBackColor = True
'			Me._btnExtension.Click += New System.EventHandler(Me.button1_Click)
			' 
			' _btnSaveExt
			' 
			Me._btnSaveExt.Location = New System.Drawing.Point(311, 72)
			Me._btnSaveExt.Name = "_btnSaveExt"
			Me._btnSaveExt.Size = New System.Drawing.Size(152, 23)
			Me._btnSaveExt.TabIndex = 24
			Me._btnSaveExt.Text = "S&ave(extension Method)"
			Me._btnSaveExt.UseVisualStyleBackColor = True
'			Me._btnSaveExt.Click += New System.EventHandler(Me.button1_Click)
			' 
			' groupBox1
			' 
			Me.groupBox1.Location = New System.Drawing.Point(35, 8)
			Me.groupBox1.Name = "groupBox1"
			Me.groupBox1.Size = New System.Drawing.Size(200, 100)
			Me.groupBox1.TabIndex = 36
			Me.groupBox1.TabStop = False
			' 
			' groupBox2
			' 
			Me.groupBox2.Location = New System.Drawing.Point(278, 8)
			Me.groupBox2.Name = "groupBox2"
			Me.groupBox2.Size = New System.Drawing.Size(200, 100)
			Me.groupBox2.TabIndex = 37
			Me.groupBox2.TabStop = False
			' 
			' _btnExit
			' 
			Me._btnExit.Location = New System.Drawing.Point(68, 151)
			Me._btnExit.Name = "_btnExit"
			Me._btnExit.Size = New System.Drawing.Size(75, 23)
			Me._btnExit.TabIndex = 38
			Me._btnExit.Text = "E&xit"
			Me._btnExit.UseVisualStyleBackColor = True
'			Me._btnExit.Click += New System.EventHandler(Me.button1_Click)
			' 
			' FormMain
			' 
			Me.AutoScaleDimensions = New System.Drawing.SizeF(6F, 13F)
			Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
			Me.ClientSize = New System.Drawing.Size(500, 186)
			Me.Controls.Add(Me._btnExit)
			Me.Controls.Add(Me._btnAbout)
			Me.Controls.Add(Me.lblFilePath)
			Me.Controls.Add(Me._FileSize)
			Me.Controls.Add(Me._btnSaveExt)
			Me.Controls.Add(Me._btnSave)
			Me.Controls.Add(Me._btnExtension)
			Me.Controls.Add(Me._btnSelect)
			Me.Controls.Add(Me.groupBox1)
			Me.Controls.Add(Me.groupBox2)
			Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
			Me.MaximizeBox = False
			Me.MinimizeBox = False
			Me.Name = "FormMain"
			Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
			Me.Text = "Click To Open a Dialog"
			Me.ResumeLayout(False)
			Me.PerformLayout()

		End Sub

		#End Region

		Private WithEvents _btnSelect As System.Windows.Forms.Button
		Private _FileSize As System.Windows.Forms.Label
		Private WithEvents _btnSave As System.Windows.Forms.Button
		Private lblFilePath As System.Windows.Forms.Label
		Private WithEvents _btnAbout As System.Windows.Forms.Button
		Private WithEvents _btnExtension As System.Windows.Forms.Button
		Private WithEvents _btnSaveExt As System.Windows.Forms.Button
		Private groupBox1 As System.Windows.Forms.GroupBox
		Private groupBox2 As System.Windows.Forms.GroupBox
		Private WithEvents _btnExit As System.Windows.Forms.Button


	End Class
End Namespace

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United States United States
Decebal Mihailescu is a software engineer with interest in .Net, C# and C++.

Comments and Discussions