Академический Документы
Профессиональный Документы
Культура Документы
namespace SampleNamespace
{
class SampleClass{}
interface SampleInterface{}
struct SampleStruct{}
enum SampleEnum{a,b}
delegate void SampleDelegate(int i);
namespace SampleNamespace.Nested
{
class SampleClass2{}
}
}
Within a namespace, you can declare one or more of the following types:
another namespace
class
interface
struct
enum
delegate
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
namespaceMy_Namespaces
{
namespaceInner
{
classProgram
{
public static voidmyMessage()
{
Console.ReadLine("Message from Inner
Namespace");}
}
}
classNamespaceCall
{
public static voidmain(string[] args)
{
Inner.Program.myMessage();
Console.ReadLine();
}
}
}
Q2. What are properties and methods of List Box. Using example explain
how we use them?
Ans. The ListBox control is used to provide a list of items from which the
user may select one or more items. If a list box contains more items than
can be displayed at one time, a vertical scroll bar is automatically added.
Useful Properties
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication11
{
public partial class Form1 : Form
{
List<string> _items = new List<string>(); // <-- Add this
public Form1()
{
InitializeComponent();
listBox1.DataSource = _items;
}
}
}
Description of the C# code. The code simply has a List of strings at the
class level. This is a good place to store the lines you want to show in
your ListBox. In the constructor, we add three elements to the List.
Description of the DataSource property. At the final point in the
constructor, we assign the DataSource from the listBox1 to the new List.
Now, run the program and you will see the three strings in your ListBox.
Use Button controls
Go back to your Designer window in Visual Studio where you see the
image of the Form. Select the buttons and then add the text "Add" and
"Remove" to their Text properties in the Properties pane. Run your
program again and you will see this:
Q4. What are properties of Date Time Picker. To which library they belong
and program to use them?
Properties Comments
Format A DateTimePickerFormat value that specifies if the format is short or
long. Defaults to long.
MaxDateTime A read-only DateTime object that indicates the maximum date
supported by the control.
MinDateTime A read-only DateTime object that indicates the minimum date
supported by the control.
Text A string object that represents the selected date.
Value A DateTime object that represents the selected date.
Events Comments
CloseUp The popup calendar was dismissed.
DropDown The popup calendar was displayed.
ValueChanged The Value property has changed (user selected a new date).
dateTimePicker1.MaxDate = DateTime.Today;
dateTimePicker1.ShowCheckBox = true;
dateTimePicker1.ShowUpDown = true;
Ans. he Common Dialog Box Library contains a set of dialog boxes for
performing common application tasks, such as opening files, choosing color
values, and printing documents. The common dialog boxes allow you to
implement a consistent approach to your application's user interface. This
reduces the amount of effort that users spend in learning user interface
behavior for your application.
Name Description
Common Dialog Box Types
Discusses the different dialog boxes.
Common Dialog Box
Initialization Flags Discusses how flags are used to modify the behavior and
appearance of a common dialog box.
Customizing Common
Dialog Boxes Discusses how to use common dialog boxes.
usingSystem.Text;
dialog.RootFolder = Environment.SpecialFolder.Desktop;
dialog.SelectedPath = Environment.CurrentDirectory;
dialog.ShowNewFolderButton = true;
if(dialog.ShowDialog() == DialogResult.OK)
MessageBox.Show(dialog.SelectedPath);
}