473,969 Members | 22,704 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

c# : implement OnClick into Object

Hallo,

I'm a newbie and try to learn C# while trying to progr. a
little game which in affect touches all aspects of the language:
syntax, arrays, painting, events .... so on events I be stuck:

is it possible (and how) to implement an OnClick-Event into a
class derived from :Object. i know it's easy to have it derived from
UserControls/Controls and higher Objects - but that seems for me
to have to much overhead for a simple Object.
Background:
Have a class that paints a rectangle on constructors call with some
other properties set. At least I need to have many of these rectangles.
Also any of them needs to have a OnClick to be identified an moved
at Click-event. How is this event to implement - anybody can give some
code-examples, please?

Regards
Willy
Nov 16 '05 #1
2 5990
Hi,

You've go to add Click event:

public event EventHandler Click;

And you should implement very useful protected method,
that will raise that event:

protected virtual void OnClick(EventAr gs e) {
if( this.Click!=nul l ) {
this.Click(e);
}
}

The problem is that you'll have to find a way to
call "OnClick" method. Buttons have a "PerformCli ck"
method to do this in standard.

Cheers!

Marcin
Hallo,

I'm a newbie and try to learn C# while trying to progr. a
little game which in affect touches all aspects of the language:
syntax, arrays, painting, events .... so on events I be stuck:

is it possible (and how) to implement an OnClick-Event into a
class derived from :Object. i know it's easy to have it derived from
UserControls/Controls and higher Objects - but that seems for me
to have to much overhead for a simple Object.
Background:
Have a class that paints a rectangle on constructors call with some
other properties set. At least I need to have many of these rectangles.
Also any of them needs to have a OnClick to be identified an moved
at Click-event. How is this event to implement - anybody can give some
code-examples, please?

Regards
Willy

Nov 16 '05 #2
Short summery,
sorry I have no imagine to "Create Custom Event" which handles MouseClicks
on Objects that Paint a Rectangle???

"Sreejith S S Nair" <Sr************ @discussions.mi crosoft.com> schrieb im
Newsbeitrag news:AC******** *************** ***********@mic rosoft.com...
hi,

Best choice is Creating Custom Event

Nov 16 '05 #3

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

Similar topics

6
14418
by: Andrus Moor | last post by:
I want to add a refresh button to my web page which works like browser refresh button: it must re-load current page from server. How to implement this in javascript ?
2
18596
by: RobG | last post by:
I am trying to dynamically add an onclick to an element, however I just can't get the syntax right. consider the following function: function doClick (evt,x) { // do things with evt and x } Which is called statically by: <button onclick="doClick(event,this);">Click me</button>
17
4903
by: abs | last post by:
My element: <span onclick="alert('test')" id="mySpan">test</span> Let's say that I don't know what is in this span's onclick event. Is it possible to add another action to this element's onclick event ? I've tried something like this: oncl = document.getElementById('mySpan').onclick oncl = oncl + '\n;alert(\'added\')' document.getElementById('mySpan').onclick = oncl
7
1761
by: Brian Henry | last post by:
Hi, I am doing the following stored procedure CREATE PROCEDURE . @sender varchar(50), @subject varchar(400), @messagebody text, @hasAttachments bit, @sentTime DateTime AS
5
2140
by: Fred.Grieco | last post by:
Hi every body, I have a little pb and I'm turning around : function MyFCTN(var1,var2) { var mytable = document.getElementById("myTBL"); for (var i=myTBL.childNodes.length-1; i>0; i--){ myTBL.removeChild(myTBL.childNodes); } for(var i=0; i<var1.length; i++){
2
9170
by: bartlomiej.szafraniec | last post by:
Hi! I'm trying to implement custom button. But I don't want to extend Button class. I want to extend Control class. I want to implement Enable disable functionality. But unfortunatly when control is in Enable = false state the on click event is not called but that event is passed to parent object. How to convince my custom button class not to pass Click events to parent classes when my class is in Disabled state?
1
9143
by: OceanBreeze | last post by:
I am using ASP 2.0 and C# I have a TextBox control in .aspx file. <asp:TextBox ID="CityTxt" runat="server"></asp:TextBox> When I click on that text box, I want to trigger onClick event. onClick event is not in ASP 2.0 and gives error.
18
3957
by: joaotsetsemoita | last post by:
Hello everyone, I'm having troubles assigning an onclick event to a cell. Im trying something like cursorPoint.cells.style.cursor = "hand"; cursorPoint.cells.width = "20"; cursorPoint.cells.onclick = "alert('this is a test');" cursorPoint.cells.alt = "Select the columns"; cursorPoint.cells.innerHTML = "&nbsp;"
0
10338
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10149
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,...
0
11802
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, 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...
0
11394
jinu1996
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...
1
11541
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,...
0
10886
tracyyun
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...
0
10056
agi2029
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...
0
6393
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...
2
4720
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.