SlideShare una empresa de Scribd logo
1 de 15
Descargar para leer sin conexión
030010401 BCA 4th Semester
Preeti P Bhatt Department of Computer Science, UTU. 1 | P a g e
030010401- GUI Programming
Unit-5: Advance GUI Controls
BCA 4th Semester
Note: - This material is prepared by Ms. Preeti P Bhatt. The basic
objective of this material is to supplement teaching and discussion
in the classroom. Student is required to go for extra reading in the
subject through library work.
030010401 BCA 4th Semester
Preeti P Bhatt Department of Computer Science, UTU. 2 | P a g e
Topic Covered
 RichTextBox: Text manipulation and formatting
 Dialog Box: Color, font, file open, file save and common dialog boxes
 Treeview control: Adding nodes at design time and runtime, scanning tree view control
 ListView control: The column collection, ListView Items and sub items, Items collection, Sub
items collection, sorting in ListView, processing selected Items
030010401 BCA 4th Semester
Preeti P Bhatt Department of Computer Science, UTU. 3 | P a g e
RichTextBox
RichTextBoxes are similar to Textboxes but they provide some advanced features over the standard
Textbox.
RichTextBox allows formatting the text, say adding colors, displaying particular font types and so on.
Property of RichTextBox
Property Means
AutoSize Sets/gets a value specifying if the size of the rich text box automatically adjusts when the
font changes.
BorderStyle Sets/gets the border type of the rich text box.
BulletIndent Sets/gets the indentation used in the rich text box when the bullet style is applied to the
text.
Lines Sets/gets the lines of text in a RichTextBox control.
Multiline Sets/gets a value specifying if this is a multiline RichTextBox control.
ReadOnly Sets/gets a value specifying if text in the rich text box is read-only.
ScrollBars Sets/gets the kind of scroll bars to display in the RichTextBox control.
Methods of RichTextBox
Method Means
AppendText Appends text to the current text of the rich text box.
CanPaste Determines if you can paste information from the clipboard.
Clear Clears all text from the RichTextBox Control.
Copy Copy the current selection in the rich text box to the clipboard.
Cut Moves the current selection in the rich text box to the clipboard.
LoadFile Loads the contents of a file into the RichTextBox control.
SaveFile Saves the contents of the rich text box to a file.
Events of RichTextBox
Events Means
TextChanged Occurs when text is changed
Click Occurs when the text box is clicked.
ReadOnlyChanged Occurs when the value of the ReadOnly property is changed.
030010401 BCA 4th Semester
Preeti P Bhatt Department of Computer Science, UTU. 4 | P a g e
Accessing Text in a Rich Text Box
To access text in a rich text box, you can use two properties: Text and Rtf.
 Text holds the text in a rich text box in plain text format (like a text box)
 Rtf holds the text in rich text format.
Here's an example where we read the text in RichTextBox1 without any RTF codes and display that text
as plain text in RichTextBox2:
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
RichTextBox2.Text = RichTextBox1.Text
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button2.Click
RichTextBox2.Rtf = RichTextBox1.Rtf
End Sub
Bold, Italic, underline, strikeout and Color
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim ItalicFont As New Font(RichTextBox1.Font, FontStyle.Italic)
RichTextBox1.SelectionFont = ItalicFont
Dim BoldFont As New Font(RichTextBox1.Font, FontStyle.Bold)
RichTextBox1.SelectionFont = BoldFont
Dim UnderlineFont As New Font(RichTextBox1.Font, FontStyle.Underline)
RichTextBox1.SelectionFont = UnderlineFont
Dim StrikeoutFont As New Font(RichTextBox1.Font, FontStyle.Strikeout)
RichTextBox1.SelectionFont = StrikeoutFont
RichTextBox3.SelectionColor = Color.Red
End Sub
Saving and Loading File
Private Sub Button6_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button6.Click
RichTextBox3.SaveFile("text.rtf")
RichTextBox1.LoadFile("text.rtf")
End Sub
Alignment in RichTextBox
You can set the alignment of text in a rich text box paragraph by paragraph using the SelectionAlignment
property.
 HorizontalAlignment.Left— 0 (the default)—The paragraph is aligned along the left margin.
 HorizontalAlignment.Right— 1—The paragraph is aligned along the right margin.
 HorizontalAlignment.Center— 2—The paragraph is centered between the left and right
margins.
030010401 BCA 4th Semester
Preeti P Bhatt Department of Computer Science, UTU. 5 | P a g e
Dialog Box
Visual Basic .NET comes with built-in dialog boxes which allow us to create our own dialogs box.
Dialog Box:
– OpenFileDialog
– SaveFileDialog
– ColorDialog
– FontDialog
– PrintDialog,
– PrintPreviewDialog
– PageSetupDialog.
To make a dialog box visible at run time we use the dialog box's ShowDialog method.
You can check its return value (such as DialogResult.OK or DialogResult.Cancel) to see which button
the user has clicked. Here are the possible return values from this method, from the DialogResult
enumeration:
 Abort— The dialog box return value is Abort (usually from a button labeled Abort).
 Cancel— The dialog box return value is Cancel (usually from a button labeled Cancel).
 Ignore— The dialog box return value is Ignore (usually from a button labeled Ignore).
 No— The dialog box return value is No (usually from a button labeled No).
 None— Nothing is returned from the dialog box. This means that the modal dialog continues
running.
 OK— The dialog box return value is OK (usually from a button labeled OK).
 Retry— The dialog box return value is Retry (usually from a button labeled Retry).
 Yes— The dialog box return value is Yes (usually from a button labeled Yes).
OpenFileDialog:
Open File Dialog's are supported by the OpenFileDialog class.
They allow us to select a file to be opened.
030010401 BCA 4th Semester
Preeti P Bhatt Department of Computer Science, UTU. 6 | P a g e
Property of OpenFileDialog
Properties Mean
AddExtension Gets/Sets if the dialog box adds extension to file names if the user doesn't supply the
extension.
CheckFileEixsts Checks whether the specified file exists before returning from the dialog.
CheckPathExists Checks whether the specified path exists before returning from the dialog.
DefaultExt Allows you to set the default file extension
FileName Gets/Sets file name selected in the file dialog box
FileNames Gets the file names of all selected files.
Filter Gets/Sets the current file name filter string, which sets the choices that appear in the
"Files of Type" box.
Methods of OpenFileDialog
Method Means
OpenFile Opens the file selected by the user, with read-only permission. The file is specified by
the FileName property.
Reset Resets all options to their default values.
ShowDialog Shows the dialog box.
Events OpenFileDialog
Event Means
FileOk Occurs when the user clicks the Open or Save button.
HelpRequest Occurs when the user clicks the Help button.
Code for load image in Picture box Controls
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
If OpenFileDialog1.ShowDialog() <> DialogResult.Cancel Then
PictureBox1.Image = Image.FromFile(OpenFileDialog1.FileName)
End If
End Sub
Code for load content in RichTextBox Controls
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
If OpenFileDialog1.ShowDialog() <> DialogResult.Cancel Then
RichTextbox1.LoadFile(OpenFileDialog1.FileName)
End If
End Sub
030010401 BCA 4th Semester
Preeti P Bhatt Department of Computer Science, UTU. 7 | P a g e
SaveFileDialog:
Save File Dialog's are supported by the SaveFileDialog class and they allow us to save the file in a
specified location.
Properties of the Save File Dialog are the same as that of the Open File Dialog.
Notable property of Save File dialog is the OverwritePromopt property which displays a warning if we
choose to save to a name that already exists.
Property of SaveFileDialog
Properties Mean
AddExtension Gets/Sets if the dialog box adds extension to file names if the user doesn't supply the
extension.
CheckFileEixsts Checks whether the specified file exists before returning from the dialog.
CheckPathExists Checks whether the specified path exists before returning from the dialog.
DefaultExt Allows you to set the default file extension
FileName Gets/Sets file name selected in the file dialog box
FileNames Gets the file names of all selected files.
Filter Gets/Sets the current file name filter string, which sets the choices that appear in the
"Files of Type" box.
Methods of SaveFileDialog
Method Means
OpenFile Opens the file selected by the user, with read-only permission. The file is specified by
the FileName property.
Reset Resets all options to their default values.
ShowDialog Shows the dialog box.
Events of SaveFileDialog
Event Means
FileOk Occurs when the user clicks the Open or Save button.
HelpRequest Occurs when the user clicks the Help button.
030010401 BCA 4th Semester
Preeti P Bhatt Department of Computer Science, UTU. 8 | P a g e
Code for Save content in RichTextBox Controls
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
If SaveFileDialog1.ShowDialog <> DialogResult.Cancel Then
MsgBox("You chose " & SaveFileDialog1.FileName)
RichTextBox1.SaveFile(SaveFileDialog1.FileName)
End If
End Sub
ColorDialog:
Color Dialog's are supported by the ColorDialog Class and
they allow us to select a color. The image below displays a
color dialog.
Property of ColorDialog
Property Meaning
AllowFullOpen: Gets/Sets whether the user can use the dialog box to define custom colors.
AnyColor: Gets/Sets whether thedialog box displays all the available colors in the set of
basic colors.
Color: Gets/Sets the color selected by the user.
CustomColors: Gets/Sets the set of custom colors shown in the dialog box.
ShowHelp: Gets/Sets whether the dialog box displays a help button.
SolidColorOnly: Gets/Sets whether the dialog box will restrict users to selecting solid colors only.
Methods of ColorDialog
Method Means
Reset Resets all dialog options to their default values.
ShowDialog Shows the dialog.
Events of ColorDialog
Event Means
HelpRequest Occurs when the user clicks the Help button.
Code for ColorDialog box
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
If ColorDialog1.ShowDialog <> DialogResult.Cancel Then
Label1.Text = "Here's my new color!"
RichTextbox1.SelectionBackColor = ColorDialog1.Color
End If
End Sub
030010401 BCA 4th Semester
Preeti P Bhatt Department of Computer Science, UTU. 9 | P a g e
FontDialog:
The Font dialog box lets the user choose attributes for a logical
font,font family, font style, point size, effects , and a script .
Properties of FontDialog
Properties Meaning
AllowVerticalFonts:
Gets/Sets whether the dialog box displays both vertical and horizontal fonts or
only horizontal fonts.
Color: Gets/Sets selected font color.
Font: Gets/Sets the selected font.
MaxSize: Gets/Sets the maximum point size the user can select.
MinSize: Gets/Sets the mainimum point size the user can select.
ShowColors: Gets/Sets whether the dialog box displays the color choice.
ShowEffects Gets/Sets whether the dialog box contains controls that allow the user to
specify to specify strikethrough, underline and text color options.
ShowHelp: Gets/Sets whether the dialog box displays a help button.
Methods of ColorDialog
Method Means
Reset Resets all dialog options to default values.
ShowDialog Shows the dialog.
Events of ColorDialog
Event Means
Apply Occurs when the user clicks the Apply button.
HelpRequest Occurs when the user clicks the Help button.
Code for ColorDialog box
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
If FontDialog1.ShowDialog <> DialogResult.Cancel Then
RichTextBox1.Font = FontDialog1.Font
RichTextBox1.ForeColor = FontDialog1.Color
End If
End Sub
030010401 BCA 4th Semester
Preeti P Bhatt Department of Computer Science, UTU. 10 | P a g e
PrintDialog
Print dialogs let the user print documents, and these dialogs are supported
with the PrintDialog class.
Before displaying a Print dialog, you set the
 Document property of a PrintDialog object to a PrintDocument
object,
 PrinterSettings property to a PrinterSettings object of the
kind set by Page Setup dialogs.
Events of ColorDialog
Property Means
DefaultPageSettings Gets/sets the default settings that apply to a single, printed page of the
document.
DocumentName Gets/sets the document name to display while printing the document, as in a
print status dialog box or printer queue.
PrinterSettings Gets/sets the printer that prints the document.
Events of ColorDialog
Method Means
Print Prints the document.
Events of ColorDialog
Event Means
BeginPrint Happens when the Print method is called to start a print job.
EndPrint Happens when the last page of the document has printed.
PrintPage Happens for each page to print-you draw the page in this event's handler.
QueryPageSettings Happens before each PrintPage event.
Code for Print
Private Sub MenuItem1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MenuItem1.Click
PrintDialog1.Document = PrintDocument1
PrintDialog1.PrinterSettings = PrintDocument1.PrinterSettings
PrintDialog1.AllowSomePages = True
If PrintDialog1.ShowDialog = DialogResult.OK Then
PrintDocument1.PrinterSettings = PrintDialog1.PrinterSettings
PrintDocument1.Print()
End If
End Sub
030010401 BCA 4th Semester
Preeti P Bhatt Department of Computer Science, UTU. 11 | P a g e
Treeview
The tree view control is used to display a hierarchy of nodes (both parent, child).
You can expand and collapse these nodes by clicking them.
Properties of Treeview
Property Means
BorderStyle Gets/sets the tree view's border style.
CheckBoxes Gets/sets whether checkboxes should be displayed next to tree nodes.
Nodes Gets the collection of tree nodes.
SelectedNode Gets/sets the node that is selected.
TopNode Gets the first visible tree node.
Sorted Gets/sets if the tree nodes should be sorted.
ShowPlusMinus Gets/sets whether plus-sign (+) and minus-sign (-) buttons are shown next to tree
nodes with child tree nodes.
LastNode: Gets the last child node
NextNode: Gets the next sibling node
Methods of Treeview
Method Means
BeginUpdate Disables redrawing of the tree view.
CollapseAll Collapses all nodes.
EndUpdate Enables redrawing of the tree view.
ExpandAll Expands all the nodes.
GetNodeAt Gets the node that is at the given location.
GetNodeCount Gets the number of nodes.
Events of Treeview
Event Means
AfterCheck Occurs when a node checkbox is checked.
AfterCollapse Occurs when a tree node is collapsed.
AfterExpand Occurs when a tree node is expanded.
AfterLabelEdit Occurs when a tree node label text is edited.
AfterSelect Occurs when a tree node is selected.
BeforeCheck Occurs before a node checkbox is checked.
BeforeCollapse Occurs before a node is collapsed.
BeforeExpand Occurs before a node is expanded.
BeforeLabelEdit Occurs before a node label text is edited.
BeforeSelect Occurs before a node is selected.
ItemDrag Occurs when an item is dragged into the tree view.
030010401 BCA 4th Semester
Preeti P Bhatt Department of Computer Science, UTU. 12 | P a g e
Code for Treeview
• How to add a Root Node
TreeView1.Nodes.Add(“Node Name”)
TreeView1.Nodes.Add(txtNode.Text)
TreeView1.Nodes.Add(InputBox("ENTER NODE NAME"))
• How to add a Child node to a selected node
TreeView1.SelectedNode.Nodes.Add(“Node Name")
TreeView1.SelectedNode.Nodes.Add(txtNode.Text)
TreeView1.SelectedNode.Nodes.Add(“InputBox("ENTER NODE NAME"))")
• Collapse Selected node
TreeView1.SelectedNode.Collapse()
• Expand all Node
TreeView1.ExpandAll()
• Display Selected Node
Textbox1.Text = tvdata.SelectedNode.Text
ListView
If tree views are all about displaying node hierarchies, like the folder hierarchy on a disk, then list views
are all about displaying lists of items. You can see a list view in the right pane in the Windows Explorer
030010401 BCA 4th Semester
Preeti P Bhatt Department of Computer Science, UTU. 13 | P a g e
Properties of ListView
Properties Means
View  View.LargeIcon : The large icon mode displays large icons (large icons are 32×32
pixels) next to the item text.
 View.SmallIcon: The small icon mode is the same except that it displays items using
small icons (small icons are 16×16 pixels).
 View.List: The list mode displays small icons, always in one column
 View.Details: The report mode (also called the details mode) displays items in multiple
columns
ListItems
This contains the items displayed by the control.
SelectedItems
contains a collection of the items currently selected in the control.
MultiSelect
The user can select multiple items if the MultiSelect property is set to True.
CheckBoxes
list views can display checkboxes next to the items, if the CheckBoxes property is set to
True.
Sorting
Sort Item in listbox
Activation
Property sets what action the user must take to activate an item in the list:
 OneClick requires a single click to activate the item.
 TwoClick requires the user to double-click (a single click changes the color of the item
text).
 Standard requires the user to double-click to activate an item (but in this case, the
item does not change appearance).
Methods of ListView
Method Means
ArrangeIcons Arranges the displayed items in Large Icon or Small Icon view.
BeginUpdate Stops the list view from redrawing.
Clear Removes all items from the list view.
EndUpdate Allows redrawing of the list view.
EnsureVisible Makes sure that an item is visible.
GetItemAt Gets the item corresponding to the given X, Y coordinate.
Events of ListView
Events Means
AfterLabelEdit Occurs when a label has been edited.
BeforeLabelEdit Occurs before a label is changed.
ColumnClick Occurs when a column is clicked.
ItemActivate Occurs when an item is activated.
ItemCheck Occurs when an item is checked.
SelectedIndexChanged Occurs when the selected index changes.
030010401 BCA 4th Semester
Preeti P Bhatt Department of Computer Science, UTU. 14 | P a g e
ListView Item
The items in a list view are objects of the ListViewItem class, and the collection of those items is stored
in the list view's Items property.
Property Means
Bounds Gets the bounding rectangle of an item, including its subitems.
Checked True if the item is checked, False otherwise.
Index Gets the index in the list view of the item.
ListView Gets the list view that contains this item.
Selected Gets/sets if the item is selected.
SubItems Gets a collection of the subitems of this item.
Text Gets the text for this item.
Creating ListView in code
Private Sub Form1_Load(ByVal eventSender As System.Object, _
ByVal eventArgs As System.EventArgs) Handles MyBase.Load
ListView1.Columns.Add("Name", ListView1.Width / 4, _
HorizontalAlignment.Left)
ListView1.Columns.Add("Date Modified", ListView1.Width / 4, _
HorizontalAlignment.Left)
ListView1.Columns.Add("Type", ListView1.Width / 4, _
HorizontalAlignment.Left)
Dim ListItem1 As ListViewItem
ListItem1 = ListView1.Items.Add("Picture", 1)
ListView1.Items(0).SubItems.Add("12-12-2012")
ListView1.Items(0).SubItems.Add("Library")
Dim ListItem2 As ListViewItem
ListItem2 = ListView1.Items.Add("Document", 1)
ListView1.Items(1).SubItems.Add("13-12-2012")
ListView1.Items(1).SubItems.Add("Library")
Dim ListItem3 As ListViewItem
ListItem2 = ListView1.Items.Add("Music", 1)
ListView1.Items(2).SubItems.Add("1-1-2012")
ListView1.Items(2).SubItems.Add("Library")
ListView1.SmallImageList = ImageList1
ListView1.LargeImageList = ImageList2
End Sub
030010401 BCA 4th Semester
Preeti P Bhatt Department of Computer Science, UTU. 15 | P a g e
Code for Sorting
ListView1.Sorting = SortOrder.Ascending
Change view on basis of combobox Value
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
ComboBox1.SelectedIndexChanged
If ComboBox1.SelectedItem = "Detail" Then
ListView1.View = View.Details
ElseIf ComboBox1.SelectedItem = "LargeIcon" Then
ListView1.View = View.LargeIcon
ElseIf ComboBox1.SelectedItem = "SmallIcon" Then
ListView1.View = View.SmallIcon
ElseIf ComboBox1.SelectedItem = "List" Then
ListView1.View = View.List
ElseIf ComboBox1.SelectedItem = "Tile" Then
ListView1.View = View.Tile
End If
End Sub

Más contenido relacionado

Destacado (6)

Unit6
Unit6Unit6
Unit6
 
Unit2
Unit2Unit2
Unit2
 
Unit 1 introduction to visual basic programming
Unit 1 introduction to visual basic programmingUnit 1 introduction to visual basic programming
Unit 1 introduction to visual basic programming
 
Unit4
Unit4Unit4
Unit4
 
Ch6
Ch6Ch6
Ch6
 
Arrive RoomPoint
Arrive RoomPointArrive RoomPoint
Arrive RoomPoint
 

Similar a Unit5

Putting dialog boxes to work
Putting dialog boxes to workPutting dialog boxes to work
Putting dialog boxes to work
chunky.sarath
 
CS101S. ThompsonUniversity of BridgeportLab 7 Files, File.docx
CS101S. ThompsonUniversity of BridgeportLab 7 Files, File.docxCS101S. ThompsonUniversity of BridgeportLab 7 Files, File.docx
CS101S. ThompsonUniversity of BridgeportLab 7 Files, File.docx
annettsparrow
 
This is a java lab assignment. I have added the first part java re.pdf
This is a java lab assignment. I have added the first part java re.pdfThis is a java lab assignment. I have added the first part java re.pdf
This is a java lab assignment. I have added the first part java re.pdf
feetshoemart
 
Qtp commands
Qtp commandsQtp commands
Qtp commands
G.C Reddy
 
Creating a text editor in delphi, a tutorial
Creating a text editor in delphi, a tutorialCreating a text editor in delphi, a tutorial
Creating a text editor in delphi, a tutorial
Erwin Frias Martinez
 
Windows FTK Forensics.pdf
Windows FTK Forensics.pdfWindows FTK Forensics.pdf
Windows FTK Forensics.pdf
ssusere6dc9d
 

Similar a Unit5 (20)

Putting dialog boxes to work
Putting dialog boxes to workPutting dialog boxes to work
Putting dialog boxes to work
 
Blackboard training - Creating a learning module
Blackboard training - Creating a learning moduleBlackboard training - Creating a learning module
Blackboard training - Creating a learning module
 
CS101S. ThompsonUniversity of BridgeportLab 7 Files, File.docx
CS101S. ThompsonUniversity of BridgeportLab 7 Files, File.docxCS101S. ThompsonUniversity of BridgeportLab 7 Files, File.docx
CS101S. ThompsonUniversity of BridgeportLab 7 Files, File.docx
 
Oepnfiledialog
OepnfiledialogOepnfiledialog
Oepnfiledialog
 
Search++ Manual
Search++ ManualSearch++ Manual
Search++ Manual
 
This is a java lab assignment. I have added the first part java re.pdf
This is a java lab assignment. I have added the first part java re.pdfThis is a java lab assignment. I have added the first part java re.pdf
This is a java lab assignment. I have added the first part java re.pdf
 
Vb lecture notes
Vb lecture notesVb lecture notes
Vb lecture notes
 
Introduction to Programming
Introduction to Programming Introduction to Programming
Introduction to Programming
 
Paste Only Plain Text in RichTextBox Control using Visual Basic.Net
Paste Only Plain Text in RichTextBox Control using Visual Basic.NetPaste Only Plain Text in RichTextBox Control using Visual Basic.Net
Paste Only Plain Text in RichTextBox Control using Visual Basic.Net
 
Qtp commands
Qtp commandsQtp commands
Qtp commands
 
I need some help creating Psuedocode for a project using Java. Basic.pdf
I need some help creating Psuedocode for a project using Java. Basic.pdfI need some help creating Psuedocode for a project using Java. Basic.pdf
I need some help creating Psuedocode for a project using Java. Basic.pdf
 
Filehandling
FilehandlingFilehandling
Filehandling
 
Chapter 05
Chapter 05Chapter 05
Chapter 05
 
Creating a text editor in delphi, a tutorial
Creating a text editor in delphi, a tutorialCreating a text editor in delphi, a tutorial
Creating a text editor in delphi, a tutorial
 
Windows FTK Forensics.pdf
Windows FTK Forensics.pdfWindows FTK Forensics.pdf
Windows FTK Forensics.pdf
 
pspp-rsk.pptx
pspp-rsk.pptxpspp-rsk.pptx
pspp-rsk.pptx
 
Windows form application - C# Training
Windows form application - C# Training Windows form application - C# Training
Windows form application - C# Training
 
Module 3 open office writer
Module 3 open office writerModule 3 open office writer
Module 3 open office writer
 
Windows controls in c
Windows controls in cWindows controls in c
Windows controls in c
 
VB Dot net
VB Dot net VB Dot net
VB Dot net
 

Más de Abha Damani (20)

Ch14
Ch14Ch14
Ch14
 
Ch12
Ch12Ch12
Ch12
 
Ch11
Ch11Ch11
Ch11
 
Ch10
Ch10Ch10
Ch10
 
Ch08
Ch08Ch08
Ch08
 
Ch01 enterprise
Ch01 enterpriseCh01 enterprise
Ch01 enterprise
 
3 data mgmt
3 data mgmt3 data mgmt
3 data mgmt
 
2 it supp_sys
2 it supp_sys2 it supp_sys
2 it supp_sys
 
1 org.perf it supp_appl
1 org.perf it supp_appl1 org.perf it supp_appl
1 org.perf it supp_appl
 
Managing and securing the enterprise
Managing and securing the enterpriseManaging and securing the enterprise
Managing and securing the enterprise
 
Unit2
Unit2Unit2
Unit2
 
Unit 3
Unit 3Unit 3
Unit 3
 
Unit 4
Unit 4Unit 4
Unit 4
 
Unit 5
Unit 5Unit 5
Unit 5
 
Unit 6
Unit 6Unit 6
Unit 6
 
Unit 1
Unit 1Unit 1
Unit 1
 
Language processor
Language processorLanguage processor
Language processor
 
Introduction to compiler
Introduction to compilerIntroduction to compiler
Introduction to compiler
 
Function of device driver
Function of device driverFunction of device driver
Function of device driver
 
Unit 3 assembler and processor
Unit 3   assembler and processorUnit 3   assembler and processor
Unit 3 assembler and processor
 

Último

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Último (20)

Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 

Unit5

  • 1. 030010401 BCA 4th Semester Preeti P Bhatt Department of Computer Science, UTU. 1 | P a g e 030010401- GUI Programming Unit-5: Advance GUI Controls BCA 4th Semester Note: - This material is prepared by Ms. Preeti P Bhatt. The basic objective of this material is to supplement teaching and discussion in the classroom. Student is required to go for extra reading in the subject through library work.
  • 2. 030010401 BCA 4th Semester Preeti P Bhatt Department of Computer Science, UTU. 2 | P a g e Topic Covered  RichTextBox: Text manipulation and formatting  Dialog Box: Color, font, file open, file save and common dialog boxes  Treeview control: Adding nodes at design time and runtime, scanning tree view control  ListView control: The column collection, ListView Items and sub items, Items collection, Sub items collection, sorting in ListView, processing selected Items
  • 3. 030010401 BCA 4th Semester Preeti P Bhatt Department of Computer Science, UTU. 3 | P a g e RichTextBox RichTextBoxes are similar to Textboxes but they provide some advanced features over the standard Textbox. RichTextBox allows formatting the text, say adding colors, displaying particular font types and so on. Property of RichTextBox Property Means AutoSize Sets/gets a value specifying if the size of the rich text box automatically adjusts when the font changes. BorderStyle Sets/gets the border type of the rich text box. BulletIndent Sets/gets the indentation used in the rich text box when the bullet style is applied to the text. Lines Sets/gets the lines of text in a RichTextBox control. Multiline Sets/gets a value specifying if this is a multiline RichTextBox control. ReadOnly Sets/gets a value specifying if text in the rich text box is read-only. ScrollBars Sets/gets the kind of scroll bars to display in the RichTextBox control. Methods of RichTextBox Method Means AppendText Appends text to the current text of the rich text box. CanPaste Determines if you can paste information from the clipboard. Clear Clears all text from the RichTextBox Control. Copy Copy the current selection in the rich text box to the clipboard. Cut Moves the current selection in the rich text box to the clipboard. LoadFile Loads the contents of a file into the RichTextBox control. SaveFile Saves the contents of the rich text box to a file. Events of RichTextBox Events Means TextChanged Occurs when text is changed Click Occurs when the text box is clicked. ReadOnlyChanged Occurs when the value of the ReadOnly property is changed.
  • 4. 030010401 BCA 4th Semester Preeti P Bhatt Department of Computer Science, UTU. 4 | P a g e Accessing Text in a Rich Text Box To access text in a rich text box, you can use two properties: Text and Rtf.  Text holds the text in a rich text box in plain text format (like a text box)  Rtf holds the text in rich text format. Here's an example where we read the text in RichTextBox1 without any RTF codes and display that text as plain text in RichTextBox2: Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click RichTextBox2.Text = RichTextBox1.Text End Sub Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button2.Click RichTextBox2.Rtf = RichTextBox1.Rtf End Sub Bold, Italic, underline, strikeout and Color Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click Dim ItalicFont As New Font(RichTextBox1.Font, FontStyle.Italic) RichTextBox1.SelectionFont = ItalicFont Dim BoldFont As New Font(RichTextBox1.Font, FontStyle.Bold) RichTextBox1.SelectionFont = BoldFont Dim UnderlineFont As New Font(RichTextBox1.Font, FontStyle.Underline) RichTextBox1.SelectionFont = UnderlineFont Dim StrikeoutFont As New Font(RichTextBox1.Font, FontStyle.Strikeout) RichTextBox1.SelectionFont = StrikeoutFont RichTextBox3.SelectionColor = Color.Red End Sub Saving and Loading File Private Sub Button6_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button6.Click RichTextBox3.SaveFile("text.rtf") RichTextBox1.LoadFile("text.rtf") End Sub Alignment in RichTextBox You can set the alignment of text in a rich text box paragraph by paragraph using the SelectionAlignment property.  HorizontalAlignment.Left— 0 (the default)—The paragraph is aligned along the left margin.  HorizontalAlignment.Right— 1—The paragraph is aligned along the right margin.  HorizontalAlignment.Center— 2—The paragraph is centered between the left and right margins.
  • 5. 030010401 BCA 4th Semester Preeti P Bhatt Department of Computer Science, UTU. 5 | P a g e Dialog Box Visual Basic .NET comes with built-in dialog boxes which allow us to create our own dialogs box. Dialog Box: – OpenFileDialog – SaveFileDialog – ColorDialog – FontDialog – PrintDialog, – PrintPreviewDialog – PageSetupDialog. To make a dialog box visible at run time we use the dialog box's ShowDialog method. You can check its return value (such as DialogResult.OK or DialogResult.Cancel) to see which button the user has clicked. Here are the possible return values from this method, from the DialogResult enumeration:  Abort— The dialog box return value is Abort (usually from a button labeled Abort).  Cancel— The dialog box return value is Cancel (usually from a button labeled Cancel).  Ignore— The dialog box return value is Ignore (usually from a button labeled Ignore).  No— The dialog box return value is No (usually from a button labeled No).  None— Nothing is returned from the dialog box. This means that the modal dialog continues running.  OK— The dialog box return value is OK (usually from a button labeled OK).  Retry— The dialog box return value is Retry (usually from a button labeled Retry).  Yes— The dialog box return value is Yes (usually from a button labeled Yes). OpenFileDialog: Open File Dialog's are supported by the OpenFileDialog class. They allow us to select a file to be opened.
  • 6. 030010401 BCA 4th Semester Preeti P Bhatt Department of Computer Science, UTU. 6 | P a g e Property of OpenFileDialog Properties Mean AddExtension Gets/Sets if the dialog box adds extension to file names if the user doesn't supply the extension. CheckFileEixsts Checks whether the specified file exists before returning from the dialog. CheckPathExists Checks whether the specified path exists before returning from the dialog. DefaultExt Allows you to set the default file extension FileName Gets/Sets file name selected in the file dialog box FileNames Gets the file names of all selected files. Filter Gets/Sets the current file name filter string, which sets the choices that appear in the "Files of Type" box. Methods of OpenFileDialog Method Means OpenFile Opens the file selected by the user, with read-only permission. The file is specified by the FileName property. Reset Resets all options to their default values. ShowDialog Shows the dialog box. Events OpenFileDialog Event Means FileOk Occurs when the user clicks the Open or Save button. HelpRequest Occurs when the user clicks the Help button. Code for load image in Picture box Controls Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click If OpenFileDialog1.ShowDialog() <> DialogResult.Cancel Then PictureBox1.Image = Image.FromFile(OpenFileDialog1.FileName) End If End Sub Code for load content in RichTextBox Controls Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click If OpenFileDialog1.ShowDialog() <> DialogResult.Cancel Then RichTextbox1.LoadFile(OpenFileDialog1.FileName) End If End Sub
  • 7. 030010401 BCA 4th Semester Preeti P Bhatt Department of Computer Science, UTU. 7 | P a g e SaveFileDialog: Save File Dialog's are supported by the SaveFileDialog class and they allow us to save the file in a specified location. Properties of the Save File Dialog are the same as that of the Open File Dialog. Notable property of Save File dialog is the OverwritePromopt property which displays a warning if we choose to save to a name that already exists. Property of SaveFileDialog Properties Mean AddExtension Gets/Sets if the dialog box adds extension to file names if the user doesn't supply the extension. CheckFileEixsts Checks whether the specified file exists before returning from the dialog. CheckPathExists Checks whether the specified path exists before returning from the dialog. DefaultExt Allows you to set the default file extension FileName Gets/Sets file name selected in the file dialog box FileNames Gets the file names of all selected files. Filter Gets/Sets the current file name filter string, which sets the choices that appear in the "Files of Type" box. Methods of SaveFileDialog Method Means OpenFile Opens the file selected by the user, with read-only permission. The file is specified by the FileName property. Reset Resets all options to their default values. ShowDialog Shows the dialog box. Events of SaveFileDialog Event Means FileOk Occurs when the user clicks the Open or Save button. HelpRequest Occurs when the user clicks the Help button.
  • 8. 030010401 BCA 4th Semester Preeti P Bhatt Department of Computer Science, UTU. 8 | P a g e Code for Save content in RichTextBox Controls Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click If SaveFileDialog1.ShowDialog <> DialogResult.Cancel Then MsgBox("You chose " & SaveFileDialog1.FileName) RichTextBox1.SaveFile(SaveFileDialog1.FileName) End If End Sub ColorDialog: Color Dialog's are supported by the ColorDialog Class and they allow us to select a color. The image below displays a color dialog. Property of ColorDialog Property Meaning AllowFullOpen: Gets/Sets whether the user can use the dialog box to define custom colors. AnyColor: Gets/Sets whether thedialog box displays all the available colors in the set of basic colors. Color: Gets/Sets the color selected by the user. CustomColors: Gets/Sets the set of custom colors shown in the dialog box. ShowHelp: Gets/Sets whether the dialog box displays a help button. SolidColorOnly: Gets/Sets whether the dialog box will restrict users to selecting solid colors only. Methods of ColorDialog Method Means Reset Resets all dialog options to their default values. ShowDialog Shows the dialog. Events of ColorDialog Event Means HelpRequest Occurs when the user clicks the Help button. Code for ColorDialog box Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click If ColorDialog1.ShowDialog <> DialogResult.Cancel Then Label1.Text = "Here's my new color!" RichTextbox1.SelectionBackColor = ColorDialog1.Color End If End Sub
  • 9. 030010401 BCA 4th Semester Preeti P Bhatt Department of Computer Science, UTU. 9 | P a g e FontDialog: The Font dialog box lets the user choose attributes for a logical font,font family, font style, point size, effects , and a script . Properties of FontDialog Properties Meaning AllowVerticalFonts: Gets/Sets whether the dialog box displays both vertical and horizontal fonts or only horizontal fonts. Color: Gets/Sets selected font color. Font: Gets/Sets the selected font. MaxSize: Gets/Sets the maximum point size the user can select. MinSize: Gets/Sets the mainimum point size the user can select. ShowColors: Gets/Sets whether the dialog box displays the color choice. ShowEffects Gets/Sets whether the dialog box contains controls that allow the user to specify to specify strikethrough, underline and text color options. ShowHelp: Gets/Sets whether the dialog box displays a help button. Methods of ColorDialog Method Means Reset Resets all dialog options to default values. ShowDialog Shows the dialog. Events of ColorDialog Event Means Apply Occurs when the user clicks the Apply button. HelpRequest Occurs when the user clicks the Help button. Code for ColorDialog box Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click If FontDialog1.ShowDialog <> DialogResult.Cancel Then RichTextBox1.Font = FontDialog1.Font RichTextBox1.ForeColor = FontDialog1.Color End If End Sub
  • 10. 030010401 BCA 4th Semester Preeti P Bhatt Department of Computer Science, UTU. 10 | P a g e PrintDialog Print dialogs let the user print documents, and these dialogs are supported with the PrintDialog class. Before displaying a Print dialog, you set the  Document property of a PrintDialog object to a PrintDocument object,  PrinterSettings property to a PrinterSettings object of the kind set by Page Setup dialogs. Events of ColorDialog Property Means DefaultPageSettings Gets/sets the default settings that apply to a single, printed page of the document. DocumentName Gets/sets the document name to display while printing the document, as in a print status dialog box or printer queue. PrinterSettings Gets/sets the printer that prints the document. Events of ColorDialog Method Means Print Prints the document. Events of ColorDialog Event Means BeginPrint Happens when the Print method is called to start a print job. EndPrint Happens when the last page of the document has printed. PrintPage Happens for each page to print-you draw the page in this event's handler. QueryPageSettings Happens before each PrintPage event. Code for Print Private Sub MenuItem1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MenuItem1.Click PrintDialog1.Document = PrintDocument1 PrintDialog1.PrinterSettings = PrintDocument1.PrinterSettings PrintDialog1.AllowSomePages = True If PrintDialog1.ShowDialog = DialogResult.OK Then PrintDocument1.PrinterSettings = PrintDialog1.PrinterSettings PrintDocument1.Print() End If End Sub
  • 11. 030010401 BCA 4th Semester Preeti P Bhatt Department of Computer Science, UTU. 11 | P a g e Treeview The tree view control is used to display a hierarchy of nodes (both parent, child). You can expand and collapse these nodes by clicking them. Properties of Treeview Property Means BorderStyle Gets/sets the tree view's border style. CheckBoxes Gets/sets whether checkboxes should be displayed next to tree nodes. Nodes Gets the collection of tree nodes. SelectedNode Gets/sets the node that is selected. TopNode Gets the first visible tree node. Sorted Gets/sets if the tree nodes should be sorted. ShowPlusMinus Gets/sets whether plus-sign (+) and minus-sign (-) buttons are shown next to tree nodes with child tree nodes. LastNode: Gets the last child node NextNode: Gets the next sibling node Methods of Treeview Method Means BeginUpdate Disables redrawing of the tree view. CollapseAll Collapses all nodes. EndUpdate Enables redrawing of the tree view. ExpandAll Expands all the nodes. GetNodeAt Gets the node that is at the given location. GetNodeCount Gets the number of nodes. Events of Treeview Event Means AfterCheck Occurs when a node checkbox is checked. AfterCollapse Occurs when a tree node is collapsed. AfterExpand Occurs when a tree node is expanded. AfterLabelEdit Occurs when a tree node label text is edited. AfterSelect Occurs when a tree node is selected. BeforeCheck Occurs before a node checkbox is checked. BeforeCollapse Occurs before a node is collapsed. BeforeExpand Occurs before a node is expanded. BeforeLabelEdit Occurs before a node label text is edited. BeforeSelect Occurs before a node is selected. ItemDrag Occurs when an item is dragged into the tree view.
  • 12. 030010401 BCA 4th Semester Preeti P Bhatt Department of Computer Science, UTU. 12 | P a g e Code for Treeview • How to add a Root Node TreeView1.Nodes.Add(“Node Name”) TreeView1.Nodes.Add(txtNode.Text) TreeView1.Nodes.Add(InputBox("ENTER NODE NAME")) • How to add a Child node to a selected node TreeView1.SelectedNode.Nodes.Add(“Node Name") TreeView1.SelectedNode.Nodes.Add(txtNode.Text) TreeView1.SelectedNode.Nodes.Add(“InputBox("ENTER NODE NAME"))") • Collapse Selected node TreeView1.SelectedNode.Collapse() • Expand all Node TreeView1.ExpandAll() • Display Selected Node Textbox1.Text = tvdata.SelectedNode.Text ListView If tree views are all about displaying node hierarchies, like the folder hierarchy on a disk, then list views are all about displaying lists of items. You can see a list view in the right pane in the Windows Explorer
  • 13. 030010401 BCA 4th Semester Preeti P Bhatt Department of Computer Science, UTU. 13 | P a g e Properties of ListView Properties Means View  View.LargeIcon : The large icon mode displays large icons (large icons are 32×32 pixels) next to the item text.  View.SmallIcon: The small icon mode is the same except that it displays items using small icons (small icons are 16×16 pixels).  View.List: The list mode displays small icons, always in one column  View.Details: The report mode (also called the details mode) displays items in multiple columns ListItems This contains the items displayed by the control. SelectedItems contains a collection of the items currently selected in the control. MultiSelect The user can select multiple items if the MultiSelect property is set to True. CheckBoxes list views can display checkboxes next to the items, if the CheckBoxes property is set to True. Sorting Sort Item in listbox Activation Property sets what action the user must take to activate an item in the list:  OneClick requires a single click to activate the item.  TwoClick requires the user to double-click (a single click changes the color of the item text).  Standard requires the user to double-click to activate an item (but in this case, the item does not change appearance). Methods of ListView Method Means ArrangeIcons Arranges the displayed items in Large Icon or Small Icon view. BeginUpdate Stops the list view from redrawing. Clear Removes all items from the list view. EndUpdate Allows redrawing of the list view. EnsureVisible Makes sure that an item is visible. GetItemAt Gets the item corresponding to the given X, Y coordinate. Events of ListView Events Means AfterLabelEdit Occurs when a label has been edited. BeforeLabelEdit Occurs before a label is changed. ColumnClick Occurs when a column is clicked. ItemActivate Occurs when an item is activated. ItemCheck Occurs when an item is checked. SelectedIndexChanged Occurs when the selected index changes.
  • 14. 030010401 BCA 4th Semester Preeti P Bhatt Department of Computer Science, UTU. 14 | P a g e ListView Item The items in a list view are objects of the ListViewItem class, and the collection of those items is stored in the list view's Items property. Property Means Bounds Gets the bounding rectangle of an item, including its subitems. Checked True if the item is checked, False otherwise. Index Gets the index in the list view of the item. ListView Gets the list view that contains this item. Selected Gets/sets if the item is selected. SubItems Gets a collection of the subitems of this item. Text Gets the text for this item. Creating ListView in code Private Sub Form1_Load(ByVal eventSender As System.Object, _ ByVal eventArgs As System.EventArgs) Handles MyBase.Load ListView1.Columns.Add("Name", ListView1.Width / 4, _ HorizontalAlignment.Left) ListView1.Columns.Add("Date Modified", ListView1.Width / 4, _ HorizontalAlignment.Left) ListView1.Columns.Add("Type", ListView1.Width / 4, _ HorizontalAlignment.Left) Dim ListItem1 As ListViewItem ListItem1 = ListView1.Items.Add("Picture", 1) ListView1.Items(0).SubItems.Add("12-12-2012") ListView1.Items(0).SubItems.Add("Library") Dim ListItem2 As ListViewItem ListItem2 = ListView1.Items.Add("Document", 1) ListView1.Items(1).SubItems.Add("13-12-2012") ListView1.Items(1).SubItems.Add("Library") Dim ListItem3 As ListViewItem ListItem2 = ListView1.Items.Add("Music", 1) ListView1.Items(2).SubItems.Add("1-1-2012") ListView1.Items(2).SubItems.Add("Library") ListView1.SmallImageList = ImageList1 ListView1.LargeImageList = ImageList2 End Sub
  • 15. 030010401 BCA 4th Semester Preeti P Bhatt Department of Computer Science, UTU. 15 | P a g e Code for Sorting ListView1.Sorting = SortOrder.Ascending Change view on basis of combobox Value Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged If ComboBox1.SelectedItem = "Detail" Then ListView1.View = View.Details ElseIf ComboBox1.SelectedItem = "LargeIcon" Then ListView1.View = View.LargeIcon ElseIf ComboBox1.SelectedItem = "SmallIcon" Then ListView1.View = View.SmallIcon ElseIf ComboBox1.SelectedItem = "List" Then ListView1.View = View.List ElseIf ComboBox1.SelectedItem = "Tile" Then ListView1.View = View.Tile End If End Sub