0% found this document useful (0 votes)
62 views12 pages

hw3 Cap 406

The document provides information about namespaces and properties/methods of listboxes in C#: 1. Namespaces help organize code and avoid naming collisions. They allow accessing classes from other namespaces. 2. Listbox properties include SelectedIndex, Items, MultiColumn, and SelectionMode. Methods include ClearSelected, FindString, and GetSelected. 3. The document gives an example of using namespaces and describes several common listbox properties and methods.

Uploaded by

Bableen Kaur
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views12 pages

hw3 Cap 406

The document provides information about namespaces and properties/methods of listboxes in C#: 1. Namespaces help organize code and avoid naming collisions. They allow accessing classes from other namespaces. 2. Listbox properties include SelectedIndex, Items, MultiColumn, and SelectionMode. Methods include ClearSelected, FindString, and GetSelected. 3. The document gives an example of using namespaces and describes several common listbox properties and methods.

Uploaded by

Bableen Kaur
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 12

Homework Title / No.

: _____HOMEWORK3_______Course Code: _406________

Course Instructor: ______ MR Rohit Ohri____ Course Tutor (if applicable): MR Rohit Ohri_

Date of Allotment: _____________________ Date of submission: _

Student’s Roll No.___RTB012A15_______ Section No. : _RTB012____


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: Bableen Kaur


Evaluator’s comments:
_____________________________________________________________________
Marks obtained : ___________ out of ______________________
Content of Homework should start from this page only:

CAP 406 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 Namespaces are C# program elements designed to help you
organize your programs. They also provide assistance in avoiding
name clashes between two sets of code. Implementing Namespaces in
your own code is a good habit because it is likely to save you from
problems later when you want to reuse some of your code. For
example, if you created a class named Console, you would need to put
it in your own namespace to ensure that there wasn't any confusion
about when the System.Console class should be used or when your
class should be used. Generally, it would be a bad idea to create a
class named Console, but in many cases your classes will be named
the same as classes in either the .NET Framework Class Library or a
third party library and namespaces help you avoid the problems that
identical class names would cause.
Example of namespace
Using System;
Using A.B.C;

namespace E
{
using D;

class Program
{
static void Main()
{
// Can access CClass type directly from A.B.C.
CClass var1 = new CClass();

// Can access DClass type from D.


DClass var2 = new DClass();

// Must explicitely specify F namespace.


F.FClass var3 = new F.FClass();

// Output.
Console.WriteLine(var1);
Console.WriteLine(var2);
Console.WriteLine(var3);
}
}
}

namespace A
{
namespace B
{
namespace C
{
public class CClass
{
}
}
}
}

namespace D
{
public class DClass
{
}
}

namespace F
{
public class FClass
{
}
}

Output:

A.B.C.CClass
D.DClass
F.FClass

Q2. What are properties and methods of List Box. Using example
explain how we use them?

properties of listbox

Name Availability Description


This value indicates the
zero-based index of the
selected item in the list
box. If the list box can
SelectedIndex Read/Write contain multiple
selections at the same
time, this property holds
the index of the first
item in the selected list.
In a list box with
multiple columns, this
ColumnWidth Read/Write
property specifies the
width of the columns.
The Items collection
contains all of the items
in the list box. You use
Items Read-only
the properties of this
collection to add and
remove items.
A list box can have more
than one column. Use
MultiColumn Read/Write this property the get or
set the number of
columns in the list box.
This property is a
collection, which holds
SelectedIndices Read-only all of the zero-based
indices of the selected
items in the list box.
SelectedItem Read/Write In a list box where only
one item can be
selected, this property
contains the selected
item if any. In a list box
where more than one
selection can be made,
it will contain the first of
the selected items.
This property is a
collection, which
SelectedItems Read-only
contains all of the items
currently selected.
You can choose between
four different modes of
selection in a list box:

q None: No items can be


selected.

q One: Only one item


can be selected at any
time.
SelectionMode Read/Write
q MultiSimple: Multiple
items can be selected.

q MultiExtended:
Multiple items can be
selected and the user
can use the Ctrl, Shift
and arrows keys to
make selections.
Setting this property to
true will cause the
Sorted Read/Write ListBox to sort the items
it contains
alphabetically.
Text Read/Write We've seen Text
properties on a number
of controls, but this one
works very differently
than any we've seen so
far. If you set the Text
property of the list box
control, it searches for
an item that matches
the text, and selects it.
If you get the Text
property, the value
returned is the first
selected item in the list.
This property cannot be
used if the
SelectionMode is None.
(CheckedListBox only)
This property is a
collection, which
CheckedIndicies Read-only contains all indexes in
the CheckedListBox that
is a checked or
indeterminate state.
(CheckedListBox only)
This is a collection of all
the items in a
CheckedItems Read-only CheckedListBox that are
in a checked or
indeterminate state.

(CheckedListBox only) If
this property is true, an
CheckOnClick Read/Write item will change its
state whenever the user
clicks it.
(CheckedListBox only)
You can choose between
ThreeDCheckBoxes Read/Write Checkboxes that are flat
or normal by setting
this property.

Listbox methods

Name Description
ClearSelected Clears all selections in the ListBox,
FindString Finds the first string in the ListBox
beginning with a string you specify
for example FindString("a") will find
the first string in the ListBox
beginning with 'a'
Like FindString but the entire string
FindStringExact
must be matched
Returns a value that indicates
GetSelected
whether an item is selected
Sets or clears the selection of an
SetSelected
item
ToString Returns the currently selected item
(CheckedListBox only) Returns a
GetItemChecked value indicating if an item is
checked or not
(CheckedListBox only) Returns a
GetItemCheckState value indicating the check state of
an item
(CheckedListBox only) Sets the
SetItemChecked
item specified to achecked state.
(CheckedListBox only) Sets the
SetItemCheckState
check state of an item

Q3. Write detailed Program. And Steps to create Message Box that
gives a confirmation message after checking user name and pass word
authentication from a user?
Q4. What are properties of Date Time Picker. To which library they
belong and program to use them?
Ans
Properties Comments
Format A DateTimePickerFormat value that specifies if the forma
MaxDateTime A read-only DateTime object that indicates the maximum d
MinDateTime A read-only DateTime object that indicates the minimum d
Text A string object that represents the selected date.
Value A DateTime object that represents the selected date.
using System
System.Collections.Generic
System.ComponentModel
System.Drawing
System.Text
System.Windows.Forms
Public Class Form1
Inherits Form

Public Sub New()


InitializeTimePicker()

End Sub
Private timePicker As DateTimePicker

Private Sub InitializeTimePicker()


timePicker = New DateTimePicker()
timePicker.Format = DateTimePickerFormat.Time
timePicker.ShowUpDown = True
timePicker.Location = New Point(10, 10)
timePicker.Width = 100
Controls.Add(timePicker)

End Sub

<STAThread()> _
Shared Sub Main()
Application.EnableVisualStyles()
Application.Run(New Form1())

End Sub
End Class

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

Q5. Elaborate Common Dialogue Box using example?

Answer

Windows implements a variety of reusable dialog boxes that are


common to all applications, including dialog boxes for opening files,
saving files, and printing. Since these dialog boxes are implemented
by the operating system, they can be shared among all the
applications that run on the operating system, which helps user
experience consistency; when users are familiar with the use of an
operating system-provided dialog box in one application, they don't
need to learn how to use that dialog box in other applications. Because
these dialog boxes are available to all applications and because they
help provide a consistent user experience, they are known as common
dialog boxes.

Windows Presentation Foundation (WPF) encapsulates the open file,


save file, and print common dialog boxes and exposes them as
managed classes for you to use in standalone applications.

Q6. WAP to explain Save Dialogue Box?


SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.InitialDirectory =
Environment.SpecialFolder.MyDocuments;
saveFileDialog1.Filter = "Your extension here (*.EXT)|*.ext|All Files
(*.*)|*.*" ;
saveFileDialog1.FilterIndex = 1;

if(saveFileDialog1.ShowDialog() == DialogResult.OK)
{
Console.WriteLine(saveFileDialog1.FileName);
}

Q7. How do you use File Input Output Dialogue Box? What is the
purpose of System.IO. Writ a prg. And give its use.
Q8. What is color Dialogue Box. How do we use it?
Answer 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 color dialog box as
shown below.

FIG 1

As soon as we select color in the colordialogbox it will come in the


textbox.

Now place a piece of code on the button (…) as below.

Private void btncolor_Click (object sender, EventArgs e)


{
colorDialog1.ShowDialog (); //dialog box will appear.
textBox1.BackColor = colorDialog1.Color;//in
textbox1backcolour filled with the help of color dialog box as shown in
above figure.
}

Similarly for the second color dialog button (…)

Private void button1_Click (object sender, EventArgs e)


{
colorDialog2.ShowDialog ();
txtBrowser2.BackColor = colorDialog2.Color;
}

The output will be appear like

You might also like