943,536 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 2321
  • C# RSS
Jul 21st, 2008
0

Accesing variable/function in Control using (Control)Sender

Expand Post »
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 ?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
karhong is offline Offline
14 posts
since Aug 2006
Jul 21st, 2008
0

Re: Accesing variable/function in Control using (Control)Sender

Sure, cast it to ShapeControl because Control class doesn't contain Growing property.
c# Syntax (Toggle Plain Text)
  1. private void Grow(object sender, EventArgs e)
  2. {
  3. Shape controlAll = (Shape)sender;
  4. controlAll.Growing = 50;
  5. }
Featured Poster
Reputation Points: 480
Solved Threads: 276
Postaholic
Ramy Mahrous is offline Offline
2,189 posts
since Aug 2006
Aug 13th, 2008
0

Re: Accesing variable/function in Control using (Control)Sender

your good idol
Reputation Points: 10
Solved Threads: 0
Newbie Poster
nevoj is offline Offline
3 posts
since Jul 2008
Aug 13th, 2008
0

Re: Accesing variable/function in Control using (Control)Sender

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
nevoj is offline Offline
3 posts
since Jul 2008
Aug 15th, 2008
0

Re: Accesing variable/function in Control using (Control)Sender

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...
c# Syntax (Toggle Plain Text)
  1. private void Grow(object sender, EventArgs e)
  2. {
  3. ListBox lstBoxForItems = new ListBox();
  4. lstBoxForItems.Items.Add("1");
  5. lstBoxForItems.Items.Add("2");
  6. lstBoxForItems.Items.Add("3");
  7. lstBoxForItems.Show();
  8. this.Controls.Add(lstBoxForItems);
  9. lstBoxForItems.SelectedIndexChanged += new EventHandler(lstBoxForItems_SelectedIndexChanged);
  10. }
  11.  
  12. void lstBoxForItems_SelectedIndexChanged(object sender, EventArgs e)
  13. {
  14. MessageBox.Show(lstBoxForItems.SelectedItem.ToString());
  15. }
Featured Poster
Reputation Points: 480
Solved Threads: 276
Postaholic
Ramy Mahrous is offline Offline
2,189 posts
since Aug 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Dot Net Frame Worke + Crystal Report + windows installer dll file
Next Thread in C# Forum Timeline: c# windows application





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC