In C#, how would I use a delegate to manipulate a form from a custom class I made? -
I know that manipulation of a text box on a form with a form, but I do not know how a textbox Manipulate a class in any file in a form.
Can anyone tell me how I will write a representative; So a callback I could call a method from a class in a different file, and could have changed the stuff on a text box in a different way?
I do not know how I can explain that it will be better than any thanks for any help!
Your class should not change the form.
However, you can create a representative or an incident in your class, and increase your incidence of the incident when some action should be taken. Your form can attach an eventholder to this event, and execute the appraisal action.
For example:
class MyClass {public event eventHandler dosoming; Public Zero DoWork () {// Some Accessories // DoSomething Event Increase OnDoSomething (EventArgs.Empty); } Protected Virtual Zero Endorsement (EventArgs args) {// This code will ensure that you do not have any illegal illegal thread display // Exception, and to avoid race conditions // Note that it will not work in wpf you will not sync You can also see a look at CONTACTX class I event handler handler = dosoming; If (handler! = Null) {ISynchronizeInvoke target = handler. Target as ISynchronizeInvoke; If (Target! = Null & amp; Target.InvoquerEquare) {target.Invoke (Handler, New Object [] {this, args}); } Other {handlers (this, args); }}}} And, in your form, you do this:
MyClass c = new MyClass (); C.DoSomething + = New EventHandler (MyClass_DoSomething); C.DoWork (); Private Zero MyClass_DoSomething (Object Sender, EventArgs E) {// Manipulate Your Form Text Box1.Text = "..."; } When you want to pass some data from your class into your form, you can use the Generic EventHandler representative, and create your own EventArgs class, in which the information Forms are required.
Public category MyEventArgs: EventArgs {public string SomeData {get; Private set; } Public MyEventArgs (strings) {this.SomeData = s; }} Then off course, you have to use Generic Event Holder in your class, and give proper data to the constructor of your own events class. In Eventhandler, you can then use this data.
Comments
Post a Comment