:: Home

  login:         
  passwords:  

Winforms Interview Questions

Windows Forms Deployment
Windows Forms Controls
Windows Forms Data Binding
Windows Forms Datagrid
Windows Forms Docking
Windows Forms Keyboard Handling
Windows Forms Layout
Windows Forms Licensing
Windows Forms Menus
Windows Forms Mouse Handling
Windows Forms from MFC
Windows Forms from VB6
Windows Forms Patterns
Windows Forms Printing
Windows Forms Resources
Windows Form Scrolling
Windows Forms Tips
Windows Forms Common Dialogs
Windows Forms Listbox
Windows Forms ComboBox
Windows Forms Rich TextBox
Windows Forms ListView
Windows Forms TreeView
Windows Forms Button
Windows Forms TabControl
Windows Forms TextBox
Windows Forms MDI
Windows Forms Cursors
Windows Forms WebBrowser
Windows Forms PictureBox
Windows Forms Form
Windows Forms MDI
Windows Forms In IE
GDI+Bitmaps&Images
GDI+Font
GDI+Color
GDI+Brushes
GDI Drawing Tips
GDI+ from GDI
GDI Paths Regions
GDI+Pens
Interioerability WIn32
Tools Metadata Viewers
Design Time Serialization
Design Time Custom Designers
Design Time Tips
Design Time Type Editors
Vs.Net Tips
Vs.Net Debugging
Vs.Net Macros
Framework Tips General
Framework Tips Events
Framework Tips General IO
Framework Tips Strings
Framework Tips Threading
Tool Resource Editor
Design Time UI
Framework Tips CGI
Framework Tips XML

WPF Interview Qs

SilverLight Interview Qs

SAP Interview Questions

Oracle Interview Questions

PHP Interview Questions

Ajax Interview Questions

IIS 7.0

OOP Interview Questions

Ruby Interview Questions

Sql Server Interview Questions

SharePoint 2007 Questions

Microsoft Crm Questions

Windows Forms Common Dialogs

The General Winforms Interview Questions consists the most frequently asked questions in Winforms. This list of 100+ questions guage your familiarity with the Winforms platform. The q&a have been collected over a period of time from various blogs, forums and other similar Winforms sites

18.Windows Forms Common Dialogs

    18.1 How do I use the ColorDialog to pick a color?
    18.2 How do I use the FontDialog class to set a control's font?
    18.3 How do I implement a Folder Browser class?
    18.4 How can I get just the name of a file from the complete path string?
    18.5 How can I get just the extension of a file from the complete path string?
    18.6 How do I use the OpenFileDialog?
    18.7How do I specify the path for the FolderBrowser instance when it opens the first time?

18.1 How do I use the ColorDialog to pick a color?

It is straight-forward. Create an instance of the class and call its ShowDialog method.

ColorDialog colorDialog1 = new ColorDialog(); //fontDialog1.ShowColor = true; if(colorDialog1.ShowDialog() != DialogResult.Cancel ) { textBox1.ForeColor = colorDialog1.Color; } textBox1.Text = "this is a test";

18.2 How do I use the FontDialog class to set a control's font?

It is straight-forward. Create an instance of the class and call its ShowDialog method.

FontDialog fontDialog1 = new FontDialog();
fontDialog1.ShowColor = true;
if(fontDialog1.ShowDialog() != DialogResult.Cancel )
{
textBox1.Font = fontDialog1.Font ;
textBox1.ForeColor = fontDialog1.Color;
}
textBox1.Text = "this is a test";

18.3 How do I implement a Folder Browser class?

Below is a technique that uses FolderNameEditor and FolderBrowser classes to implement a solution. You can also use iterop to get a solution. Both the FolderNameEditor and FolderBrowser classes used in this solution are described in the Docs as "This type supports the .NET Framework infrastructure and is not intended to be used directly from your code."

// add a reference to System.Design.DLL
using System.Windows.Forms.Design;
.............
public class DirBrowser : FolderNameEditor
{
FolderBrowser fb = new FolderBrowser();
public string Description
{
set { _description = value; }
get { return _description; }
}
public string ReturnPath
{
get { return _returnPath; }
}
public DirBrowser() { }

public DialogResult ShowDialog()
{
fb.Description = _description;
fb.StartLocation = FolderBrowserFolder.MyComputer;
DialogResult r = fb.ShowDialog();
if (r == DialogResult.OK)
_returnPath = fb.DirectoryPath;
else
_returnPath = String.Empty;
return r;
}
private string _description = "Choose Directory";
private string _returnPath = String.Empty;
}

18.4 How can I get just the name of a file from the complete path string?

Use FileInfo. Instantiate a FileInfo object with the full path as constructor arg. Then simply call FileInfo.Name and you will get just the name of the file.

FileInfo finfo = new FileInfo(strFileName);
Console.WriteLine(finfo.Name);

18.5 How can I get just the extension of a file from the complete path string?

Use FileInfo. Instantiate a FileInfo object with the full path as constructor arg. Then simply call FileInfo.Extension and you will get just the extension of the file.

FileInfo finfo = new FileInfo(strFileName);
Console.WriteLine(finfo.Extension);

18.6 How do I use the OpenFileDialog?

using System.Text;
using System.IO;
....
private void button1_Click(object sender, System.EventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.Title = "Open text file" ;
dlg.InitialDirectory = @"c:\" ;
dlg.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*" ;
if(dlg.ShowDialog() == DialogResult.OK)
{
StreamReader sr = File.OpenText(dlg.FileName);
string s = sr.ReadLine();
StringBuilder sb = new StringBuilder();
while (s != null)
{

sb.Append(s);
s = sr.ReadLine();
}
sr.Close();
textBox1.Text = sb.ToString();
}
}

18.7 How do I specify the path for the FolderBrowser instance when it opens the first time?

In the 1.1 framework there is a SelectedPath property that will let you do this.

Copyright 2007, Megasolutions Ltd