Hi,
I have a form that I need to place 3 buttons on. I would like the 3
buttons to call the same method, perhaps with different arguments.
In Powerbuilder, I could create a visual button object and code for
it, then inherit from that and place it on my form/window.
Does C# have anything like this? Is this possible?
Thanks! 4 4518
Soulless wrote:
Hi,
I have a form that I need to place 3 buttons on. I would like the 3
buttons to call the same method, perhaps with different arguments.
Why not simply provide the same event handler for all three buttons?
If they will all call the same method with different arguments, you may
as well just have three separate event handlers.
If say two of the three will be the same, it might be simpler to have
them share an event handler then check the sender, a la:
Button first = new Button("One");
Button second = new Button("Two");
Button third = new Button("Three") ;
first.Click += new EventHandler(my SpecialButton_C lick);
second.Click += new EventHandler(my SpecialButton_C lick);
third.Click += new EventHandler(my SpecialButton_C lick);
private void mySpecialButton _Click(object sender, EventArgs e)
{
if (sender == first)
SomeOtherMethod ("arg1", "arg2", overloaded_int) ;
else
SomeOtherMethod ("arg1", "arg2");
}
Either way, it doesn't look like you need inheritance at all.
Chris.
On Oct 12, 3:15 pm, Chris Shepherd <c...@nospam.ch sh.cawrote:
Soulless wrote:
Hi,
I have a form that I need to place 3 buttons on. I would like the 3
buttons to call the same method, perhaps with different arguments.
Why not simply provide the same event handler for all three buttons?
If they will all call the same method with different arguments, you may
as well just have three separate event handlers.
If say two of the three will be the same, it might be simpler to have
them share an event handler then check the sender, a la:
Button first = new Button("One");
Button second = new Button("Two");
Button third = new Button("Three") ;
first.Click += new EventHandler(my SpecialButton_C lick);
second.Click += new EventHandler(my SpecialButton_C lick);
third.Click += new EventHandler(my SpecialButton_C lick);
private void mySpecialButton _Click(object sender, EventArgs e)
{
if (sender == first)
SomeOtherMethod ("arg1", "arg2", overloaded_int) ;
else
SomeOtherMethod ("arg1", "arg2");
}
Either way, it doesn't look like you need inheritance at all.
Chris.
Thanks!!!!
Soulless,
this is called overriding method in the Object oriented programming, find
below a good guide for that http://www.devhood.com/tutorials/tut...utorial_id=328
regards,
Husam Al-A'araj www.aaraj.net
"Soulless" wrote:
Hi,
I have a form that I need to place 3 buttons on. I would like the 3
buttons to call the same method, perhaps with different arguments.
In Powerbuilder, I could create a visual button object and code for
it, then inherit from that and place it on my form/window.
Does C# have anything like this? Is this possible?
Thanks!
Soulless <dg*******@gmai l.comwrote:
I have a form that I need to place 3 buttons on. I would like the 3
buttons to call the same method, perhaps with different arguments.
In Powerbuilder, I could create a visual button object and code for
it, then inherit from that and place it on my form/window.
Does C# have anything like this? Is this possible?
Well, you *can* derive from Button - but I wouldn't advise it in this
case. Why not just use three separate instances of the normal button
class, and hook the Click events up to the same method?
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: relaxedrob |
last post by:
Hi All!
I have a page with with the following style information:
<link rel="stylesheet" type="text/css" href="/eEmployment/eTech.css"
/>
<style type="text/css">
DIV.Application {
BACKGROUND-IMAGE:url(/someImage.jpg);
}
|
by: Noah Coad [MVP .NET/C#] |
last post by:
How do you make a member of a class mandatory to override with a _new_
definition? For example, when inheriting from
System.Collections.CollectionBase, you are required to implement certain
methods, such as public void Add(MyClass c).
How can I enforce the same behavior (of requiring to implement a member with
a new return type in an inherited class) in the master class (similar to the
CollectionBase)?
I have a class called...
|
by: Kitchen Bin |
last post by:
HELP PLEASE!! The C# Visual Studio IDE is failing to load an
inherited form into the IDE from a base form when I add items to an
array property of a user control on the base form. That sounds
confusing but let me explain:
I have a UserControl, let's call it "ButtonArrayControl", and also a
separate class for holding various properties:
public class MyButtonProperties
|
by: Anthony Williams |
last post by:
Morning all,
I'm having a wee problem with a project I'm working on at the moment.
I'm leading my company into producing a website, based upon Web
Standards, which will be created using XHTML and CSS, and powered by
ASP.NET.
My first problem, which I'm near to solving, was that ASP.NET doesn't
produce valid XHTML output. We don't want to spend money on third-party
components, and we can't wait for ASP.NET 2.0, so we needed to find a
|
by: Charles Law |
last post by:
I want a set of controls that all have a border, like a group box. I thought
I would create a base control containing just a group box from which my set
of controls could inherit. Assuming that this is the right approach (please
tell me if it is not), how then do I make it so that the group box cannot be
moved around on my set of controls, but is also able to act as container for
other controls?
If I leave the modifier of the group box...
| |
by: Billy |
last post by:
I created a form, BaseForm, with a button as sort of a base class for some future windows. I added a button and put a simple MsgBox in the _click event that says "Hi from base" and I set the button's modifier property to "Protected."
Created DerivedForm inherited from BaseForm. Was able to go in and add a MsgBox to the _Click event for the button (as expected) that says "Hi from derived". When I run the app and click the button, I get both...
|
by: Xero |
last post by:
Hello. I am using vb.net.
There are two forms in my project. One is 'base' and the other one is
'savecurrent'.
There is a value stored in a textbox called 'qc_a' in 'base'. I want to
inherit it in 'savecurrent' when a button (located in 'savecurrent') is
clicked. So a declared an Object varible, whose name is 'equation' in
'savecurrent' and typed in the following code:
|
by: Alex Satrapa |
last post by:
There's some mention in the (old!) documentation that constraints such as foreign keys won't include data from inheriting tables, eg:
CREATE TABLE foo (
id SERIAL PRIMARY KEY
);
CREATE TABLE bar (
attribute integer NOT NULL
) INHERITS (foo);
|
by: Dominique |
last post by:
I'm trying to create a C# composite control and have inherited
from UserControl. This new control contains 9 buttons with images on
them ( no text ).
Firstly, what is the best way to expose these 9 buttons to the
developers who will be using my control. I want them to be able to
change visibility, enablement, onClick etc for each button, but not be
able add any new buttons. I initially thought of exposing them as some
kind of fixed...
|
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: 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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |