0

Hi,

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 ?

Edited by happygeek: fixed formatting

3
Contributors
4
Replies
6
Views
8 Years
Discussion Span
Last Post by Ramy Mahrous
0

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;
}
0

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

0

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.Items.Add("1");
lstBoxForItems.Items.Add("2");
lstBoxForItems.Items.Add("3");
lstBoxForItems.Show();
this.Controls.Add(lstBoxForItems);
lstBoxForItems.SelectedIndexChanged += new EventHandler(lstBoxForItems_SelectedIndexChanged);
        }

        void lstBoxForItems_SelectedIndexChanged(object sender, EventArgs e)
        {
            MessageBox.Show(lstBoxForItems.SelectedItem.ToString());
        }
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.