-->

Tuesday, December 8, 2015

Password Box example in WPF

If you want to design login control then must to set the special character in password box. Today, we will learn, how to design password box in WPF. In WPF, we have a PasswordBox tag in XAML , through this we can add Password box in WPF. I have a simple login control through you can see password control.



The complete code of login control

<Window x:Class="WpfApplication8.password"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="password" Height="300" Width="300">
    <Grid> 
        <StackPanel Margin="20">
            <Label>Password Box Example</Label>
            <WrapPanel>
                <Label>Username:</Label>
                <TextBox Width="100"/>
            </WrapPanel>
            <WrapPanel>
                <Label>Password:</Label>
                <PasswordBox PasswordChar="x" MaxLength="8" Width="100"/>
            </WrapPanel>
            
            
        </StackPanel>
        
    </Grid>
</Window>

Code Generates the following output:


Monday, December 7, 2015

WPF common "enable all" checkbox in the top

Introduction
In this WPF article, I will show you, single checkbox enable all other remaining checkboxes; if it is unchecked then remaining them also unchecked. To do this task, first of add single checkbox for all other checkboxes in the stack panel. Now, add other child checkboxes in nested stack panel. look at, simple xaml code view.



<Window x:Class="WpfApplication8.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <StackPanel Margin="10">
            <Label FontWeight="Bold">Technical Skills</Label>
            <StackPanel Margin="20,10">
                <CheckBox IsThreeState="True" Name="AllSelect" Checked="AllSelect_Checked" Unchecked="AllSelect_Checked">Enable All</CheckBox>
                <StackPanel Margin="20,10">
                    <CheckBox Name="singlecheckjava" Checked="singlecheckjava_Checked" Unchecked="singlecheckjava_Checked">Java</CheckBox>
                    <CheckBox Name="singlecheckcpp" Checked="singlecheckjava_Checked" Unchecked="singlecheckjava_Checked">C++</CheckBox>
                    <CheckBox Name="singlecheckphp" Checked="singlecheckjava_Checked" Unchecked="singlecheckjava_Checked">PHP</CheckBox>          
             
                 
                 
                </StackPanel>
            </StackPanel>      
         
         
        </StackPanel>
    </Grid>
</Window>
Here, we have checked and unchecked events. Both are calling same function in "Allselect" checkbox. In the child checkboxes also we have checked and unchecked event , they are calling same method. So in this program we have two method that is "AllSelect_Checked" and "singlecheckjava_Checked".

Code Behind Code 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApplication8
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void AllSelect_Checked(object sender, RoutedEventArgs e)
        {
            bool allcheckbox = (AllSelect.IsChecked == true);
            singlecheckjava.IsChecked = allcheckbox;
            singlecheckcpp.IsChecked = allcheckbox;
            singlecheckphp.IsChecked = allcheckbox;

        }

        private void singlecheckjava_Checked(object sender, RoutedEventArgs e)
        {
            AllSelect.IsChecked = null;
            if ((singlecheckjava.IsChecked == true) && (singlecheckcpp.IsChecked == true) && (singlecheckphp.IsChecked == true))
                AllSelect.IsChecked = true;
            if ((singlecheckjava.IsChecked == false) && (singlecheckcpp.IsChecked == false) && (singlecheckphp.IsChecked == false))
                AllSelect.IsChecked = false;
        }
    }
}

Friday, December 4, 2015

How to add window media player in ASP.NET

Introduction
In this article, I will show you how to play mp4 and WMV file in asp.net. To do this task first to install Silverlight into your computer by the following link. After installed Silverlight, add System.Web.Silverlight.dll file reference in the bin folder. Add media player component in ToolBox by using right click on toolBox.


Right click on toolbox--> choose Items...--->.Net Framework Components--> Click on Browse Button also select System.Web.Sliverlight from uncompressed folder.



Drag Media player control from ToolBox to Web Form. Set Required property that is mentioned below.
Media Source = ~/movie/first.mp4
Here, we have movie folder.

Download System.Web.Silverlight.dll file.

Code generates the following output

How to add window media player in ASP.NET

Thursday, December 3, 2015

Add multiple TextBox dynamically using Button click in ASP.NET C#

Introduction
In this article, I will show you how to add multiple TextBox by using button click. When we press the button then add TextBox in the panel. Similarly again when we press the button then again TextBox add just after previous one. I will give you an example of add multiple TextBox dynamically in ASP.NET.




Source code

<body>
    <form id="form1" runat="server">
    <div>

    </div>
    </form>
</body>

Code Behind page

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class DynamicallyAdd : System.Web.UI.Page
{
    Panel panelforTextBox;
    protected void Page_Load(object sender, EventArgs e)
    {
        Literal literal;
        Label labelTextBox;

        panelforTextBox = new Panel();
        panelforTextBox.ID = "panelforTextBox";
        panelforTextBox.BorderWidth = 2;
        panelforTextBox.Width = 400;
        this.form1.Controls.Add(panelforTextBox);

        literal = new Literal();
        literal.Text = "<br/>";

        this.form1.Controls.Add(literal);

        labelTextBox = new Label();
        labelTextBox.Text = "Dynamic TextBox <br/>";


        panelforTextBox.Controls.Add(labelTextBox);
        Button addbutton = new Button();
        addbutton.ID = "addbutton";
        addbutton.Text = "Add New TextBox";
        addbutton.Click += new System.EventHandler(clicktoaddTextBox);
        this.form1.Controls.Add(addbutton);

        if (IsPostBack)
        {
            controlcreate("DynamicText", "TextBox");
        }

    }

    private void controlcreate(string p1, string p2)
    {
        string[] controls = Request.Form.ToString().Split('&');
        int count = findcontrolcount(p1);
        if(count>0)
        {
            Literal lit;
            for (int k = 0; k <=count; k++)
            {
                for (int i = 0; i < controls.Length; i++)
                {
                    if (controls[i].Contains(p1+"-"+k.ToString()))
                    {
                        string controlname = controls[i].Split('=')[0];
                        string controlvalue = controls[i].Split('=')[1];
                        controlvalue = Server.UrlDecode(controlvalue);
                        if(p2=="TextBox")
                        {
                            TextBox txt = new TextBox();
                            txt.ID = controlname;
                            txt.Text = controlvalue;
                            panelforTextBox.Controls.Add(txt);
                            lit = new Literal();
                            lit.Text = "<br/>";
                            panelforTextBox.Controls.Add(lit);

                        }
                        break;
                    }
                }
            }
        }
    }

    private void clicktoaddTextBox(object sender, EventArgs e)
    {
        //throw new NotImplementedException();
        Button button = (Button)sender;
        if (button.ID=="addbutton")
        {
            int count = findcontrolcount("DynamicText");
            TextBox text = new TextBox();
            text.ID = "DynamicText-" + Convert.ToString(count + 1);
            panelforTextBox.Controls.Add(text);
            Literal lit = new Literal();
            lit.Text = "<br/>";
            panelforTextBox.Controls.Add(lit);
        }


    }

    private int findcontrolcount(string p)
    {
        //throw new NotImplementedException();
        string str = Request.Form.ToString();
        return ((str.Length - str.Replace(p, "").Length) / p.Length);

    }

}

Monday, November 23, 2015

How to determine version of MVC application

In this article, I will show you how to check  MVC version of application. There are two methods, through which we can get the version of MVC. In the first method we use property of System.Web.MVC namespace. But, How to check, check the mentioned snap shots.

1. Expand References folder 
2. Right click on System.Web.MVC namespace also select property , check the mentioned snap.

II-Method

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace WebApplication9.Controllers
{
    public class HomeController : Controller
    {
        // GET: Home
        public string Index()
        {
            return typeof(Controller).Assembly.GetName().Version.ToString();
        }
}
}

Tuesday, November 17, 2015

Drop Shadow example in WPF

In this article, I will show you, How to create Shadow of controls. Through this, we can show 3d view of control. First of all, I will apply this style on manually created designs like Ellipse, Rectangle etc. After that I will apply same things on controls. So, add a new window in the project. Add this code in between the <grid> ...</grid> section of xaml file.



 <Rectangle Height="150" Width="150" Stroke="Black" StrokeThickness="2">
            <Rectangle.BitmapEffect>
                <DropShadowBitmapEffect Color="Black" Direction="-50" ShadowDepth="40" Softness=".8"/>
               
            </Rectangle.BitmapEffect>
            <Rectangle.Fill>
                <ImageBrush ImageSource="apple.png"/>
               
            </Rectangle.Fill>
        </Rectangle>      

BitmapEffect creates the shadow effect behind the object. In the above-mentioned code we have Direction attribute. With the help of Direction attribute we can show shadow of control at user defined position. 

<Button Width="150" Margin="71,167,71,59">
            <Button.BitmapEffect>
                <DropShadowBitmapEffect Color="Black" Direction="-50" ShadowDepth="40" Softness=".7"/>
            </Button.BitmapEffect>
            <Image Source="apple.png" Stretch="Fill"/>


Code generates the following output

Drop Shadow example in WPF

How to use Hyperlink in MVC

In my previous article i have already learned about hyperlink and their uses, we have already use hyperlink in different application like asp.net. Previous article coves all such things like hyperlink properties and methods. Today i am talking about hyperlink in MVC, and how to use it.


 Hyperlink in MVC
 

 The given snap shows that how MVC work. According to the sanp view show the all tags of html. In MVC application, we use ActionLink extension of HtmlHelper. I have show the syntax and example of Hyperlink.

Syntax:


@Html.ActionLink(String LinkText, String actionName)

Example


@Html.ActionLink("Hello World","Hello")

Action Method in Controller class


public string Hello()
 {

return "Hello World!";

 }
OK Done this is complete. Now, Today we have also learn how to bind hyperlink from database table in MVC. First to prepare the class for employee entity in model folder also map this with database table(mentioned in previous article), Now your code look like

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Web;

namespace WebApplication10.Models
{
[Table("Employee")]
public class Employee
{
public int ID { get; set; }
public string Name { get; set; }
public int age { get; set; }

}
}

Prepare the Context class for connecting database in the same model folder.

using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;

namespace WebApplication10.Models
{
public class EmployeeContext: DbContext
{
public EmployeeContext()
: base("EmployeeConnection")
{

}
public DbSet<Employee> pl { get; set; }

}

}

Here EmployeeContext() constructor call the base class constructor for making connection. "EmployeeConnection" connectionString available in web.confog file. Prepare the controller class for responding the request, which is generated by the client.

public ActionResult linkEmp()
{
EmployeeContext context = new EmployeeContext();
List<Employee> employeelist = context.pl.ToList();
return View(employeelist);
}

Through the EmployeeContext class, first we retrieve all the data from the table and then store into the employee instance. Now, prepare the view for list of employee.

@model IEnumerable<WebApplication10.Models.Employee>
@using WebApplication10.Models;
@{
ViewBag.Title = "Show the particular employee";
}

<h2>Click to show the details of employee</h2>
<ol>
@foreach (Employee emp in @Model)
{
<li>@Html.ActionLink(emp.Name, "Index", new { id = emp.ID })</li>
}
</ol>

Here, we are using IEnumerable interface for collection and in the ActionLink Method, first argument of that method shows the name of the employee and second parameter show that method, which is call by hyperlink(Mentioned in Controller class) also method contain single parameter like id.

public ActionResult Index(int id)
{
EmployeeContext context = new EmployeeContext();
Employee emp = context.pl.Single(p2=>p2.ID==id);

return View(emp);
}

Code Generate the following output

How to use Hyperlink in MVC

After click on Tarun(Hyperlink), You will get the specific Employee Information.

output use Hyperlink in MVC
© Copyright 2013 Computer Programming | All Right Reserved