SlideShare ist ein Scribd-Unternehmen logo
1 von 5
Putting Dialog Boxes to Work

We will work with OpenFile, SaveFile, Font and Color Dialog's in this section. From the toolbox
drag a MainMenu component, RichTextBox control, Button Control, OpenFileDialog,
SaveFileDialog, FontDialog and ColorDialog onto the form. The sample code demonstrated
below allows you to select a file to be opened and displays it in the RichTextBox with
OpenFileDialog, allows you to save the text you enter in the RichTextBox to a location using the
SaveFileDialog, allows you to select a font and applies the selected font to text in the RTB
using FontDialog and allows you to select a color and applies the color to text in the RTB using
the ColorDialog. Select the MainMenu component and in the "Type Here" part of the MainMenu
type File and using the down arrow keys on the keyboard start typing Open, Save, SelectFont
and SelectColor under the File menu. It should look like this: File-> Open, Save, SelectFont,
SelectColor. We will assign OpenFileDialog to Open, SaveFileDialog to Save, FontDialog to
SelectFont and ColorDialog to SelectColor under File Menu. The form in design view should
look similar to the image below.




Before proceeding further you need to set properties for these dialogs in their properties window.
They are listed below.
For OpenFileDialog1, set the DefaultExt property to txt so that it opens text files, InitialDirectory
property to C:, RestoreDirectory propery to True and the Text property to Open File From.

For SaveFileDialog1, set the DefaultExt property to txt so that it saves files in text format,
InitialDirectory property to C: so that when you save a file, it first provides C: drive as the choice
of location, OverwritePrompt property to False, RestoreDirectory propery to True and the Text
property to Save File In.

For FontDialog1, set the AllowSimulations, AllowVectorFonts, AllowverticalFonts properties to
false, MaxSize to 50, MinSize to 5 and ShowApply and ShowColor properties to True.

For ColorDialog1, set AnyColor and SolidColorOnly properties to True.

Code

Imports System.IO
Public Class Form1 Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

#End Region

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As_
System.EventArgs) Handles Button1.Click
RichTextBox1.Text = " "
'clears the text in richtextbox
End Sub

Private FileName As String
'declaring filename that will be selected
Dim sr As StreamReader
'streamreader is used to read text

Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e
As_
System.EventArgs) Handles MenuItem2.Click
Try
With OpenFileDialog1
'With statement is used to execute statements using a particular object, here,_
'OpenFileDialog1
.Filter = "Text files (*.txt)|*.txt|" & "All files|*.*"
'setting filters so that Text files and All Files choice appears in the Files of
Type box
'in the dialog
If .ShowDialog() = DialogResult.OK Then
'showDialog method makes the dialog box visible at run time
FileName = .FileName
sr = New StreamReader(.OpenFile)
'using streamreader to read the opened text file
RichTextBox1.Text = sr.ReadToEnd()
'displaying text from streamreader in richtextbox
End If
End With
Catch es As Exception
MessageBox.Show(es.Message)
Finally
If Not (sr Is Nothing) Then
sr.Close()
End If
End Try
End Sub

Private Sub MenuItem3_Click(ByVal sender As System.Object, ByVal e
As_
System.EventArgs) Handles MenuItem3.Click
Dim sw As StreamWriter
'streamwriter is used to write text
Try
With SaveFileDialog1
.FileName = FileName
.Filter = "Text files (*.txt)|*.txt|" & "All files|*.*"
If .ShowDialog() = DialogResult.OK Then
FileName = .FileName
sw = New StreamWriter(FileName)
'using streamwriter to write text from richtextbox and saving it
sw.Write(RichTextBox1.Text)
End If
End With
Catch es As Exception
MessageBox.Show(es.Message)
Finally
If Not (sw Is Nothing) Then
sw.Close()
End If
End Try
End Sub

Private Sub MenuItem4_Click(ByVal sender As System.Object, ByVal e
As_
System.EventArgs) Handles MenuItem4.Click
Try
With FontDialog1
.Font = RichTextBox1.Font
'initializing the dialog box to match the font used in the richtextbox
.Color = RichTextBox1.ForeColor
'default color is Black
If .ShowDialog = DialogResult.OK Then
setFont()
'calling a method setFont() to set the selected font and color
End If
End With
Catch es As Exception
MessageBox.Show(es.Message)
End Try
End Sub

Private Sub setFont()
Try
With FontDialog1
RichTextBox1.Font = .Font
If .ShowColor Then
RichTextBox1.ForeColor = .Color
'setting the color
End If
End With
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub

Private Sub MenuItem5_Click(ByVal sender As System.Object, ByVal e As
_
System.EventArgs) Handles MenuItem5.Click
Static CustomColors() As Integer = {RGB(255, 0, 0), RGB(0, 255, 0),
RGB(0, 0, 255)}
'initializing CustomColors with an array of integers and putting Red, Green,
'and Blue in the custom colors section
Try
With ColorDialog1
.Color = RichTextBox1.ForeColor
'initializing the selected color to match the color currently used
'by the richtextbox's foreground color
.CustomColors = CustomColors
'filling custom colors on the dialog box with the array declared above
If .ShowDialog() = DialogResult.OK Then
RichTextBox1.ForeColor = .Color
CustomColors = .CustomColors
'Storing the custom colors to use again
End If
ColorDialog1.Reset()
'resetting all colors in the dialog box
End With
Catch es As Exception
MessageBox.Show(es.Message)
End Try
End Sub

End Class

Weitere ähnliche Inhalte

Andere mochten auch

A to z of stress management 1
A to z of stress management 1A to z of stress management 1
A to z of stress management 1pgujar
 
A day in the life of a future teacher
A day in the life of a future teacherA day in the life of a future teacher
A day in the life of a future teacherdanienem
 
Happy Birthday !!!
Happy Birthday !!!Happy Birthday !!!
Happy Birthday !!!Alin Armanca
 
ไขมัน
ไขมันไขมัน
ไขมันjunnanta
 
orkunn
orkunnorkunn
orkunnorkenn
 
Meta análise– veda1
Meta análise– veda1Meta análise– veda1
Meta análise– veda1souzadea1
 
Scrum gathering 2012 shanghai_ 敏捷测试与质量管理分会场演讲话题:快速可持续的高质量发布(路宁)
Scrum gathering 2012 shanghai_ 敏捷测试与质量管理分会场演讲话题:快速可持续的高质量发布(路宁)Scrum gathering 2012 shanghai_ 敏捷测试与质量管理分会场演讲话题:快速可持续的高质量发布(路宁)
Scrum gathering 2012 shanghai_ 敏捷测试与质量管理分会场演讲话题:快速可持续的高质量发布(路宁)jalamar
 
How to drink water for better heath
How to drink water for better heath How to drink water for better heath
How to drink water for better heath vikas_deshpande
 
White paper blackmoney2012
White paper blackmoney2012White paper blackmoney2012
White paper blackmoney2012vikas_deshpande
 

Andere mochten auch (15)

A to z of stress management 1
A to z of stress management 1A to z of stress management 1
A to z of stress management 1
 
A day in the life of a future teacher
A day in the life of a future teacherA day in the life of a future teacher
A day in the life of a future teacher
 
Happy Birthday !!!
Happy Birthday !!!Happy Birthday !!!
Happy Birthday !!!
 
Arrive alive
Arrive aliveArrive alive
Arrive alive
 
ไขมัน
ไขมันไขมัน
ไขมัน
 
_
  _  _
_
 
Four squares
Four squaresFour squares
Four squares
 
Sanskrit bharati course
Sanskrit bharati courseSanskrit bharati course
Sanskrit bharati course
 
orkunn
orkunnorkunn
orkunn
 
Meta análise– veda1
Meta análise– veda1Meta análise– veda1
Meta análise– veda1
 
Scrum gathering 2012 shanghai_ 敏捷测试与质量管理分会场演讲话题:快速可持续的高质量发布(路宁)
Scrum gathering 2012 shanghai_ 敏捷测试与质量管理分会场演讲话题:快速可持续的高质量发布(路宁)Scrum gathering 2012 shanghai_ 敏捷测试与质量管理分会场演讲话题:快速可持续的高质量发布(路宁)
Scrum gathering 2012 shanghai_ 敏捷测试与质量管理分会场演讲话题:快速可持续的高质量发布(路宁)
 
How to drink water for better heath
How to drink water for better heath How to drink water for better heath
How to drink water for better heath
 
White paper blackmoney2012
White paper blackmoney2012White paper blackmoney2012
White paper blackmoney2012
 
AT89 S52
AT89 S52AT89 S52
AT89 S52
 
Factores inseguridad
Factores inseguridadFactores inseguridad
Factores inseguridad
 

Ähnlich wie Putting dialog boxes to work

Código Editor Net
Código Editor NetCódigo Editor Net
Código Editor Netcymbron
 
Delphi L05 Files and Dialogs
Delphi L05 Files and DialogsDelphi L05 Files and Dialogs
Delphi L05 Files and DialogsMohammad Shaker
 
Apply Bold, Italic and Underline to Selected Text in a RichtextBox using Visu...
Apply Bold, Italic and Underline to Selected Text in a RichtextBox using Visu...Apply Bold, Italic and Underline to Selected Text in a RichtextBox using Visu...
Apply Bold, Italic and Underline to Selected Text in a RichtextBox using Visu...Daniel DotNet
 
Windows Forms For Beginners Part 5
Windows Forms For Beginners Part 5Windows Forms For Beginners Part 5
Windows Forms For Beginners Part 5Bhushan Mulmule
 
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.docxannettsparrow
 
Module 3 open office writer
Module 3 open office writerModule 3 open office writer
Module 3 open office writerjaimemgarcia
 
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.NetDaniel DotNet
 
C#_hw9_S17.docModify AnimatedBall on Chapter 13. Instead of dr.docx
C#_hw9_S17.docModify AnimatedBall on Chapter 13. Instead of dr.docxC#_hw9_S17.docModify AnimatedBall on Chapter 13. Instead of dr.docx
C#_hw9_S17.docModify AnimatedBall on Chapter 13. Instead of dr.docxRAHUL126667
 
3.1 file input and output
3.1   file input and output3.1   file input and output
3.1 file input and outputallenbailey
 
Membuat aplikasi penjualan buku sederhana
Membuat aplikasi penjualan buku sederhanaMembuat aplikasi penjualan buku sederhana
Membuat aplikasi penjualan buku sederhanaYusman Kurniadi
 
Vb lecture notes
Vb lecture notesVb lecture notes
Vb lecture notesalldesign
 
TM 2nd qtr-3ndmeeting(java script-functions)
TM 2nd qtr-3ndmeeting(java script-functions)TM 2nd qtr-3ndmeeting(java script-functions)
TM 2nd qtr-3ndmeeting(java script-functions)Esmeraldo Jr Guimbarda
 

Ähnlich wie Putting dialog boxes to work (20)

Unit5
Unit5Unit5
Unit5
 
Filehandling
FilehandlingFilehandling
Filehandling
 
VB Dot net
VB Dot net VB Dot net
VB Dot net
 
Código Editor Net
Código Editor NetCódigo Editor Net
Código Editor Net
 
Delphi L05 Files and Dialogs
Delphi L05 Files and DialogsDelphi L05 Files and Dialogs
Delphi L05 Files and Dialogs
 
Apply Bold, Italic and Underline to Selected Text in a RichtextBox using Visu...
Apply Bold, Italic and Underline to Selected Text in a RichtextBox using Visu...Apply Bold, Italic and Underline to Selected Text in a RichtextBox using Visu...
Apply Bold, Italic and Underline to Selected Text in a RichtextBox using Visu...
 
Chapter10
Chapter10Chapter10
Chapter10
 
Windows Forms For Beginners Part 5
Windows Forms For Beginners Part 5Windows Forms For Beginners Part 5
Windows Forms For Beginners Part 5
 
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
 
Module 3 open office writer
Module 3 open office writerModule 3 open office writer
Module 3 open office writer
 
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
 
C#_hw9_S17.docModify AnimatedBall on Chapter 13. Instead of dr.docx
C#_hw9_S17.docModify AnimatedBall on Chapter 13. Instead of dr.docxC#_hw9_S17.docModify AnimatedBall on Chapter 13. Instead of dr.docx
C#_hw9_S17.docModify AnimatedBall on Chapter 13. Instead of dr.docx
 
3.1 file input and output
3.1   file input and output3.1   file input and output
3.1 file input and output
 
Database connectivity with data reader by varun tiwari
Database connectivity with data reader by varun tiwariDatabase connectivity with data reader by varun tiwari
Database connectivity with data reader by varun tiwari
 
Membuat aplikasi penjualan buku sederhana
Membuat aplikasi penjualan buku sederhanaMembuat aplikasi penjualan buku sederhana
Membuat aplikasi penjualan buku sederhana
 
Chapter 11
Chapter 11Chapter 11
Chapter 11
 
WPF Application
WPF ApplicationWPF Application
WPF Application
 
Vb lecture notes
Vb lecture notesVb lecture notes
Vb lecture notes
 
TM 2nd qtr-3ndmeeting(java script-functions)
TM 2nd qtr-3ndmeeting(java script-functions)TM 2nd qtr-3ndmeeting(java script-functions)
TM 2nd qtr-3ndmeeting(java script-functions)
 
Python IO
Python IOPython IO
Python IO
 

Kürzlich hochgeladen

State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!Memoori
 
AI mind or machine power point presentation
AI mind or machine power point presentationAI mind or machine power point presentation
AI mind or machine power point presentationyogeshlabana357357
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...CzechDreamin
 
Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024Patrick Viafore
 
TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024Stephen Perrenod
 
Portal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russePortal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russe中 央社
 
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...FIDO Alliance
 
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...FIDO Alliance
 
Using IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & IrelandUsing IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & IrelandIES VE
 
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdfWhere to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdfFIDO Alliance
 
Powerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaPowerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaCzechDreamin
 
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...FIDO Alliance
 
AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101vincent683379
 
Your enemies use GenAI too - staying ahead of fraud with Neo4j
Your enemies use GenAI too - staying ahead of fraud with Neo4jYour enemies use GenAI too - staying ahead of fraud with Neo4j
Your enemies use GenAI too - staying ahead of fraud with Neo4jNeo4j
 
Designing for Hardware Accessibility at Comcast
Designing for Hardware Accessibility at ComcastDesigning for Hardware Accessibility at Comcast
Designing for Hardware Accessibility at ComcastUXDXConf
 
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...CzechDreamin
 
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfLinux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfFIDO Alliance
 
WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024Lorenzo Miniero
 
ECS 2024 Teams Premium - Pretty Secure
ECS 2024   Teams Premium - Pretty SecureECS 2024   Teams Premium - Pretty Secure
ECS 2024 Teams Premium - Pretty SecureFemke de Vroome
 
Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform EngineeringMarcus Vechiato
 

Kürzlich hochgeladen (20)

State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!
 
AI mind or machine power point presentation
AI mind or machine power point presentationAI mind or machine power point presentation
AI mind or machine power point presentation
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
 
Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024
 
TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024
 
Portal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russePortal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russe
 
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
 
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
 
Using IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & IrelandUsing IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & Ireland
 
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdfWhere to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
 
Powerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaPowerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara Laskowska
 
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
 
AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101
 
Your enemies use GenAI too - staying ahead of fraud with Neo4j
Your enemies use GenAI too - staying ahead of fraud with Neo4jYour enemies use GenAI too - staying ahead of fraud with Neo4j
Your enemies use GenAI too - staying ahead of fraud with Neo4j
 
Designing for Hardware Accessibility at Comcast
Designing for Hardware Accessibility at ComcastDesigning for Hardware Accessibility at Comcast
Designing for Hardware Accessibility at Comcast
 
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
 
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfLinux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
 
WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024
 
ECS 2024 Teams Premium - Pretty Secure
ECS 2024   Teams Premium - Pretty SecureECS 2024   Teams Premium - Pretty Secure
ECS 2024 Teams Premium - Pretty Secure
 
Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform Engineering
 

Putting dialog boxes to work

  • 1. Putting Dialog Boxes to Work We will work with OpenFile, SaveFile, Font and Color Dialog's in this section. From the toolbox drag a MainMenu component, RichTextBox control, Button Control, OpenFileDialog, SaveFileDialog, FontDialog and ColorDialog onto the form. The sample code demonstrated below allows you to select a file to be opened and displays it in the RichTextBox with OpenFileDialog, allows you to save the text you enter in the RichTextBox to a location using the SaveFileDialog, allows you to select a font and applies the selected font to text in the RTB using FontDialog and allows you to select a color and applies the color to text in the RTB using the ColorDialog. Select the MainMenu component and in the "Type Here" part of the MainMenu type File and using the down arrow keys on the keyboard start typing Open, Save, SelectFont and SelectColor under the File menu. It should look like this: File-> Open, Save, SelectFont, SelectColor. We will assign OpenFileDialog to Open, SaveFileDialog to Save, FontDialog to SelectFont and ColorDialog to SelectColor under File Menu. The form in design view should look similar to the image below. Before proceeding further you need to set properties for these dialogs in their properties window. They are listed below.
  • 2. For OpenFileDialog1, set the DefaultExt property to txt so that it opens text files, InitialDirectory property to C:, RestoreDirectory propery to True and the Text property to Open File From. For SaveFileDialog1, set the DefaultExt property to txt so that it saves files in text format, InitialDirectory property to C: so that when you save a file, it first provides C: drive as the choice of location, OverwritePrompt property to False, RestoreDirectory propery to True and the Text property to Save File In. For FontDialog1, set the AllowSimulations, AllowVectorFonts, AllowverticalFonts properties to false, MaxSize to 50, MinSize to 5 and ShowApply and ShowColor properties to True. For ColorDialog1, set AnyColor and SolidColorOnly properties to True. Code Imports System.IO Public Class Form1 Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code " #End Region Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As_ System.EventArgs) Handles Button1.Click RichTextBox1.Text = " " 'clears the text in richtextbox End Sub Private FileName As String 'declaring filename that will be selected Dim sr As StreamReader 'streamreader is used to read text Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As_ System.EventArgs) Handles MenuItem2.Click Try With OpenFileDialog1 'With statement is used to execute statements using a particular object, here,_ 'OpenFileDialog1 .Filter = "Text files (*.txt)|*.txt|" & "All files|*.*" 'setting filters so that Text files and All Files choice appears in the Files of Type box 'in the dialog If .ShowDialog() = DialogResult.OK Then 'showDialog method makes the dialog box visible at run time
  • 3. FileName = .FileName sr = New StreamReader(.OpenFile) 'using streamreader to read the opened text file RichTextBox1.Text = sr.ReadToEnd() 'displaying text from streamreader in richtextbox End If End With Catch es As Exception MessageBox.Show(es.Message) Finally If Not (sr Is Nothing) Then sr.Close() End If End Try End Sub Private Sub MenuItem3_Click(ByVal sender As System.Object, ByVal e As_ System.EventArgs) Handles MenuItem3.Click Dim sw As StreamWriter 'streamwriter is used to write text Try With SaveFileDialog1 .FileName = FileName .Filter = "Text files (*.txt)|*.txt|" & "All files|*.*" If .ShowDialog() = DialogResult.OK Then FileName = .FileName sw = New StreamWriter(FileName) 'using streamwriter to write text from richtextbox and saving it sw.Write(RichTextBox1.Text) End If End With Catch es As Exception MessageBox.Show(es.Message) Finally If Not (sw Is Nothing) Then sw.Close() End If End Try End Sub Private Sub MenuItem4_Click(ByVal sender As System.Object, ByVal e As_ System.EventArgs) Handles MenuItem4.Click Try With FontDialog1
  • 4. .Font = RichTextBox1.Font 'initializing the dialog box to match the font used in the richtextbox .Color = RichTextBox1.ForeColor 'default color is Black If .ShowDialog = DialogResult.OK Then setFont() 'calling a method setFont() to set the selected font and color End If End With Catch es As Exception MessageBox.Show(es.Message) End Try End Sub Private Sub setFont() Try With FontDialog1 RichTextBox1.Font = .Font If .ShowColor Then RichTextBox1.ForeColor = .Color 'setting the color End If End With Catch ex As Exception MessageBox.Show(ex.Message) End Try End Sub Private Sub MenuItem5_Click(ByVal sender As System.Object, ByVal e As _ System.EventArgs) Handles MenuItem5.Click Static CustomColors() As Integer = {RGB(255, 0, 0), RGB(0, 255, 0), RGB(0, 0, 255)} 'initializing CustomColors with an array of integers and putting Red, Green, 'and Blue in the custom colors section Try With ColorDialog1 .Color = RichTextBox1.ForeColor 'initializing the selected color to match the color currently used 'by the richtextbox's foreground color .CustomColors = CustomColors 'filling custom colors on the dialog box with the array declared above If .ShowDialog() = DialogResult.OK Then RichTextBox1.ForeColor = .Color CustomColors = .CustomColors 'Storing the custom colors to use again
  • 5. End If ColorDialog1.Reset() 'resetting all colors in the dialog box End With Catch es As Exception MessageBox.Show(es.Message) End Try End Sub End Class