Tuesday, April 30, 2013

Overloading Object oriented programming का एक महत्वपूर्ण feature है जो की किसी procedure के multiple versions बनाने और उन्हे अलग अलग tasks के लिए use करने के सुविधा प्रदान करता है। overloading मे procedure का नाम same होता है इसमे केवल prameteres मे difference होता है जो की उसी procedure को एक ही नाम से अलग अलग प्रकार से task perform करने मे हेल्प करता है। इसका उदेश्य किसी procedure के अलग अलग versions बनाना है जिनके नाम एक ही रहते है। 


Overloading Rules: 


         Overloading करते समय निम्न बातों को ध्यान मे रखना चाहिए। 



  • Same Name: सभी overloaded procedures के नाम same होने चाहिए।


  • Different Signature: सभी overloaded procedures मे निम्न मे से कम से कम एक difference होना चाहिए तभी procedures को overload किया जा सकता है-




  1. Number of Parameters


  2. Order of Parameters


  3. Data Types of Parameters


  4. Number of Type Parameters


  5. Return Type



Ex:



Public Class Shape



Public Function Area(ByVal radius As Double) As Double



Return Math.PI * radius * radius



End Function



Public Function Area(ByVal length As Double, ByVal width As Double) As Double



Return length * width



End Function



Public Function Area(ByVal a As Integer, ByVal b As Integer, ByVal c As Integer) As Double



Dim s As Integer



s = (a + b + c) / 2



Return (Math.Sqrt(s * (s - a) * (s - b) * (s - c)))



End Function



End Class

 Mybase की तरह की यह keyword किसी method को override करने पर derived class की overrided method को कॉल करने के लिए use की जाती है। यह निश्चित कर देती है की call की गई method इसी derived class की overrided method है। 



Public Overrides Function Area() As Double



Return ((Math.PI * Radius * MyClass.length) + MyBase.Area())



End Function




Limitations of MyClass keyword: 



  • MyClass real object नहीं है इसीलिए इसके द्वारा variable मे value को assign, procedure मे pass etc. नहीं कर सकते हैं।


  • Myclass का use केवल उसी क्लास के members के लिए किया जा सकता है।


  • Myclass को standard modules मे use नहीं कर सकते हैं।


  • Myclass को ऐसे methods के साथ नहीं use किया जा सकता है जो की base class से override नहीं की जा सकती है।

Monday, April 29, 2013

 Mybase keyword inheritance मे base class की overrided method को call करने के लिए use की जाती है। जब inheritance करते समय कभी भी base class की overrided method की आवश्यकता पड़ती है तब mybase keyword का use कर use call कर सकते हैं। जैसे given example मे जब Circle के area calculate किया जाता है साथ ही जब Cone का area calculate करते है तब Circle class के area को override करने के आवश्यकता पड़ती है इसमे base class (Circle) के area method को कॉल करने के लिए mybase का use किया जाता है।
 
Circle.vb

Public Class Circle
    Private cradius As Double
    Public Property Radius() As Double
        Get
            radius = cradius
        End Get
        Set(ByVal value As Double)
            If value < 0 Then
                msgbox("Wrong Input:")
            Else
                cradius = value
            End If
        End Set
    End Property

    Public Overridable Function Area() As Double
        Return Math.PI * Radius ^ 2
    End Function

  
End Class
Cone.vb 
Public Class Cone
    Inherits Circle
    Dim l As Double
    Public Property length() As Double
        Get
            length = l
        End Get
        Set(ByVal value As Double)
            l = value
        End Set
    End Property
    Public Overrides Function Area() As Double
        Return ((Math.PI * Radius * length) + MyBase.Area())
    End Function

End Class


Limitations of MyBase keyword: 
  • Mybase keyword केवल immediate base class के लिए use की जा सकता है।
  • Mybase real object नहीं है इसीलिए इसके द्वारा variable मे value को assign, procedure मे pass etc. नहीं कर सकते हैं।
  • Mybase को MustOverride base class के लिए use नहीं कर सकते हैं।
  • Mybase base class के अंदर प्रयोग नहीं की जा सकती है।
  • Mybase को friend member के लिए use नहीं किया जा सकता है।

Inheritance Modifiers: 

         Inheritance के लिए Visual basic .Net कुछ class level modifiers provide करता है। 
  • NotInheritable: class को ininheritable बनाने के लिए। ऐसी class को inherite नहीं किया जा सकता हैं।
  • MustInherit: इसका use करने पर class को base class मे use करना अनिवार्य हो जाता है।   इसे केवल base class की तरह ही use किया जा सकता है।
Oerriding Properties and Methods in Derived Class:

         By default derived class base class की सभी properties और methods को inherite कर लेती है। कभी कभी Derived class मे inherite की गई property या method को अलग प्रकार से प्रयोग करने के आवश्यकता पड़ती है ऐसी अवसर पर इसे overriding करना कहलाता है। इसके लिए VB।Net Base class और Derived class दोनों में use होने वाली properties और methods के लिए कुछ modifiers प्रदान करता है जिनहे प्रयोग कर किसी भी method आदि की overriding को control कर सकते हैं। जो निम्नलिकीहित हैं। 

For Properties and methods of Base Class: 
  • Overridable: इसका use करने पर property या method को override किया जा सकता है।
  • NotOverridable: इसका use करने पर property या method को override नहीं किया जा सकता है।
  • MustOverride: इसका use करने पर property या method को override करना अनिवार्य हो जाता है।
For Properties and methods of Derived Class: 
  • Overrides: यह overridable property या method को override करते समय प्रयोग की जाती है।

VB.net मे सभी classes को inherite किया जा सकता है। लेकिन ऐसी सभी classes जिनमें की       NotInheritable keyword का use किया गया है inherite नहीं की जा सकती हैं। 
  • Classes को other projects से भी inherite किया जा सकता है।
  • VB.Net केवल Single और Multilevel inheritance को support करती है।
  • Inheritance करने के लिए Base और Derieved class दोनों के access type equal होने चाहिए तभी inheritance possible है।
 

 Inheritance VB.Net का एक महत्वपूर्ण feature है जो कि एक class को किसी अन्य class के features को use करने के facility provide करता है। यह पहले से बनी हुई class पर based नई class बनाने की सुविधा देता है। यह reusability को support करता हैं जहां किसी feature को जोड़ने या पुराने class के features को use करने के लिए उन्हे फिर से नहीं बनाना पड़ता है उन्हे inheritance के द्वारा पुरानी class से inherite कर नई class मे add कर लेते हैं। inherite कि जाने वाली class को base-class या parent class और inherite करने वाली class को derived या child class कहते हैं। 
Inheriting a Class: 
         Derived class मे base class को inherite करने के लिए Inherits keyword का use कर base class का नाम define कर देते हैं। inherite करने के बाद base class की सभी properties, methods, events, fields और constants को derived class मे use किया जा सकता है। 

DerivedCircle.vb

Public Class DerivedCircle    Inherits Circle     Public Function Circumfrence() As Double        Return 2 * math.pi * radius    End FunctionEnd Class
 
Form4.vb 
Public Class Form4
     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click        Dim dc As New DerivedCircle        dc.Radius = Val(TextBox1.Text)        MsgBox("Area = " & dc.Area)        MsgBox("Circumfrence =" & dc.Circumfrence)    End Sub
  
End Class

Constructors:

किसी object को declare करते समय उसे construct करते समय new keyword का use कर उसका नया instance create किया जाता है। जब किसी class के object को declare करते है तब new keyword object का नया instance बनाने के लिए प्रयोग होता है। Constructors ऐसे member functions हैं जो कि किसी भी नए object मे fields और properties को initialize करने के लिए use किए जाते हैं। जब object को create करने के लिए new keyword का use करते है तब यह automatically call होकर properties को initialize कर देते हैं।

किसी भी class मे multiple contructores को भी use किया जा सकता है। जिसमे एक default और कई parameterized contructors हो सकते हैं। 


Constructors new subroutine के द्वारा implement किए जाते हैं। यह constructor object के new instance create होने पर automatically call हो जाते हैं। constructor बनाने के लिए Class मे कहीं भी new subroutine को define कर किया जाता है। parameterized contructor के लिए उसमें arguments को भी define कर दिया जाता है। 


 



Public Class Circle


Public Sub New()



Radius = 0



End Sub



Public Sub New(ByVal R As Double)



Radius = R



End Sub



End Class



 


इस प्रकार object को declare करने पर constructor automentic call हो जाएगा और value initialize हो जाएगी। 



Dim c As New Circle(10)

Methods: 


Methods object द्वारा perform किए जाने वाले actions को represent करते हैं। methods functions को ही कहा जाता है। इन्हे किसी special task को perform करने के लिए use किया जाता है। यह किसी भी problem को devide कर उसे easy बना देते हैं। 



<Access modifier> Function <Function Name> ([arguments]) As <Return Type>





[Function’s statements]





Return <returning value>





End Function




Ex:




Public Function Area() As Double



Return math.pi * radius ^ 2



End Function

 Properties: 


    Properties class मे use होने वाली fields की तरह होती हैं। लेकिन इन्हे Get और Set property के द्वारा implement किया जाता है। जो की data को control कर input और output को कंट्रोल किया जाता है। इसमें data को set करते समय उसे verify भी किया जा सकता है। 


         Set Section data को property मे set करते समय use होता है। और Get Section data को property से retrieve करते समय invoke होता है। property मे value को pass करते समय उसे Set section मे verify किया जा सकता है। data के valid होने पर उसे local field मे store का देते है । इसी प्रकार data को get करने के लिए उसी variable के द्वारा value return कर दी जाती है। जैसे previous example मे Radius एक property है। property को निम्न प्रकार से declare करते हैं। 


Syntax:



<access_specifier> [Readonly] property <property_name> () As <Type>



Get



[Statements]



End Get



Set (Byval Value As <Type>)



[Statements]



End Set



End Property




Exp:



Public Property Radius() As Double



Get



radius = cradius



End Get



Set(ByVal value As Double)



If value < 0 Then



msgbox("Wrong Input:")



Else



cradius = value



End If



End Set



End Property

Fields: 


Classes fields, properties, methods और events से मिलकर बनती है। यह सभी object information को contain करती है। Fields class मे use होने वाले variables को कहते है। जिसमें value को directly read और write किया जा सकता है। Fields को normal variables की तरह ही declare किया जाता है। इन्हे member variables भी कहते हैं जो कि data को handle करने कि लिए किया जाता है। Previous program मे cradius field है। 



Private cradius As Double

Objects run-time entity हैं जो की class को run करने के लिए use की जाती है। class के variable को ही object कहा जाता है। यह run होकर class के data को store और use class के functions के द्वारा process करता है। इसके create होने पर यह memory मे space लेता है और delete होने पर यह space system को वापस हो जाता है। VB.Net मे object को declare करने के लिए variable declaration statement का use new keyword किया जाता है। 




Syntax




Dim <obj_name> As New Class_Name



Or



Dim <Obj_Name> As Class_Name = New Class_Name





Ex:     




Dim cir As New Circle




               Or 




Dim cir As Circle = New Circle 

Friday, April 26, 2013

Circle.cs

image087
Public Class Circle
    Private cradius As Double
    Public Property Radius() As Double
        Get
            radius = cradius
        End Get
        Set(ByVal value As Double)
            If value < 0 Then
                msgbox("Wrong Input:")
            Else
                cradius = value
            End If
        End Set
    End Property
 
    Public Function Area() As Double
        Return math.pi * radius ^ 2
    End Function
 
    Public Function Circumfrence() As Double
        Return 2 * math.pi * radius
    End Function
End Class




 









Public Class Form4


 


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click


        Dim c As New circle


        c.Radius = Val(TextBox1.Text)


        MsgBox("Area = " & c.Area)


        MsgBox("Circumfrence =" & c.Circumfrence)


    End Sub


 



End Class

VB.Net एक Object oriented programming language है इसलिए यह इसके सभी features को support करती है। जो निम्न हैं-

  1. Class: class एक user defined data type है जो की data और functions को contain करता है। इसका कोई visible interface नहीं होता है और न ही ये खुद से run हो सकती हैं। VB.Net मे Class fields, properties, methods और events को contain करती है।

Building a Class: VB.Net मे class बनाने के लिए यह Class Library project provide करता है। जिसका use कर class का collection बनाया जा सकता है। इसके अलावाWindows Application project मे भी Class Files को add कर use किया जा सकता है। इसके लिए सर्वप्रथम एक windows application project create कर लेते हैं। इसके बाद Project menu मे जाकर Add New Windows Form या Add Class select करते हैं। इसके बाद डिस्प्ले होने वाले New Item Dialog box मे Class templet को selectकरते हैं। और file का नाम enter कर Add button पर click करते है। इसके बाद Project मे एक class file add हो जाती है और class declare हो जाती है।

image084

image085

 

Class Declaration Syntax:

[Access_Modifier] [MustInherit | NotInheritable] Class <Class_Name>


        [Inherits <Base_Class_Name>]


        [Statements]


End Class



Access_Modifier: Optional. Can be one of the following:





MultiInherit / NotInheritable: Optional, Define class can be inherited or Not.


Class: Keyword, Define Class


Class_Name: Name of the Class


Inherits: used when Inheritance is used


Base_Class_Name: Name of base class at inheritance



image086

  1. Object: यह OOPs की basic run-time entity है। जो कि किसी object (person, place, a bank account etc.) को represent करता है। object class का variable है जो कि class को execute करता है और उसमे उपलब्ध methods को use कर डाटा को process करता है। object के create होने पर यह memory मे अन्य variables की तरह ही space लेता है।
  2. Class : Class एक user defined data type है जो कि data और code को contain करता है जो कि object द्वारा use किया जाता है। class एक structure है जो किobject कि working को define करता है। class को create करने के बाद उसके कई objects बनाए जा सकते हैं। इस प्रकार कहा जा सकता है कि class एक ही प्रकार केobjects का collection है।
  3. Data Abstraction and Encapsulation: data और functions को एक साथ bind करना Encapsulation कहलाता है। यह class का सबसे important feature है। इसमे डाटा को class के बाहर access नहीं किया जा सकता है केवल class के functions ही इसे access कर सकते है। data abstraction बिना background process कीdetails के data को input और output करने से है जिसमे यह Class के functions के द्वारा perform होता है।
  4. Inheritance: यह OOPs का एक महत्वपूर्ण feature है जो कि एक class को दूसरी class के features को access करने की facility provide करता है। इसमे एक classका object अन्य class की properties को भी access कर use कर सकता है। यह reuseability के feature को implement करता है जहां किसी class मे नए features कोadd करने के लिए नई class बनाकर उसमें पुरानी class के features को भी implement किया जाता है साथ ही नई class मे और codes भी जोड़ दिये जाते हैं।
  5. Polymorphism: यह भी OOPs का important concept है जो की एक से अधिक form को बनाकर उसे use करने की facility देता है। यह Function और operators दोनों के द्वारा perform किया जाता है जहां function name या operator वही रहता है पर arguments की संख्या या type या operands के type अलग होने पर अलग प्रकार से useहोते है और task को perform करते हैं। जैसे + operator numenrical addition और strings को जोड़ने के लिये use होता हैं।
  6. Dynamic Binding: OOPs मे inheritance और polymorphism इस feature को implement करते हैं जिसमें Binding या linking procedure के call होने पर perform होते हैं। इसे dynamic binding कहते हैं।
  7. Message Passing: OOPs मे objects परस्पर communicate करते हैं। objects information को send और receive कर communication करते हैं। OOPs मे message passing function call के समय perform होता है। जिसमें information function argument के रूप में function के माध्यम से object मे input होता है और object कीmethod उसे process कर result generate का देती है।

Programming मे दो प्रकार के program paradigm का use किया जाता है। यह Procedure Oriented और Object oriented programming हैं। नए समय की सभी programming languages Object oriented programming को use करती हैं। OOPs एक software development paradigm है जो कि procedure oriented approach मे आने वाले problems कोsolve करने के लिए किया जाता है। Object oriented programming, Data को program development के दौरान system मे flow नहीं होने देता। यह इसे किसी भी other functionके द्वारा अचानक change होने से रोकता है। इसमे problem को object के द्वारा solve किया जाता है और data और function object के साथ काम करते हैं। object के data को केवल object का function ही access कर सकता है। इस प्रकार कहा जा सकता है कि Object oriented programming एक ऐसी programming approach है जिसमे data औरfuncitons को एक साथ bind कर दिया जाता है जिसे class कहते हैं और उसे objects के द्वारा use किया जाता है। जहां प्रत्येक object के लिए उसके data और functions अलग अलग store और process होते हैं। यहा object के लिए memory space allocate होता है जिसमे उसका data और functions store होते हैं।

Features of Object Oriented Programming:

  1. Object
  2. Class
  3. Data abstraction and encapsulation
  4. Inheritance
  5. Polymorphism
  6. Dynamic Binding
  7. Message Passing

             यह Label की तरह का ही होता है लेकिन यह HTML मे दी जाने वाली Links की तरह होता है जिसमे click करने पर कोई page open होता है। इसी प्रकार इसमे भीclick करने पर यह किसी page से लिंक होती है। इसमे label control की सभी properties use होती हैं इसके अलावा इसमे कुछ अन्य properties भी होती हैं।

  • LinkColor: इसका use link का color get और set करने के लिए किया जाता हैं।
  • VisitedLinkColor: इसका use visite की गई Link का color set या get करने के लिए किया जाता हैं।
  • ActiveLinkColor: इसका use activate link का color get या set करने के लिए किया जाता है।

Events: सभी common events इसमे use की जा सकती हैं। इसकी main event LinkClicked होती है जो निम्न है-

  • LinkClicked: यह linklabel पर click करने पर perform होती है।

image083

Public Class Form4

Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e AsSystem.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked

System.Diagnostics.Process.Start("http://www.google.co.in")

End Sub

End Class

Thursday, April 25, 2013

Open, Save, Color, Font and Print Dialog Controls
image082

Imports System.IO
Public Class Dialogss

    Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        OpenFileDialog1.Title = "Select File to open"
        OpenFileDialog1.Filter = "Text File|*.txt|All Files|*.*"
        OpenFileDialog1.FilterIndex = 1
        OpenFileDialog1.CheckFileExists = True
        OpenFileDialog1.CheckPathExists = True
        OpenFileDialog1.InitialDirectory=My.Computer.FileSystem.SpecialDirectories.MyDocuments
        OpenFileDialog1.Multiselect = False
        OpenFileDialog1.ShowHelp = True
        Dim rfile As StreamReader
        If OpenFileDialog1.ShowDialog = MsgBoxResult.OK Then
            rfile = New StreamReader(OpenFileDialog1.FileName)
            Me.TextBox1.Text = rfile.ReadToEnd
        End If

    End Sub

    Private Sub Button2_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        SaveFileDialog1.Title = "Save File"
        SaveFileDialog1.Filter = "Text Files|*.txt|All Files|*.*"
        SaveFileDialog1.AddExtension = True
        SaveFileDialog1.DefaultExt = "txt"
        Dim wfile As StreamWriter
        If SaveFileDialog1.ShowDialog = MsgBoxResult.Ok Then
            wfile = New StreamWriter(SaveFileDialog1.FileName)
            wfile.Write (Me.TextBox1.Text)
            wfile.Close ()
        End If
    End Sub

    Private Sub Button3_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        ColorDialog1.AllowFullOpen = True
        ColorDialog1.FullOpen = True
        If ColorDialog1.ShowDialog = MsgBoxResult.Ok Then
            Me.TextBox1.ForeColor = ColorDialog1.Color
        End If
    End Sub

    Private Sub Button4_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        FontDialog1.ShowEffects = True
        FontDialog1.ShowApply = True
        If FontDialog1.ShowDialog = MsgBoxResult.Ok Then
            Me.TextBox1.Font = FontDialog1.Font
        End If
    End Sub

    Private Sub Button5_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        PrintDialog1.AllowPrintToFile = True
        PrintDialog1.AllowSelection = True
        Dim pd As New Printing.PrintDocument

        PrintDialog1.Document = New Printing.PrintDocument
        If PrintDialog1.ShowDialog = MsgBoxResult.Ok Then
            pd.Print()
        End If
    End Sub
End Class

         इसका use Print Dialog box को display करने के लिए किया जाता है। यह सबसे important dialog control है क्योकि अधिकतर windows application documents को print करते है। अतः printing मे इसका use किया जाता है। यह dialog box printing के सभी option automatically provide करता है। इसमे printer, pages, print size, printtype etc. सभी को set किया जा सकता है। इसे use करने से पहले form मे place किया जाता है। या runtime मे इसे form पर add कर लिया जाता है। इसेshow करने के लिए ShowDialog method का use किया जाता है। इसके properties निम्न हैं।

image081

  • Name: इसका use control का name define किया जाता है। जो dialog को codes मे identify करता है।
  • AllowPrintToFile: इसके ture होने पर print to file check box enable हो जाता है।
  • AllowSelection: इसके property के ture होने पर pages select करने के लिए Radio buttons enable हो जाती हैं।
  • AllowSomePages: इसके ture होने पर user file मे से केवल कुछ pages को select करने भी print कर सकता है।
  • Documents: इसका use print किए जाने वाले document को set करने के लिए किया जाता है।
  • PrintToFile: इसके ture होने पर print To file checkbox checked भी रहेगा।
  • ShowHelp: इसके ture होने पर Print dialog box मे help button भी display होती है।
  • ShowNetwork: इसके True होने पर Network button display होती है। जिससे network मे लगे printer को भी access किया जा सकता है।

      Color dialog control का use color dialog box को display करने के लिए किया जाता है। यह dialogbox color को select करने और colors को मिलाकर नए colours बनाने की facility देता है। यह भी dialog controls की category के अंदर Toolbox मे पाया जाता है। इसे display करने के लिए ShowDialog control काuse किया जाता है। इसमे निम्न properties होती हैं।

image080

  • Name: इसका use control का name define किया जाता है। जो dialog को codes मे identify करता है।
  • AllowFullOpen: इसे true करने पर Color dialog को full mode मे open किया जा सकता है। इसमे user custom colors भी बना सकता है।
  • AnyColor: इसके ture होने पर color dialog box सभी available colors को display करता है।
  • Color: इसके use Color dialog मे select किए गए color को get या set करने के लिए किया जाता है।
  • CustomColors: इसका use color dialog मे custom color को set करने के लिए किया जाता है।
  • SolidColorOnly: इसके true होने पर user केवल Solid colors को ही use कर सकता है। इसमे custom colors को use नहीं किया जा सकता है।

  इसका use font dialog box को display करने के लिए किया जाता है। font dialog box मे Font का name, size, color, type etc. set करने केfacility होती है। इन सभी settings को font dialog control का use कर display किया जाता है। यह font से related सभी प्रकार की settings के लिए use किया जाता है। जैसे – bold, italic, underline, script etc. इसे form मे place करने के बाद ShowDialog method का use कर इसे dialog box को display किया जाता है। इसकी propertiesनिम्नलिखित हैं।

image079

  • Name: इसका use control का name define किया जाता है। जो dialog को codes मे identify करता है।
  • Color: इसका use font dialog मे select किए गए color को get करने के लिए किया जाता है। इसमे colors केवल showcolor property के ture होने पर display होते हैं।
  • Font: यह एक font object है। इसका use font dialog box मे set किए गए font को get और set करने के लिए use की जाती हैं। इसमे font की सभी settings available रहती हैं जैसे- Font name, size, bold, italic, underline etc.
  • FontMustExist: इसके ture होने पर यह dialog को केवल exist fonts को select किया जा सकता है। ऐसे नहीं करने पर warning message display होता है।
  • MaxSize/ MinSize: यह दोनों property integer values लेती हैं और font की maximum size और minimum size get और set करने के लिए use की जाती है।
  • ShowApply: इस property के ture होने पर Apply button भी font dialog box मे display होती है।
  • ShowColor: इसके ture होने पर dialog box मे font color select करने के लिए भी option display होता है।

   Save dialog box किसी file को save करते समय displayहोता है। इसका use file को save करने के लिए location और उसका name setकरने की facility देता है। Save पर click करने पर display होने वाले dialog box को Save File Dialog box कहते हैं। चूंकि windows के ज़्यादातरapplications user को file save करने के लिए prompt करते हैं इसीलिएVB.Net मे इसे common dialog control के अंदर रखा गया है। इस dialog boxमे user file की location और उसके name को set करता है और save परclick करने पर file save हो जाती है। SaveFileDialog control, Common Dialog control category के अंदर आता है। इसे form पर place करShowdialog() method को call कर इसे अपने application मे display किया जा सकता है। यह dialog control OpenFileDialog की निम्न properties को supportकरता है।

image078

  • Name: इसका use control का name define किया जाता है। जो dialog कोcodes मे identify करता है।
  • AddExtension: यह property determine करती है की dialogbox FileNameमे automatically extension add कर लेगा या नहीं यदि use उसे मिटा देता है।
  • CheckFileExists: इसके ture होने पर DialogBox automatically input किए गए file name को check कर लेगा। File के exist नहीं होने पर यहwarning message display करता है।
  • CheckPathExists: इसके True होने पर dialogbox File के path कोautomatically check कर लेगा। Path exist नहीं होने पर यह warning message display करता है।
  • DefaultExe: इसका use Default filename extension set करने के लिए किया जाता है। जो की extension नहीं देने पर
  • भी file के साथ automatically add हो जाता है।
  • FileName: इसका use Dialog box मे input की गई file को और उसकेpath को get करने के लिए किया जाता है। यह Input की गई File Name कोreturn करती है।
  • Filter: यह Savefiledialog box की एक important property है। इसका use Files को filter करने के लिए किया जाता है। यह dialog मे display होने वाली files के type को specify करने के लिए किया जाता है। जैसे Text files को display करने के लिए Filter मे “Text Files|*.txt” set करते है। Pipeline ( | ) character का use file description और Extension को अलग अलग करने के लिए किया जाता है। यह एक साथ कई file extension set करने के लिए semicolor character का use किया जाता है। जैसे - “BMP,GIF and JPG|*.bmp;*.gif;*.jpg”
  • FilterIndex: इसका use Filter property मे define किए गए Filters मेdefault filter को set करने के लिए किया जाता है। यह interger type की वैल्यू contain करती है।
  • InitialDirectory: इसका use dialog box के लिए initial directory set करने के लिए किया जाता है। जो default open होती है।
  • RestoreDirectory: इसे ture करने पर dialog box previous मे open की गई directory को automatically save कर लेता है जो दुबारा open करने पर वही directory open हो जाती है।
  • ShowHelp: इसके ture होने पर Help button display होती है।
  •  Title: यह property dialog box के title को set करने के लिए किया जाता है।

     इसका use open file dialog box को display करने के लिए किया जाता है। यह dialog box user को file select और open करने की सुविधा प्रदान करता है। यह user को multiple files select करने के सुविधा देता है। इसमे files और folders की list display होती है। जिसमे से user files को select कर सकता है और उन्हेprocess कर सकता है। इसे display करने के लिए ShowDialog() method का use किया जाता है। यह एक वैल्यू return करती है जो की dialog मे click की गई button को बताती है।

If OpenFileDialog1.ShowDialog = DialogResult.OK Then

MsgBox (OpenFileDialog1.FileName)

End If

 

image077

इसमे निम्न property होती हैं।

  • Name: इसका use control का name define किया जाता है। जो dialog को codes मे identify करता है।
  • AddExtension: यह property determine करती है की dialogbox FileName मे automatically extension add कर लेगा या नहीं यदि use उसे मिटा देता है।
  • CheckFileExists: इसके ture होने पर DialogBox automatically input किए गए file name को check कर लेगा। File के exist नहीं होने पर यह warning message display करता है।
  • CheckPathExists: इसके True होने पर dialogbox File के path को automatically check कर लेगा। Path exist नहीं होने पर यह warning message display करता है।
  • DefaultExe: इसका use Default filename extension set करने के लिए किया जाता है। जो की extension नहीं देने पर भी file के साथ automatically add हो जाता है।
  • FileName: इसका use Dialog box मे select की गई file को और उसके path को get करने के लिए किया जाता है। यह Selected File Name को return करती है।
  • FileNames: यह property multiple files को select करने पर सभी files को उनके path के साथ get करने के लिए किया जाता है।
  • Filter: यह openfiledialog box की एक important property है। इसका use Files को filter करने के लिए किया जाता है। यह dialog मे display होने वाली files के type कोspecify करने के लिए किया जाता है। जैसे Text files को display करने के लिए Filter मे “Text Files|*.txt” set करते है। Pipeline ( | ) character का use file description और Extension को अलग अलग करने के लिए किया जाता है। यह एक साथ कई file extension set करने के लिए semicolor character का use किया जाता है। जैसे - “BMP,GIF and JPG|*.bmp;*.gif;*.jpg”
  • FilterIndex: इसका use Filter property मे define किए गए Filters मे default filter को set करने के लिए किया जाता है। यह interger type की वैल्यू contain करती है।
  • InitialDirectory: इसका use dialog box के लिए initial directory set करने के लिए किया जाता है। जो default open होती है।
  • MultiSelect: इसके ture होने पर Dialog box मे multiple files को select किया जा सकता है।
  • RestoreDirectory: इसे ture करने पर dialog box previous मे open की गई directory को automatically save कर लेता है जो दुबारा open करने पर वही directory open हो जाती है।
  • ShowHelp: इसके ture होने पर Help button display होती है।
  • Title: यह property dialog box के title को set करने के लिए किया जाता है।
  • ShowReadOnly: इसके ture होने पर ReadOnly का एक checkbox भी openfiledialog मे display होता है।

Tuesday, April 23, 2013

image

Windows Applications मे अधिकतर applications मे user को filename, font name और size, color etc. के लिए prompt करते है। इन common works के लिएdialog box बनाना एक कठिन कार्य है। windows OS इसके लिए standard dialog box provide करता है। जो कि इस प्रकार के सभी common tasks को perform करते है।VB.Net मे यह common dialog box use किए जा सकते है। इसके लिए किसी भी extra programming effort करने कि आवश्यकता नहीं पड़ती है। यह dialog controls run timeमे form मे invisible होते है इन्हे कुछ methods का use कर display किया जा सकता है। यह सभी dialog category के अंदर toolbox मे पाये जाते हैं। इसमे निम्न प्रकार केdialog box होते हैं।

  1. OpenFileDialog
  2. SaveFileDialog
  3. ColorDialog
  4. FontDialog
  5. PrintDialog

Using Common Dialog Controls:

      सभी common dialog controls को use करने से पहले इन्हे form मे add करना पड़ता है। इसके लिए toolbox मे dialog category मे ये सभीcontrol available रहते हैं। यह controls runtime मे form मे visible नहीं रहते हैं। सभी common dialog controls को display करने के लिए ShowDialog () method का useकिया जाता है। इसे use करने पर यह method dialog result को return करती है जिसे dialogresult type के variable मे store कर सकते हैं।

If ColorDialog1.ShowDialog = DialogResult.OK Then

Me.BackColor = ColorDialog1.Color

End If

TreeView control मे display होने वाले node, nodes collection के अंदर पाये जाते हैं। nodes collection, TreeView control मे nodes को add, remove etc. के लिएmethods provide करता है। nodes collection मे design और run time दोनों मे nodes को manipulate किया जा सकता है। design time मे यह nodes collection editor provide करता है जिसे treeview के nodes property पर click कर display किया जा सकता है। Runtime मे इसमे nodes को manipulate करने के लिए निम्न methods का useकिया जाता है।

  • Add: इस method का use nodes collection मे nodes को add करने के लिए किया जाता है।

Syntax: Nodes.Add (Node_Caption)

Nodes.Add (Node_Object)

Nodes.Add (index, Node_Object)

Ex- image076

Me.TreeView1.Nodes.Add("Course")

Me.TreeView1.Nodes(0).Nodes.Add("Degree")

Me.TreeView1.Nodes(0).Nodes.Add("Diploma")

Me.TreeView1.Nodes(0).Nodes(0).Nodes.Add("BCA")

Me.TreeView1.Nodes(0).Nodes(0).Nodes.Add("BSc IT")

Me.TreeView1.Nodes(0).Nodes(0).Nodes.Add("MSC CS")

Me.TreeView1.Nodes(0).Nodes(0).Nodes.Add("MSC IT")

Me.TreeView1.Nodes(0).Nodes(1).Nodes.Add("PGDCA")

Me.TreeView1.Nodes(0).Nodes(1).Nodes.Add("DCA")

  • Count: इसका use nodes को count करने के लिए किया जाता है।

Syntax- Nodes.Count

Ex- msgbox (Treeview1.Nodes.count)

  • Clear: इसे nodes collection से nodes को एक साथ remove करने के लिए किया जाता है।

Syntax- Nodes.Clear ()

Ex- TreeView1.Nodes.clear ()

  • Remove: इसका use nodes collection से node को remove करने के लिए किया जाता है इसमे index का use इया जाता है।

Syntax- Nodes.Remove (index)

Ex- Me.TreeView1.Nodes (0).Nodes (1).Remove()

  • Item: इसका use nodes collection से किसी item को get करने के लिए किया जाता है।

Syntax- Nodes.Item (index)

Ex- MsgBox (Me.TreeView1.Nodes (0).Nodes.Item (0).Text)

  • FirstNode/LastNode/PrevNode/NextNode: इसका use क्रमशः First Node, Last Node, Previous Node और Next Node के get करने के लिए किया जाता है।

Dim n As TreeNode

n = Me.TreeView1.Nodes(0).FirstNode

MsgBox(n.Text)

Contact us

Name

Email *

Message *