Silverlight Expand Button Size On Mouse Click in VB.NET

In this article you will learn how to expend the Button size on mouse click in Silverlight.
  • 2148

The below example shows you that, when you click on the button at that time button size will increase.

Example of Expended Button

MainPage.xaml.vb Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using
 System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Threading;
namespace SilverlightApplication5
{
    public partial class MainPage : UserControl
   {
        const double minSize = 15;
        const double maxSize = 50;
        Button b;
        public MainPage()
        {
            InitializeComponent();
            ExpendedButton();
        }
        public void ExpendedButton()
        {
            this.Tag = "ExpendedButton";
            b = new Button();
            b.Content = "Expanding Button";
            b.FontSize = minSize;
            b.HorizontalAlignment =HorizontalAlignment.Center;
            b.VerticalAlignment =VerticalAlignment.Center;
            b.Click += afterClick;
            Content = b;
        }
        void afterClick(object sender, RoutedEventArgs args)
        {
            DispatcherTimer timer = new DispatcherTimer();
            timer.Interval = TimeSpan.FromSeconds(0.2);
            timer.Tick += starttimer;
            timer.Start();
        }
        void starttimer(object sender, EventArgs args)
        {
            b.FontSize += 3;
            if (b.FontSize >= maxSize)
        {
            b.FontSize = minSize;
            (sender as DispatcherTimer).Stop();
        }
        }
    }
}

Output Window

Button before mouse click

2.gif
 

Button after mouse click

3.gif
 

Conclusion

Hope you will learn through this article how to Expend the Button size on mouse click in Silverlight.

The below example shows you that, when you click on the button at that time button size will increase

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.