| | |
How can define custom events,properties
Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Dec 2007
Posts: 1
Reputation:
Solved Threads: 0
dear freinds,
from right clicking on project I have add New Item as Component class and change
component to TextBox. Then from Toolbox i have add Textbox from this component
Now, when i put the textbox from component i need a keypress event as a parent
event for all the textboxes.
pls guide for the same
thank a lot to all.
from right clicking on project I have add New Item as Component class and change
component to TextBox. Then from Toolbox i have add Textbox from this component
Now, when i put the textbox from component i need a keypress event as a parent
event for all the textboxes.
pls guide for the same
thank a lot to all.
•
•
Join Date: Oct 2007
Posts: 172
Reputation:
Solved Threads: 16
I didn't understand very well your quqestion but I guess u shoud add an event to your customized component as a textbox nested in a componen u can not use directly its properties methods and events. I give this solution may be the problem will be solved
assume that I have created a new component in witch I added a textBox called textBox1
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
namespace myTextBox
{
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
private string Text
{
get { return textBox1.Text; }
set { textBox1.Text = value; }
}
/*I can fire the TextBox1 event from a method that I define as
* public to be visible when I use the component later in the main project*/
private void FireTheKeyPressEvent()
{
// This line fire the event from this method
textBox1.KeyPress += new KeyPressEventHandler(textBox1_KeyPress);
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
// TO DO: implement the event handler method
}
}
}
assume that I have created a new component in witch I added a textBox called textBox1
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
namespace myTextBox
{
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
private string Text
{
get { return textBox1.Text; }
set { textBox1.Text = value; }
}
/*I can fire the TextBox1 event from a method that I define as
* public to be visible when I use the component later in the main project*/
private void FireTheKeyPressEvent()
{
// This line fire the event from this method
textBox1.KeyPress += new KeyPressEventHandler(textBox1_KeyPress);
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
// TO DO: implement the event handler method
}
}
}
•
•
Join Date: Oct 2007
Posts: 172
Reputation:
Solved Threads: 16
If u try the previous code The FireTheKeyPressEvent() will not appear in the method list when u instantiate a new compoment object now try to put public void FireTheKeyPressEvent() rather thant private void FireTheKeyPressEvent() u will see the method in the methods list of the object
I we summarize The KeyPress Event related to the textbox in the component will not appear within the component properties and method list except the u define it in the as a component class member and I insist that u define it as public
I we summarize The KeyPress Event related to the textbox in the component will not appear within the component properties and method list except the u define it in the as a component class member and I insist that u define it as public
![]() |
Other Threads in the C# Forum
- Previous Thread: Find focused control?
- Next Thread: how to insert image path
| Thread Tools | Search this Thread |
.net access algorithm array barchart bitmap box broadcast c# check checkbox client combobox control conversion csharp custom cyclethruopenforms data database datagrid datagridview dataset date/time datetime degrees development dll draganddrop drawing encryption enum event excel file finalyearproject form format forms function gdi+ getoutlookcontactusinfcsvfile globalization httpwebrequest image index input install installer java label list listbox mandelbrot math mono mouseclick mysql operator panel path photoshop picturebox pixelinversion post programming radians regex remote remoting richtextbox save server silverlight sleep socket sql sql-server statistics stream string table text textbox thread time timer timespan update usercontrol users validate validation visualstudio webbrowser wia windows winforms wpf xml





