Hi,
This question is somewhat basic. Is it possible to call a method in
frmMain, using another class? Here's a snippet:
partial class frmMain : Form
{
private void MessageThis(Str ing text)
{
MessageBox.Show (text);
}
}
public class AnotherClass
{
public AnotherClass(te xt)
{
frmMain.Message This(text); //doesn't work
MessageThis(tex t); //doesn't work
//and so on...
}
}
I've dabbled with public and static methods, etc, but I can't seem to
find the correct way.
Thanks. 4 1537
MessageThis() is private, which means it can only be called from frmMain.
Making it public will make it callable from AnotherClass, but only if
AnotherClass has an instance of frmMain available to it, for example:
frmMain frm = new frmMain();
frm.MessageThis (text);
The above is a trivial example to get the idea across of needing an instance
variable to call the method from. I realize that you wouldn't likely
actually use it the way I illustrate.
Making MessageThis() public AND static would make it callable as
frmMain.Message This() (that is, will make the method available from the
class itself without requiring an instance) but I presume that MessageThis()
is supposed to receive a message on behalf of an instance of frmMain; if so,
then making the method static wouldn't work because the method wouldn't then
have access to instance data of frmMain.
If you could explain what you're actually trying to accomplish perhaps we
could find a way to your solution.
--Bob
"Typpo" <ot********@opt online.net> wrote in message
news:ut******** *****@TK2MSFTNG P10.phx.gbl... Hi,
This question is somewhat basic. Is it possible to call a method in frmMain, using another class? Here's a snippet:
partial class frmMain : Form { private void MessageThis(Str ing text) { MessageBox.Show (text); } }
public class AnotherClass { public AnotherClass(te xt) { frmMain.Message This(text); //doesn't work MessageThis(tex t); //doesn't work //and so on... } }
I've dabbled with public and static methods, etc, but I can't seem to find the correct way.
Thanks.
Using the following code:
frmMain frm = new frmMain();
frm.MessageThis (text);
Works fine. The problem is, I'm creating a new form in the process and
frm.Show() reveals a duplicate. The method is called correctly,
however, and the intended effect takes place on the duplicate form. The
original form isn't changed at all.
I'm sorry if I was vague. Here's what I am trying to do...
On the main form, the user presses a button that loads a dialog form
that he or she fills out. The dialog form creates a new class that
organizes the information, and I would like to have the class or the
dialog form call a method contained in the main form's class. This
method adds the information to a list on the main form.
Thanks for your help. I hope I'm making sense =/.
Bob Grommes wrote: MessageThis() is private, which means it can only be called from frmMain.
Making it public will make it callable from AnotherClass, but only if AnotherClass has an instance of frmMain available to it, for example:
frmMain frm = new frmMain(); frm.MessageThis (text);
The above is a trivial example to get the idea across of needing an instance variable to call the method from. I realize that you wouldn't likely actually use it the way I illustrate.
Making MessageThis() public AND static would make it callable as frmMain.Message This() (that is, will make the method available from the class itself without requiring an instance) but I presume that MessageThis() is supposed to receive a message on behalf of an instance of frmMain; if so, then making the method static wouldn't work because the method wouldn't then have access to instance data of frmMain.
If you could explain what you're actually trying to accomplish perhaps we could find a way to your solution.
--Bob
"Typpo" <ot********@opt online.net> wrote in message news:ut******** *****@TK2MSFTNG P10.phx.gbl...
Hi,
This question is somewhat basic. Is it possible to call a method in frmMain, using another class? Here's a snippet:
partial class frmMain : Form { private void MessageThis(Str ing text) { MessageBox.Sh ow(text); } }
public class AnotherClass { public AnotherClass(te xt) { frmMain.Messa geThis(text); //doesn't work MessageThis(t ext); //doesn't work //and so on... } }
I've dabbled with public and static methods, etc, but I can't seem to find the correct way.
Thanks.
Why don't you just pass a reference to your class object to the dialog form
so it can provide the information back to your main form.
Greg
"Typpo" <ot********@opt online.net> wrote in message
news:OF******** ********@TK2MSF TNGP15.phx.gbl. .. Using the following code:
frmMain frm = new frmMain(); frm.MessageThis (text);
Works fine. The problem is, I'm creating a new form in the process and frm.Show() reveals a duplicate. The method is called correctly, however, and the intended effect takes place on the duplicate form. The original form isn't changed at all.
I'm sorry if I was vague. Here's what I am trying to do...
On the main form, the user presses a button that loads a dialog form that he or she fills out. The dialog form creates a new class that organizes the information, and I would like to have the class or the dialog form call a method contained in the main form's class. This method adds the information to a list on the main form.
Thanks for your help. I hope I'm making sense =/.
Bob Grommes wrote: MessageThis() is private, which means it can only be called from
frmMain. Making it public will make it callable from AnotherClass, but only if AnotherClass has an instance of frmMain available to it, for example:
frmMain frm = new frmMain(); frm.MessageThis (text);
The above is a trivial example to get the idea across of needing an
instance variable to call the method from. I realize that you wouldn't likely actually use it the way I illustrate.
Making MessageThis() public AND static would make it callable as frmMain.Message This() (that is, will make the method available from the class itself without requiring an instance) but I presume that
MessageThis() is supposed to receive a message on behalf of an instance of frmMain; if
so, then making the method static wouldn't work because the method wouldn't
then have access to instance data of frmMain.
If you could explain what you're actually trying to accomplish perhaps
we could find a way to your solution.
--Bob
"Typpo" <ot********@opt online.net> wrote in message news:ut******** *****@TK2MSFTNG P10.phx.gbl...
Hi,
This question is somewhat basic. Is it possible to call a method in frmMain, using another class? Here's a snippet:
partial class frmMain : Form { private void MessageThis(Str ing text) { MessageBox.Sh ow(text); } }
public class AnotherClass { public AnotherClass(te xt) { frmMain.Messa geThis(text); //doesn't work MessageThis(t ext); //doesn't work //and so on... } }
I've dabbled with public and static methods, etc, but I can't seem to
findthe correct way.
Thanks.
Sorry Greg, I'm not sure what you mean by that. I have an array of
class objects.
How would I pass, say, myClass[2] to the dialog form and have it return
the info filled out back to the main form?
Thanks again.
news.microsoft. com wrote: Why don't you just pass a reference to your class object to the dialog form so it can provide the information back to your main form.
Greg
"Typpo" <ot********@opt online.net> wrote in message news:OF******** ********@TK2MSF TNGP15.phx.gbl. ..
Using the following code:
frmMain frm = new frmMain(); frm.MessageTh is(text);
Works fine. The problem is, I'm creating a new form in the process and frm.Show() reveals a duplicate. The method is called correctly, however, and the intended effect takes place on the duplicate form. The original form isn't changed at all.
I'm sorry if I was vague. Here's what I am trying to do...
On the main form, the user presses a button that loads a dialog form that he or she fills out. The dialog form creates a new class that organizes the information, and I would like to have the class or the dialog form call a method contained in the main form's class. This method adds the information to a list on the main form.
Thanks for your help. I hope I'm making sense =/.
Bob Grommes wrote:
MessageThis( ) is private, which means it can only be called from frmMain. Making it public will make it callable from AnotherClass, but only if AnotherCla ss has an instance of frmMain available to it, for example:
frmMain frm = new frmMain(); frm.MessageT his(text);
The above is a trivial example to get the idea across of needing an instance variable to call the method from. I realize that you wouldn't likely actually use it the way I illustrate.
Making MessageThis() public AND static would make it callable as frmMain.Mess ageThis() (that is, will make the method available from the class itself without requiring an instance) but I presume that MessageThis() is supposed to receive a message on behalf of an instance of frmMain; if so, then making the method static wouldn't work because the method wouldn't then have access to instance data of frmMain.
If you could explain what you're actually trying to accomplish perhaps we could find a way to your solution.
--Bob
"Typpo" <ot********@opt online.net> wrote in message news:ut***** ********@TK2MSF TNGP10.phx.gbl. ..
Hi,
This question is somewhat basic. Is it possible to call a method in frmMain, using another class? Here's a snippet:
partial class frmMain : Form { private void MessageThis(Str ing text) { MessageBox. Show(text); } }
public class AnotherClass { public AnotherClass(te xt) { frmMain.Mes sageThis(text); //doesn't work MessageThis (text); //doesn't work //and so on... } }
I've dabbled with public and static methods, etc, but I can't seem to find the correct way.
Thanks.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: LRW |
last post by:
Having a problem getting a onSubmit function to work, to where it popsup a
confirmation depending on which radiobutton is selected.
Here's what I have:
function checkdel() {
if (document.getElementById"].value=='1') {
confirm('Are you sure you want to delete this file?');
}
}
......
|
by: JSM |
last post by:
Hi,
I have a form (FormA) which was loaded using Application.Run when my app
loads. This form has a button which loads Form B using "FormB myForm=new
FormB()". My question is, how do I access and modify the value of a control
on FormA from FormB?
I thought this would be easy but I was wrong.
Cheers,
|
by: jm |
last post by:
Easy probably, please read on. I know some of you have commented
already about some of my socket question. I appreciate that.
I have a Form1:
static void Main()
{
Application.Run(new Form1());
clsListening.AsynchronousSocketListener.StartListening();
|
by: Hazzard |
last post by:
I just realized that the code I inherited is using all asp.net server
controls (ie. webform controls) and when I try to update textboxes on the
client side, I lose the new value of the textbox when submitting the form to
update the database. The server doesn't have the client side value any more.
It seems to me that as I begin to write the client side javacript code for
form validation and client side editing capabilities in order to save...
|
by: 42 |
last post by:
I implemented a simple class inherited from Page to create a page
template. It simply wraps some trivial html around the inherited page,
and puts the inherited page into a form.
The problem I have run into is that the emitted html at the end of the
process is slightly different and doesn't work.
Please don't be put off by all the source code. All the guts are in this
first base class, and it doesn't do much. The rest is trivial...
| |
by: Joe |
last post by:
Hello All,
I have a very simple form as you can here. This form has one Textbox and
one Button named Download. In ASP after tying in the text box even if I hit
enter, the form was getting submitted but in ASP.NET this is not happening.
The form is not submitted until I click on the Download button. Can someone
tell me how I can change this so that after tying the text in the Textbox if
someone hits Enter, the form will be submitted? ...
|
by: Ranginald |
last post by:
Sorry for the simple question but thanks in advance:
My goal is to create reusale code for a web app in C#.
I have written the code already as a windows app but here is where I am
confused:
To keep it really easy let's say this is the code:
function addition(int, int);
int X;
|
by: njuneardave |
last post by:
Hey,
this is a simple question. I am new to the whole visual C# scene.
I am creating a simple "Find Word" dialog box. I have the menu working: File -> Find -> Find Word....then it pops up my alternate form. On the form, there is a textbox entry field. I want to take the text from that textbox and search for it in a rich text box in the original form....here's a snippet of my code that is giving me an error:
String searchKey =...
|
by: RSH |
last post by:
I have a simple question regarding inheritance in a web form.
I have a DropDownList in an aspx form. It is called DropDownList1
I have a class that will be overriding the render event so I have a snippet
of this class:
Public Class CustomDDL
Inherits DropDownList
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |