h1.post-title { color:orange; font-family:verdana,Arial; font-weight:bold; padding-bottom:5px; text-shadow:#64665b 0px 1px 1px; font-size:32px; } -->

Pages

WPF Day-5

Introduction:
    Last Four days, we talked about WPF Introduction, AccessText Control, Board and Canvas, Calendar, CheckBox, ComboBox and ContextMenu Control. Today we will discuss about Datagrid, DatePicker, DockPanel, and DocumentViewer Control.

·  Datagrid Control:
               Represents a control that displays data in a customizable grid.
                  It starts from .Net Framework 4.0.
Please refer this: http://msdn.microsoft.com/en-us/library/system.windows.controls.datagrid%28v=vs.100%29.aspx
·  DatePicker Control:
               Represents a control that allows the user to select a date.
               It starts from .Net Framework 4.0.
Please refer this: http://msdn.microsoft.com/en-us/library/system.windows.controls.datepicker.aspx
·  DockPanel Control :
     Defines an area where you can arrange child elements either horizontally or vertically, relative to each other.
Create ContextMenu in XAML:
<DockPanel Background="AliceBlue">
            <TextBox Name="textBox1" TextWrapping="Wrap" Margin="10, 10, 5, 5" Grid.Row="7" Height="36" Width="202">The quick brown fox jumps over the lazy dog.
                <TextBox.ContextMenu>
                    <ContextMenu>
                        <MenuItem Header="_USA" />
                        <Separator />
                        <MenuItem Header="_INDIA"  />
                        <Separator />
                        <MenuItem Header="CHINA"/>
                        <Separator />
                        <MenuItem Header="SOUTH AFRICA" />
                    </ContextMenu>
                </TextBox.ContextMenu>
            </TextBox>
        </DockPanel>

Create ContextMenu in Coding:
    CheckBox chkYes;
     CheckBox chkNo;
     DockPanel dockPanel;
private void dockPanelControl()
        {
            dockPanel = new DockPanel();
            dockPanel.Background = Brushes.LightSlateGray;
            dockPanel.Margin = new Thickness(10, 15, 5, 10);
            dockPanel.Height = 100;
            dockPanel.Width= 200;
            dockControl(dockPanel);
            this.Content = dockPanel;
        }
        private void dockControl(DockPanel dpnl)
        {
            chkYes = new CheckBox();
            chkYes.ClickMode = ClickMode.Press;
            chkYes.Content = "Yes";
            chkYes.IsChecked = true;
            chkYes.Margin = new Thickness(10, 10, 25, 20);

            chkNo = new CheckBox();
            chkNo.ClickMode = ClickMode.Press;
            chkNo.Content = "No";
            chkNo.Margin = new Thickness(10, 10, 25, 20);
            dpnl.Children.Add(chkYes);
            dpnl.Children.Add(chkNo);
        }
private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            dockPanelControl();
        }
·  DocumentViewer Control:
           Document viewing control that can host paginated FixedDocument content such as an XpsDocument. Simple says that user can view all documents like (PDF, text. Image files)
FixedDocument:
   It is a fixed format document with read Access for user.
    Provides a Package that holds the content of an XPS document.
Package:
           Container that can store multiple data objects.
Create ContextMenu in XAML:
<DocumentViewer Margin="20,12,12,26" Name="documentViewer1" Background="Azure" />
Create ContextMenu in Coding:
        DocumentViewer docViewer;
             private void documentViewerControl()
              {
                   docViewer = new DocumentViewer();
                   docViewer.Background = Brushes.LightSlateGray;
                    this.Content = docViewer;
        }
            private void Window_Loaded(object sender, RoutedEventArgs e)
             {
                 documentViewerControl();
             }
Conclusion:
  I hope, you to get some ideas about Datagrid, DatePicker, DockPanel, and DocumentViewer Control in WPF. Thanks for reading this article. We will talk about other controls in next Chapters.              

Create textBox using Class in C#.net

In this Article, I will explain Create a TextBox in the Class file and call the method in any form in the Application.
you can create a Class in the Several ways in the .Net.
you can create via "Class.cs" file.
you can create via "CodeFile.cs" file.
you can create via "Form.cs" file.
Now , i will explain One by one .

you can create via "Class.cs" file.:
Open your Project
Click "Project">> Add Class or Shift +Alt+C.
User can view the "Add New Item" window.
in the Name Input box , User can see the Class1.cs.
Click "ok" or change class file name in the input Box with Extension(.cs) and Clicks "Ok" button.
User can view this below format.

///Default namespaces
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Namespace_Program // Namespace Name
{
    class Class2 // Class name
    {
    }
}
Now , User add coding within the Class .
For Eg:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Namespace_Program
{
    class Class2  : Form  // We inherited form intoi class2
    {
       public static void TextBox(Form  frm)
        {
            TextBox txt = new TextBox();
            txt.Name = "txt_One";
            txt.Text = "Unit Testing";
            frm.Controls.Add(txt);
       }
    }
}

Now we just call this TextBox Method in the Form Class file
   Class2.TextBox(this);
Result: User can view the TextBox in the Form1 Designer at Run Time.
you can create via "CodeFile.cs" file:
we just create a method in the Class file using CodeFile.cs
using System;
using System.Windows.Forms;
namespace Test_namespace
{
    class dynamicControl : System.Windows.Forms.Form
    {
        public static void TextBox(Form frm)
        {
            TextBox txt = new TextBox();
            txt.Name = "txt_One";
            txt.Text = "Unit Testing";
            txt.Location = new System.Drawing.Point(20, 25);
            frm.Controls.Add(txt);
        }
    }
}
call in the Form.cs
 dynamicControl.TextBox(this);

you can create via "Form.cs" file:
open Form.cs
Copy and Paste code in the form.cs
    public static void TextBox(Form frm)
        {
            TextBox txt = new TextBox();
            txt.Name = "txt_One";
            txt.Text = "Testing";
            txt.Location = new Point(75, 100);
            frm.Controls.Add(txt);
        }
you can create via "Form.cs" file:
call the funciton in the form.cs
    TextBox(this);
I hope, this article helps you. Thanks for reading this Article.