I've created a partial class : Control for designing the shape of my polygon.
It works well but there's one problem that I tried to find on net but I get nothing.

I've created one int named 'size'. Then I created a function named 'Growing' for 'get' and 'set'.
When I created an object from that class, I just type on the object name.Growing, then I can 'get' the size and 'set' the size.
This no problem.

The problem exist when I created as follow:

private void Grow(object sender, EventArgs e)
Control controlAll =  (Control)sender;


This 'controlAll' is use to track which polygon I choose.
but when I run this line of code, it seems like controlAll can't get to the function I declared in the class "Growing"

controlAll.Growing = 50; // ERROR WENT HERE

Is there any ways to make the control to identified the function that I created in the class ? Any idea ?

Recommended Answers

All 4 Replies

Sure, cast it to ShapeControl because Control class doesn't contain Growing property.

private void Grow(object sender, EventArgs e)
Shape controlAll = (Shape)sender; 
controlAll.Growing = 50;

your good idol

but do you know how to access an object that had been done through a instance for example when i click a button it will create a list box then how can i get the selected item of that list box

Very easy, I'll write code, when user presses on the button, it creates object fron ListBox type and create an event for it also...

private void Grow(object sender, EventArgs e)
ListBox lstBoxForItems = new ListBox();
lstBoxForItems.SelectedIndexChanged += new EventHandler(lstBoxForItems_SelectedIndexChanged);

        void lstBoxForItems_SelectedIndexChanged(object sender, EventArgs e)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.