| | |
Accesing variable/function in Control using (Control)Sender
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Aug 2006
Posts: 14
Reputation:
Solved Threads: 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 ?
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 ?
Sure, cast it to ShapeControl because Control class doesn't contain Growing property.
c# Syntax (Toggle Plain Text)
private void Grow(object sender, EventArgs e) { Shape controlAll = (Shape)sender; controlAll.Growing = 50; }
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
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)
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()); }
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
![]() |
Other Threads in the C# Forum
- Previous Thread: Dot Net Frame Worke + Crystal Report + windows installer dll file
- Next Thread: c# windows application
| Thread Tools | Search this Thread |
Tag cloud for C#
.net access algorithm array barchart bitmap box buttons c# chat check checkbox class client color combobox control conversion csharp custom database datagrid datagridview dataset datetime degrees draganddrop drawing encryption enum event excel file files form format forms ftp function gdi+ httpwebrequest image index input install java label list listbox listener login mandelbrot math mouseclick mysql networking object operator oracle path photoshop picturebox pixelinversion post prime programming radians regex remote remoting resource richtextbox save saving serialization server sleep socket sql statistics stream string table tcp text textbox thread time timer treeview update usercontrol validation view visualstudio webbrowser windows winforms wpf xml






