| | |
Browse Control in C#
Thread Solved |
•
•
Join Date: Nov 2007
Posts: 85
Reputation:
Solved Threads: 0
hi there,
is there a browse control in C# windows application form ,
if so , plz, how can I add it to my toolBox and how can I use it to allow the user to browse any file she wants,
if not how can I implement the idea og browsing ( that the user choose a file and then I do what ever I need with its path)
urgent help is neede pleease
Thanks in advance
is there a browse control in C# windows application form ,
if so , plz, how can I add it to my toolBox and how can I use it to allow the user to browse any file she wants,
if not how can I implement the idea og browsing ( that the user choose a file and then I do what ever I need with its path)
urgent help is neede pleease
Thanks in advance
there's always something to learn
Ahhh Codeproject - love that site Jerry! I think (not tested it) this will work:
Hope that helps! Just put that in the event handler of the button you wish to be the browse button!
C# Syntax (Toggle Plain Text)
OpenFileDialog op = new OpenFileDialog(); op.ShowDialog();
Last edited by majestic0110; May 20th, 2008 at 3:46 pm. Reason: added code
Computers are man's attempt at designing a cat: It does whatever it wants, whenever it wants, and rarely ever at the right time.
•
•
Join Date: Sep 2008
Posts: 1
Reputation:
Solved Threads: 1
C# Syntax (Toggle Plain Text)
namespace GenerateHtmlNamespace { using System; using System.Drawing; using System.ComponentModel; using System.WinForms; using System.IO; public class MakeHtml : Form { DialogResult s; private System.ComponentModel.Container components; private StatusBar statusBar1; private Label label1; private Label label2; private TextBox textBox1; private TextBox textBox2; private Button button1; private Button button2; private Button button3; private Button button4; private Button button5; private GroupBox groupBox1; private GroupBox groupBox2; private string nm = ""; private string filename = ""; private StreamWriter writer = null; public MakeHtml() { InitializeComponent(); } public override void Dispose() { base.Dispose(); components.Dispose(); } public static void Main(string[] args) { Application.Run(new MakeHtml()); } private void InitializeComponent() { this.components = new System.ComponentModel.Container(); this.label1 = new Label(); this.label2 = new Label(); this.textBox1 = new TextBox(); this.textBox2 = new TextBox(); this.groupBox1 = new GroupBox(); this.groupBox2 = new GroupBox(); this.button1 = new Button(); this.button2 = new Button(); this.button3 = new Button(); this.button4 = new Button(); this.button5 = new Button(); this.statusBar1 = new StatusBar(); label1.Location = new System.Drawing.Point(88, 56); label1.Text = "Enter Your Name"; label1.Size = new System.Drawing.Size(192, 32); label1.BorderStyle = System.WinForms.BorderStyle.FixedSingle; label1.ForeColor = System.Drawing.SystemColors.ActiveCaption; label1.Font = new System.Drawing.Font("Comic Sans MS", 12f); label1.BackColor = System.Drawing.Color.Bisque; label1.TextAlign = System.WinForms.HorizontalAlignment.Right; label2.Location = new System.Drawing.Point(88, 104); label2.Text = "Enter HTML File Name "; label2.Size = new System.Drawing.Size(192, 32); label2.BorderStyle = System.WinForms.BorderStyle.FixedSingle; label2.ForeColor = System.Drawing.SystemColors.ActiveCaption; label2.Font = new System.Drawing.Font("Comic Sans MS", 12f); label2.BackColor = System.Drawing.Color.Bisque; label2.TextAlign = System.WinForms.HorizontalAlignment.Right; textBox1.Location = new System.Drawing.Point(296, 56); textBox1.ForeColor = System.Drawing.SystemColors.ActiveCaption; textBox1.Font = new System.Drawing.Font("Lucida Sans Unicode", 12f); textBox1.Text = "Subhagata"; textBox1.Size = new System.Drawing.Size(208, 32); textBox1.BackColor = System.Drawing.Color.NavajoWhite; textBox2.Location = new System.Drawing.Point(296, 104); textBox2.ForeColor = System.Drawing.SystemColors.ActiveCaption; textBox2.Font = new System.Drawing.Font("Lucida Sans Unicode", 12f); textBox2.Text = "myFile.html"; textBox2.Size = new System.Drawing.Size(208, 32); textBox2.BackColor = System.Drawing.Color.NavajoWhite; button1.Location = new System.Drawing.Point(144, 280); button1.ForeColor = System.Drawing.SystemColors.ControlDarkDark; button1.BackColor = System.Drawing.SystemColors.ControlLight; button1.Size = new System.Drawing.Size(112, 40); button1.Font = new System.Drawing.Font("Times New Roman", 12f); button1.Text = "Make HTML"; button1.Click += new System.EventHandler(button1_Click); button2.Location = new System.Drawing.Point(256, 280); button2.ForeColor = System.Drawing.SystemColors.ControlDarkDark; button2.BackColor = System.Drawing.SystemColors.ControlLight; button2.Size = new System.Drawing.Size(112, 40); button2.Font = new System.Drawing.Font("Times New Roman", 12f); button2.Text = "Clear"; button2.Click += new System.EventHandler(button2_Click); button3.Location = new System.Drawing.Point(368, 280); button3.ForeColor = System.Drawing.SystemColors.ControlDarkDark; button3.BackColor = System.Drawing.SystemColors.ControlLight; button3.Size = new System.Drawing.Size(104, 40); button3.Font = new System.Drawing.Font("Times New Roman", 12f); button3.Text = "Exit"; button3.Click += new System.EventHandler(button3_Click); button4.Location = new System.Drawing.Point(184, 184); button4.ForeColor = System.Drawing.Color.DarkSlateGray; button4.BackColor = System.Drawing.SystemColors.ControlLight; button4.Size = new System.Drawing.Size(120, 32); button4.Font = new System.Drawing.Font("Times New Roman", 8f); button4.Text = "Change Window Color"; button4.Click += new System.EventHandler(button4_Click); button5.Location = new System.Drawing.Point(304, 184); button5.ForeColor = System.Drawing.Color.DarkSlateGray; button5.BackColor = System.Drawing.SystemColors.ControlLight; button5.Size = new System.Drawing.Size(120, 32); button5.Font = new System.Drawing.Font("Times New Roman", 8f); button5.Text = "Change Label Color"; button5.Click += new System.EventHandler(button5_Click); groupBox1.Location = new Point(96, 256); groupBox1.Text = "Action"; groupBox1.Size = new Size(416, 88); groupBox2.Location = new Point(85, 168); groupBox2.Text = "Customize Window Settings"; groupBox2.Size = new Size(432, 64); statusBar1.Location = new Point(0, 200); statusBar1.Size = new Size(200, 16); statusBar1.Text = "Enter Details"; this.Text = "MakeHtml"; this.Cursor = Cursors.PanNW; this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.BackColor = System.Drawing.SystemColors.GrayText; this.ClientSize = new System.Drawing.Size(592, 485); this.StartPosition = FormStartPosition.CenterScreen; this.Controls.Add(label1); this.Controls.Add(label2); this.Controls.Add(textBox1); this.Controls.Add(textBox2); this.Controls.Add(button1); this.Controls.Add(button2); this.Controls.Add(button3); this.Controls.Add(button4); this.Controls.Add(button5); this.Controls.Add(groupBox1); this.Controls.Add(groupBox2); this.Controls.Add(statusBar1); } protected void button1_Click(object sender, System.EventArgs e) { nm = textBox1.Text.Trim(); filename = textBox2.Text.Trim(); if((textBox1.Text == "") || (textBox2.Text == "")) { statusBar1.Text = "Please enter the required details."; textBox1.Focus(); } else { if(GenerateCode()) { statusBar1.Text = "Html code generated to file "+filename; } else { statusBar1.Text = "Error"; } } } protected void button2_Click(object sender, System.EventArgs e) { textBox1.Text = ""; textBox2.Text = ""; statusBar1.Text = "Cleared All"; } protected void button3_Click(object sender, System.EventArgs e) { this.Close(); } protected void button4_Click(object sender, System.EventArgs e) { ColorDialog colorDialog1 = new ColorDialog(); colorDialog1.AllowFullOpen=false; colorDialog1.ShowDialog(); Color objColor = colorDialog1.Color; this.BackColor=objColor; } protected void button5_Click(object sender, System.EventArgs e) { ColorDialog colorDialog1 = new ColorDialog(); colorDialog1.AllowFullOpen=false; colorDialog1.ShowDialog(); Color objColor = colorDialog1.Color; label1.ForeColor=objColor; label2.ForeColor=objColor; } private bool GenerateCode() { File f = new File(filename); if(f.Exists) { s=MessageBox.Show("This fils already exists. Do you want to delete it ???" , "Worning" , MessageBox.YesNo | MessageBox.IconExclamation); if(String.Format("{0}" , s) == "Yes") { f.Delete(); } else { s=MessageBox.Show("Enter a different file name." , "Worning"); textBox2.Focus(); } } FileStream outputfile = null; try { outputfile = new FileStream(filename,FileMode.OpenOrCreate, FileAccess.Write); writer = new StreamWriter(outputfile); writer.BaseStream.Seek(0, SeekOrigin.End); DoWrite ("<HTML>"); DoWrite ("<HEAD>"); DoWrite ("<TITLE>"); DoWrite ("This HTML file is create in C#"); DoWrite ("</TITLE>"); DoWrite ("</HEAD>"); DoWrite ("<BODY BGCOLOR='Tan'>"); DoWrite ("<CENTER>"); DoWrite ("<BR><BR><H2>Hello " + nm + "</H2>"); DoWrite ("<BR><H4><A HREF='http://www.csharphelp.com'>www.csharphelp.com</A></H4>"); DoWrite ("</CENTER>"); DoWrite ("</BODY>"); DoWrite ("</HTML>"); writer.Close(); } catch(Exception ex) { Console.WriteLine("Exception GenerateCode = "+ex); statusBar1.Text = "Error"; outputfile = null; writer = null; return false; } return true; } private void DoWrite (String line) { writer.WriteLine(line); writer.Flush(); } } }
Last edited by cscgal; Sep 15th, 2008 at 11:18 am. Reason: Added code tags
•
•
Join Date: Jan 2009
Posts: 3
Reputation:
Solved Threads: 1
FileView Control from Shell MegaPack http://www.ssware.com/megapack.htm is worth a look - it can be put in your windows forms and allows users to browse for files/folders
![]() |
Similar Threads
- Win XP themes after system restore (Windows NT / 2000 / XP)
- C#ASP.Net: how to browse the folder list on Server? (C#)
- Help with Browse (Visual Basic 4 / 5 / 6)
- connected to the web but cant browse (Web Browsers)
- Help! Can't browse, use control panel or Explorer (Viruses, Spyware and other Nasties)
- Client comp. can't browse other site using PPPoE Broad Band Connection (Web Browsers)
- XP Can not browse workgroup (Networking Hardware Configuration)
Other Threads in the C# Forum
- Previous Thread: Object reference not set to an instance of an object.
- Next Thread: file browser
Views: 4322 | Replies: 6
| Thread Tools | Search this Thread |
Tag cloud for C#
.net 2d access algorithm application array asp.net bitmap box button c# chat check checkbox class client color combobox control conversion csharp custom database datagrid datagridview dataset datetime degrees deployment drawing enum excel file files form format forms function gcd gdi+ graphics grid http httpwebrequest image index input interface java list listbox login mandelbrot math mysql networking notepad operator path pda picturebox pixelinversion prime print programming regex remote remoting resource resourcefile save saving search serialization server sleep socket sounds sql statistics string tcp text textbox thread time timer treeview update usercontrol validation view visual visualstudio webbrowser webcam windows winforms wpf xml






