Вы находитесь на странице: 1из 20

CERTIFICATE

Homework Title / No. : __________HOMEWORK 3_________Course Code :


___1404______

Course Instructor : _____Rohit Ohri_________________ Course Tutor (if applicable)


: ____________

Date of Allotment : _____________________ Date of submission : ____28 th March,


2011_______________

Student’s Roll No._ RTB012A37______ Section No. :


____TB012________________
Declaration:
I declare that this assignment is my individual work. I have not copied from any other
student’s work or from any other source except where due acknowledgment is made
explicitly in the text, nor has any part been written for me by another person.
Student’s Signature :
_Vanita_
Evaluator’s comments:
___________________________________________________________________
__
Marks obtained : ___________ out of ______________________
Content of Homework should start from this page only:
Home Work 3

Part – A ( Attempt any three from Q1. to Q.4)


Q1. What are Namespaces? How do we use it , Give Example?

Ans. The namespace keyword is used to declare a scope. This namespace


scope lets you organize code and gives you a way to create globally unique
types:

namespace SampleNamespace
{
class SampleClass{}
interface SampleInterface{}
struct SampleStruct{}
enum SampleEnum{a,b}
delegate void SampleDelegate(int i);
namespace SampleNamespace.Nested
{
class SampleClass2{}
}
}

Whether or not you explicitly declare a namespace in a C# source file, the


compiler adds a default namespace. This unnamed namespace, sometimes
called the global namespace, is present in every file. Any identifier in the
global namespace is available for use in a named namespace.

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

 ColumnWidth - Defines the width of columns in a


multicolumn ListBox.

 IntegralHeight - Indicates whether the control should resize to


avoid showing partial items. (You may want to set this property
to false, because when set to true, the ListBox looks really jerky
if it is docked within a container and the container is resized.)

 MultiColumn - Indicates whether the ListBox supports multiple


columns.

 SelectedIndices - Gets a collection that contains the zero-based


indexes of all currently selected items in the ListBox.

 SelectedItems - Gets a collection containing the currently selected


items in the ListBox.

 SelectionMode - Defines the method in which items are selected


in the ListBox. Takes a value from the SelectionMod enumeration:

 MultiExtended - Multiple items can be selected, and the user can


use the SHIFT, CTRL, and arrow keys to make selections.
 MultiSimple - Multiple items can be selected.
 None - No items can be selected.
 One - Only one item can be selected.
Useful Methods

 ClearSelected - Unselects all items in the ListBox.

 SetSelected - Selects or clears the selection for the specified item


in a ListBox.

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();

_items.Add("One"); // <-- Add these


_items.Add("Two");
_items.Add("Three");

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?

Ans. The DateTimePicker control derives from


the System.Windows.Forms.Control class and consists of two parts: a label
that displays the selected date and a popup calendar that allows users to
select a new date.

Properties and Events

In addition to the properties and events of the Control class, the managed


control contains the following properties and events.

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).

public void CreateMyDateTimePicker()

// Create a new DateTimePicker control and initialize it.

DateTimePicker dateTimePicker1 = new DateTimePicker();

// Set the MinDate and MaxDate.

dateTimePicker1.MinDate = new DateTime(1985, 6, 20);

dateTimePicker1.MaxDate = DateTime.Today;

// Set the CustomFormat string.

dateTimePicker1.CustomFormat = "MMMM dd, yyyy - dddd";


dateTimePicker1.Format = DateTimePickerFormat.Custom;

// Show the CheckBox and display the control as an up-down control.

dateTimePicker1.ShowCheckBox = true;

dateTimePicker1.ShowUpDown = true;

Part- B (Attempt any three from Q5. to Q8.)

Q5. Elaborate Common Dialogue Box using example?

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.

Using Common Dialog


Boxes Covers tasks that invoke common dialog boxes.

Common Dialog Box


Reference Contains the API reference.
 usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;

usingSystem.Text;

static void Main(string[] args)

using (FolderBrowserDialog dialog = new FolderBrowserDialog())

//Set the root folder

dialog.RootFolder = Environment.SpecialFolder.Desktop;

//Set the currently selected directory

dialog.SelectedPath = Environment.CurrentDirectory;

//Do you want to allow the user to create folders in this


dialog?

dialog.ShowNewFolderButton = true;

//A meaningful description

dialog.Description = "This is a description";

if(dialog.ShowDialog() == DialogResult.OK)

MessageBox.Show(dialog.SelectedPath);
}

Q6. WAP to explain Save Dialogue Box?


Ans.
{
public stringfile1;
publicForm1()
{
InitializeComponent();
}
private voidForm1_Load(objectsender,
EventArgse)
{
}
private
void
openToolStripMenuItem_Click_1(object sender,EventArgs
e)
{
int size = -1;
DialogResult
result
=
openFileDialog1.ShowDialog(); // Show the dialog.
if (result ==DialogResult.OK) // Test
result.
{
stringfile;
file = openFileDialog1.FileName;
try
{
richTextBox1.Text =
File.ReadAllText(file);
size = richTextBox1.Text.Length;
}
catch(IOException)
{
}
}
Console.WriteLine(size); // <-- Shows file
size in debugging mode.
Console.WriteLine(result); // <-- For
debugging use only.
}
private voidmenuStrip1_ItemClicked(object
sender,ToolStripItemClickedEventArgs e)
{
}
private
void
saveAsToolStripMenuItem_Click_1(object
sender,
EventArgse)
{
saveAs();
}
public voidsaveAs()
{
if (saveFileDialog1.ShowDialog() ==
DialogResult.OK)
{
string name = saveFileDialog1.FileName;
// Write to the file name selected.
// ... You can write the text from a
TextBox instead of a string literal.
File.WriteAllText(name,
richTextBox1.Text);
}
}
private
void
saveToolStripMenuItem_Click_1(object sender,EventArgs
e)
{
save();
}
public voidsave()
{
if (file1 == null)
{
saveAs();
}
file1 = openFileDialog1.FileName;
File.WriteAllText(file1,
richTextBox1.Text);
MessageBox.Show("file saved");
}
private voidnewToolStripMenuItem_Click(object
sender,EventArgs e)
{
newForm1();
}
private
void
exitToolStripMenuItem_Click_1(object sender,EventArgs
e)
{
Close();
}
}
}
Q8. What is color Dialogue Box. How do we use it?
Ans. Program states that in one form if we want to place one button, while
clicking on the button next form is appear with change color and having a
display button like change color in a new window button, if we click new
window button we will take color dialog box along with button which looks
like button (…) along with the textbox. If we click on (…)button color dialog
box is appear and if we choose color on that dialog box the back color of
the textbox will be filled like that.
Open new project and create a Form1 with one button having text property
click to change color as shown below.
Place a code on the double click on the button event.
public partial class color : Form
    {
        Boolean check = false;//declare check for conditions
        public color()
        {
            InitializeComponent();
        }
 
        private void BtnColour_Click(object sender, EventArgs e)
        {
            if (check == false)//checking conditions if check is false
//then executes this statement.
            {
                this.BackColor = Color.Red;//color of the form is red.
                BtnColour.Text = "new window";//resetting button text
                check = true;
            }
            else
            {
                Form1 fm = new Form1();//create object of the form as fm
                fm.ShowDialog();
 
            }
Next create another page with the help of add existing item, as shown
below:

As soon as we click on the button(…)we can see a colour dialog box as


shown below.

Вам также может понравиться