.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> WPF >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Border Control in WPF Day-2

Posted By:Narayanan       Posted Date: August 27, 2012    Points: 200    Category: WPF    URL: http://www.dotnetspark.com  

Introduction: Yesterday we talked about WPF Introduction and AccessText Control. Today we will discuss about Board Control
 

ยท  Border Control:

  To draw a border, background or both around another elements.

Create Border in XAML:

<Border Background="CadetBlue"  BorderBrush="Blue" BorderThickness="5" CornerRadius="600" Padding="15">   </Border>

Create Border in Coding:

  Border myBorder;

     private void brder()

        {

            myBorder = new Border();

            myBorder.Background = Brushes.LightBlue;

            myBorder.BorderBrush = Brushes.Black;

            myBorder.BorderThickness = new Thickness(2);

            myBorder.CornerRadius = new CornerRadius(45);

            myBorder.Padding = new Thickness(25);

            this.Content = myBorder;

        }

        private void Window_Loaded(object sender, RoutedEventArgs e)

        {

            brder();

    }


Suppose, User wants to display a Child element in the Border.

This is the example.

Create Border in XAML:

 

       <Border  BorderThickness="5"   BorderBrush="Green"   CornerRadius="10"  Background="LightGray" HorizontalAlignment="Left" VerticalAlignment="Top" Width="270" Height="250">

        <Border  BorderThickness="1"   BorderBrush="Yellow"   CornerRadius="5"  Background="Blue"  HorizontalAlignment="Center"  VerticalAlignment="Center"  Width="150" Height="50">

        </Border>

        </Border>

Create Border in Coding:

   

     Border myBorder;

        Border myChildBorder;

    private void brder()

        {

            myBorder = new Border();

            myBorder.Background = Brushes.LightBlue;

            myBorder.BorderBrush = Brushes.Black;

            myBorder.BorderThickness = new Thickness(2);

            myBorder.CornerRadius = new CornerRadius(45);

            myBorder.Padding = new Thickness(25);

            myChildBorder = new Border();

            myChildBorder.Background = Brushes.DarkGreen;

            myChildBorder.BorderBrush = Brushes.Cyan;

            myChildBorder.BorderThickness = new Thickness(2);

            myChildBorder.CornerRadius = new CornerRadius(45);

            myChildBorder.Width = 100;

            myChildBorder.VerticalAlignment = VerticalAlignment.Center;

            myChildBorder.Height  = 100;

            myChildBorder.Padding = new Thickness(25);

            myBorder.Child = myChildBorder;

            this.Content = myBorder;

        }

        private void Window_Loaded(object sender, RoutedEventArgs e)

        {

            brder();

    }

   

Conclusion:

  I hope, you get some ideas about Border. Thanks for reading this article. We will talk about other controls in next Chapters.              

 


 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend