Microsoft Communities

Welcome to WindowsClient.net | Sign in | Join

Here are some frequently asked questions about Windows Forms and their answers.

Windows Forms FAQs

Browse by Tags

All Tags » Button (RSS)


  • How do I make a Button trigger a Click event at specific time intervals while the mouse is down like a ScrollBar button?

    public class RepeatButton : Button { private Timer timer1; public int Interval { get { return Timer.Interval; } set { Timer.Interval = value; } } private Timer Timer { get { if ( timer1 == null ) { // create and setup the timer timer1 = new Timer(); timer1...
  • How do I trigger a Button Click event?

    Use the Button's public method PerformClick. Contributed from George Shepherd's Windows Forms FAQ
  • How do I put a bitmap or icon on a Button?

    You can use the Button.Image property to add an image to a button face. Use the Button.ImageAlign (and possibly Button.TextAlign) to layout your button face. You can also implement custom drawing on a button face as described in How do I add custom drawing...
  • How do I resize a Button to fit its text?

    Get a Graphics object for the button and use its MeasureString method to compute the width you need. using ( Graphics g = button1.CreateGraphics() ) float w = g.MeasureString( button1.Text, button1.Font ).Width; button1.Width = (int) w + 12; // 12 is...
  • How do I add custom drawing to a Button?

    Subclass Button and add a custom Paint event handler that does you custom drawing. public class CustomButton : Button { public CustomButton() { Paint += new PaintEventHandler( ButtonPaint ); } private void ButtonPaint( object sender, PaintEventArgs e...


Page view counter