473,387 Members | 1,431 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Calling a class from a button

How do I call a public class function in C# from a button
like

private void Button1_Click(...
{
TextFromFile(); ????????????????????
}

public class TextFromFile
{
....
}
regards
reidarT
Nov 16 '05 #1
4 14571
ReidarT <re****@eivon.no> wrote:
How do I call a public class function in C# from a button
like


You can't "call" a class. You can call a method, or create an instance
of a class, and then call a method from that class. Or you could call a
static method. Now, what do you actually want to do?

(I would strongly advise learning the basics of C# before doing GUI
coding, btw. GUI coding has all kinds of added complications which will
be even harder to cope with if you're not confident about the basic
platform.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2

"ReidarT" <re****@eivon.no> wrote in message
news:un*************@TK2MSFTNGP15.phx.gbl...
How do I call a public class function in C# from a button
like

private void Button1_Click(...)
{
new TextFromFile();
}

public class TextFromFile
{
// do something
}
Nov 16 '05 #3
Oh No!

public void Button1_Click()
{
myClass c = new myClass()
c.MyMethod()
}

public class myClass
{
public void myMethod()
{
// Do Something
}
}

But you should (both) follow Jon Skeet's advice.

"Zach" wrote:

"ReidarT" <re****@eivon.no> wrote in message
news:un*************@TK2MSFTNGP15.phx.gbl...
How do I call a public class function in C# from a button
like

private void Button1_Click(...)
{
new TextFromFile();
}

public class TextFromFile
{
// do something
}

Nov 16 '05 #4
"Marinus Holkema" <Ma************@discussions.microsoft.com> wrote in
message news:01**********************************@microsof t.com...
Oh No!


*** Oh Yes! ***

Have fun!

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace WindowsApplication2
{
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.ComponentModel.Container components = null;
public Form1()
{
InitializeComponent();
}

<snipped>

#region Windows Form Designer generated code
<snipped>
#endregion
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void button1_Click(object sender, System.EventArgs e)
{
//******************
new Class1(1);
//******************
}
}
}

using System;
using System.Runtime.InteropServices;
namespace WindowsApplication2
{

public class Class1
{
[DllImport("kernel32.dll")]
public static extern bool Beep(int frequuency, int duration);

int tone;
public Class1(int tone)
{
this.tone = tone;
execute();
}
void execute()
{
if (tone == 0)
{
Random random = new Random();
for(int i = 0; i < 10000; i++)
{
Beep(random.Next(1000),100);
}
}

if(tone == 1)
{
Beep(800,100);
Beep(900,100);
Beep(800,100);
}
}
}
}
Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Klaus Friese | last post by:
Hi, i'm currently working on a plugin for Adobe InDesign and i have some problems with that. I'm not really a c++ guru, maybe somebody here has an idea how to solve this. The plugin is...
6
by: Jon Hyland | last post by:
Ok, I'm a little rusty on this, it should be a simple problem but I can't figure it out. How can I handle form events in my main code page?? I'm creating a Windows App in C#. Rather than make...
15
by: Bryan | last post by:
I have a multi-threaded C# console application that uses WMI (System.Management namespace) to make RPC calls to several servers (600+ ) and returns ScheduledJobs. The section of my code that...
2
by: a | last post by:
Hi Extremely easy question for someone who knows the answer I'm sure :-) (aren't they all) What exactly does LoadControl do? Whats the difference between calling this and just constructing a...
12
by: Ron | last post by:
Greetings, I am trying to understand the rational for Raising Events instead of just calling a sub. Could someone explain the difference between the following 2 scenarios? Why would I want to...
4
by: Fedor Semenov | last post by:
How can I call a base class' constructor from a derived class. Suppose I have: class Button // Base class { public: Button(void) { // Register classes, create the button, etc. } };
6
by: ahmad.humyn | last post by:
I want to call a hidden form. My code goes something like in which the main calls form1. form1 has a button which creates & calls form2 and hides itself. Now I have a button in form2 which if...
2
by: dunderhead | last post by:
Hello, I am having a problem with function and class syntax. I have one class (MakePanel1) that creates a button and label. The button-click event of the button is linked to a function...
2
by: sumanthsclsdc | last post by:
Hello friends, I have a problem, I implemented a class which uses tkinter and displays the window as required, the class will create a window with listbox and inserts some items into it, I...
23
by: Stewart Berman | last post by:
I am trying to develop a wrapper class for the Windows API functions in Visual Studio 2008: GetOpenFileName GetSaveFileName I put together a starter class: using System; using...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.