bobber205

I am creating my first Windows form application. I have a "form1.cs" file and a "program.cs" file. I have a button called refreshbutton. I want it to called a method called "refreshtext" whenever it's clicked. I have currently put that function inside my program.cs function.

I could put the code into my program's click event, but I want it to be as modular as possible so I can call this function at any time. ^_^

So where do I put this code What "using" statements do I need to use
EDIT.. Here's my code.

EDIT: Here's some code.

Program.cs
[code]
using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace RSSGuiVersion
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Armitunes());


}

public static void refreshData()
{

System.Console.WriteLine("a");
//RSSGuiVersion.Armitunes.currentSong.Text = "a";
Label referencetotext = new Label();
referencetotext = RSSGuiVersion.Armitunes.currentSong;

}
}




}
[/code]

Form1.css
[code]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
//using RSSGuiVersion;


namespace RSSGuiVersion
{
public partial class Armitunes : Form
{
public Armitunes()
{
InitializeComponent();
}

private void label1_Click(object sender, EventArgs e)
{
this.Text = "a";
}

private void refreshButton_Click(object sender, EventArgs e)
{
currentSong.Text = "You clicked on my friend! Sad";
RSSGuiVersion.Program.refreshData();


}
}
}
[/code]


Re: Windows Forms General How Do I have my button Controls Call a Function

Jeremy Filburn

You can add a click event handler after the InitializeComponent() line or double click the button in the IDE and it will create one for you!

Code Snippet

this.refreshButton.Click += new System.EventHandler(this.refreshButton_Click);