Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

Use Anchoring feature in window forms on controls using .net 2.0.

Author: Zunnair
Download Source Code : 821_AnchoringApp.zip

In this simple article you will learn that how to use anchoring feature on window form controls.

 Create new c# project. Drag one Rich text box control, five buttons on the windows form.

 

Now write following code on form load event:

 

C#

private void Form1_Load(object sender, EventArgs e)

        {

            this.Text = "DevAsp Anchoring APP";

 

            button1.Anchor = AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Left;

            button2.Anchor = AnchorStyles.Bottom  | AnchorStyles.Right | AnchorStyles.Left;

            button3.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left;

            button4.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Right;

            richTextBox1.Anchor = AnchorStyles.Left | AnchorStyles.Bottom |AnchorStyles.Right | AnchorStyles.Top ;

           

        }

 

VB

Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)

        Me.Text = "DevAsp Anchoring APP"

 

        button1.Anchor = AnchorStyles.Top Or AnchorStyles.Right Or AnchorStyles.Left

        button2.Anchor = AnchorStyles.Bottom Or AnchorStyles.Right Or AnchorStyles.Left

        button3.Anchor = AnchorStyles.Top Or AnchorStyles.Bottom Or AnchorStyles.Left

        button4.Anchor = AnchorStyles.Top Or AnchorStyles.Bottom Or AnchorStyles.Right

        richTextBox1.Anchor = AnchorStyles.Left Or AnchorStyles.Bottom Or AnchorStyles.Right Or AnchorStyles.Top

 

    End Sub

 

Now write code on buttons events

 

C#

 

private void button3_Click(object sender, EventArgs e)

        {

            richTextBox1.Anchor = AnchorStyles.Left;

        }

 

        private void button1_Click(object sender, EventArgs e)

        {

            richTextBox1.Anchor = AnchorStyles.Top;

        }

 

        private void button4_Click(object sender, EventArgs e)

        {

            richTextBox1.Anchor = AnchorStyles.Right;

        }

 

        private void button2_Click(object sender, EventArgs e)

        {

            richTextBox1.Anchor = AnchorStyles.Bottom;

        }

 

        private void button5_Click(object sender, EventArgs e)

        {

            richTextBox1.Anchor = AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Right | AnchorStyles.Top;

        }

 

VB

 

Private Sub button3_Click(ByVal sender As Object, ByVal e As EventArgs)

        richTextBox1.Anchor = AnchorStyles.Left

    End Sub

 

    Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)

        richTextBox1.Anchor = AnchorStyles.Top

    End Sub

 

    Private Sub button4_Click(ByVal sender As Object, ByVal e As EventArgs)

        richTextBox1.Anchor = AnchorStyles.Right

    End Sub

 

    Private Sub button2_Click(ByVal sender As Object, ByVal e As EventArgs)

        richTextBox1.Anchor = AnchorStyles.Bottom

    End Sub

 

    Private Sub button5_Click(ByVal sender As Object, ByVal e As EventArgs)

        richTextBox1.Anchor = AnchorStyles.Left Or AnchorStyles.Bottom Or AnchorStyles.Right Or AnchorStyles.Top

    End Sub

 

This is the simple code for Anchoring windows forms controls.

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Home button in Web Browser Control Application using C# .net 2.0

Disclaimer - Privacy
© 2002-2017 DevASP.net