Search Results

Search found 461 results on 19 pages for 'eventhandler'.

Page 3/19 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Java, Jacob and Microsoft Outlook events: Receiving "Can't find event iid" Error

    - by Adam Paynter
    I am writing a Java program that interacts with Microsoft Outlook using the Jacob library (bridges COM and Java). This program creates a new MailItem, displaying its Inspector window to the user. I wish to subscribe to the inspector's Close event to know when the user is finished editing their mail item. To subscribe to the event, I followed the instructions in Jacob's documentation (about 2⁄3 down the page): The current [event] model is conceptually similar to the Visual Basic WithEvents construct. Basically, I provide a class called com.jacob.com.DispatchEvents which has a constructor that takes a source object (of type com.jacob.com.Dispatch) and a target object (of any type). The source object is queried for its IConnectionPointContainer interface and I attempt to obtain an IConnectionPoint for its default source interface (which I obtain from IProvideClassInfo). At the same time, I also create a mapping of DISPID's for the default source interface to the actual method names. I then use the method names to get jmethodID handles from the target Java object. All event methods currently must have the same signature: one argument which is a Java array of Variants, and a void return type. Here is my InspectorEventHandler class, conforming to Jacob's documentation: public class InspectorEventHandler { public void Activate(Variant[] arguments) { } public void BeforeMaximize(Variant[] arguments) { } public void BeforeMinimize(Variant[] arguments) { } public void BeforeMove(Variant[] arguments) { } public void BeforeSize(Variant[] arguments) { } public void Close(Variant[] arguments) { System.out.println("Closing"); } public void Deactivate(Variant[] arguments) { } public void PageChange(Variant[] arguments) { } } And here is how I subscribe to the events using this InspectorEventHandler class: Object outlook = new ActiveXComponent("Outlook.Application"); Object mailItem = Dispatch.call(outlook, "CreateItem", 0).getDispatch(); Object inspector = Dispatch.get(mailItem, "GetInspector").getDispatch(); InspectorEventHandler eventHandler = new InspectorEventHandler(); // This supposedly registers eventHandler with the inspector new DispatchEvents((Dispatch) inspector, eventHandler); However, the last line fails with the following exception: Exception in thread "main" com.jacob.com.ComFailException: Can't find event iid at com.jacob.com.DispatchEvents.init(Native Method) at com.jacob.com.DispatchEvents.(DispatchEvents.java) at cake.CakeApplication.run(CakeApplication.java:30) at cake.CakeApplication.main(CakeApplication.java:15) couldn't get IProvideClassInfo According to Google, a few others have also received this error. Unfortunately, none of them have received an answer. I am using version 1.7 of the Jacob library, which claims to prevent this problem: Version 1.7 also includes code to read the type library directly from the progid. This makes it possible to work with all the Microsoft Office application events, as well as IE5 events. For an example see the samples/test/IETest.java example. I noticed that the aforementioned IETest.java file subscribes to events like this: new DispatchEvents((Dispatch) ieo, ieE,"InternetExplorer.Application.1"); Therefore, I tried subscribing to my events in a similar manner: new DispatchEvents((Dispatch) inspector, eventHandler, "Outlook.Application"); new DispatchEvents((Dispatch) inspector, eventHandler, "Outlook.Application.1"); new DispatchEvents((Dispatch) inspector, eventHandler, "Outlook.Application.12"); All these attempts failed with the same error.

    Read the article

  • numeric updown control c#

    - by Raghav
    I am using numeric updowncontrol. For min and max values changed listening for these events this.numDownMinLimit.ValueChanged += new System.EventHandler(this.numDownMinLimit_ValueChanged); this.numDownMaxLimit.ValueChanged += new System.EventHandler(this.numDownMaxLimit_ValueChanged); step size set is 0.1 The eventhandler takes some time to complete. If you keep the mouse pressed for a period of time and then release it, the eventhandler still executes with the previous values which were fired. How do we prevent this scenario from occurring? I would like to discard the remaining events which are still in the queue, waiting to be handled, when the user releases the mouse button.

    Read the article

  • Does O2Micro Oz776 Smartcard reader support SLE5528 cards?

    - by Proton
    Well, the title seems indicating I'm a lazy guy but it's not the truth... I'm messing with this weird circumstance a whole day. My laptop is a Dell Latitude D630 which has a Oz776 (usb idVendor == 0x0b97, idProduct == 0x7772) smartcard reader, but I'm not sure if it is functioning well. It can successfully recognize my Gemplus GPK4000 smartcard and my SIM card, but not SLE5528. This is my pcscd log when insert the GPK4000: 06039271 ifdhandler.c:1043:IFDHPowerICC() action: PowerUp, usb:0b97/7772:libhal:/org/freedesktop/Hal/devices/usb_device_b97_7772_noserial_if0 (lun: 0) 00000100 - 000000 62 00 00 00 00 00 14 01 00 00 00967744 <- 000000 80 0A 00 00 00 00 14 00 00 00 3B 27 00 80 65 A2 0C 01 01 37 00000048 ATR: 3B 27 00 80 65 A2 0C 01 01 37 00000013 atrhandler.c:102:ATRDecodeAtr() Conv: 01, Y1: 02, K: 07 00000011 atrhandler.c:120:ATRDecodeAtr() TA1: FFFFFFFF, TB1: 00, TC1: FFFFFFFF, TD1:FFFFFFFF 00000011 atrhandler.c:248:ATRDecodeAtr() CurrentProtocol: 1, AvailableProtocols: 1 00000062 eventhandler.c:429:EHStatusHandlerThread() Card inserted into O2 Micro Oz776 00 00 00000014 Card ATR: 3B 27 00 80 65 A2 0C 01 01 37 29016873 eventhandler.c:361:EHStatusHandlerThread() Card Removed From O2 Micro Oz776 00 00 This is the log when insert a SLE5528 card: 99999999 ifdhandler.c:1043:IFDHPowerICC() action: PowerUp, usb:0b97/7772:libhal:/org/freedesktop/Hal/devices/usb_device_b97_7772_noserial_if0 (lun: 0) 00000048 - 000000 62 00 00 00 00 00 11 01 00 00 ** Then it chokes here, when I remove the card, the log continues ** 04741980 <- 000000 80 00 00 00 00 00 11 42 FE 00 00000044 commands.c:225:CmdPowerOn Card absent or mute 00000017 ifdhandler.c:1096:IFDHPowerICC() PowerUp failed 00000082 eventhandler.c:429:EHStatusHandlerThread() Card inserted into O2 Micro Oz776 00 00 00000021 eventhandler.c:443:EHStatusHandlerThread() Error powering up card. 00402818 eventhandler.c:361:EHStatusHandlerThread() Card Removed From O2 Micro Oz776 00 00 I found that SLE5528 is ISO7816 compatible, and it should have ATR, but it just chokes at the PowerUp. When inserted any PVC card with no chip or AT24C01 card, it would not choke but report immediate PowerUp failure. When I tried it on Windows(Windows 7, "runas other user", smartcard login), it chokes too while PVC cards and AT24C01 report immediate failure.

    Read the article

  • Pass an Event as parameter

    - by dkson
    I have a class which bundles events and registers controls to easily register/unregister them, it's basically used this way: Private Sub MyFocusHandler(ByVal sender As Object, ...) ... End Sub ... Dim b1 = new MyTextBox() Dim b2 = new MyTextBox() .... 'Lot of Controls' Dim cr = new ControlRegistration() cr.RegisterControl(b1) cr.RegisterControl(b2) .... 'Register a lot of controls' cr.RegisterEvent("Focus",New EventHandler(AddressOf MyFocusHandler)) cr.RegisterEvent("Validate",New EventHandler(AddressOf MyValidateHandler)) So I don't have to add the handlers manually for each control. The ControlRegistration-Class will cycle through the list of registered controls and check if a control has a registered event and then attach the eventhandler, something like: ... For Each control in contols Dim ev_info As Reflection.EventInfo = _ control.GetType().GetEvent(.GetType().GetEvent(event_name)) If Not (ev_info Is Nothing) Then ev_info.AddEventHandler ... ... My problem is that i am identifying the event by a string Public Sub RegisterEvent(ByVal eventName As String, ByVal handler As [Delegate]) ... ... cr.RegisterEvent("Focus",New EventHandler(AddressOf MyFocusHandler)) I don't want to depend on the name of the event, since it is possibly that the name changes, and then things will break up. Is there a way I can do this like: Public Sub RegisterEvent(ByVal theEvent As ???, ByVal handler As [Delegate]) ... ... cr.RegisterEvent(IMyControl.MyEvent,New EventHandler(AddressOf MyEventHandler)) I hope it is clear what I want to archive. Anybody any ideas? Thanks

    Read the article

  • How to pass event to method?

    - by tomaszs
    I would like to create a method that takes as a argument an event an adds eventHandler to it to handle it properly. Like this: I have 2 events: public event EventHandler Click; public event EventHandler Click2; Now i would like to pass particular event to my method like this (pseudocode): public AttachToHandleEvent(EventHandler MyEvent) { MyEvent += Item_Click; } private void Item_Click(object sender, EventArgs e) { MessageBox.Show("lalala"); } ToolStripMenuItem tool = new ToolStripMenuItem(); AttachToHandleEvent(tool.Click); Is it possible or do I not understand it good? Edit: I've noticed with help of you that this code worked fine, and returned to my project and noticed that when I pass event declared in my class it works, but when I pass event from other class id still does not work. Updated above example to reflect this issue. What I get is this error: The event 'System.Windows.Forms.ToolStripItem.Click' can only appear on the left hand side of += or -=

    Read the article

  • Is there a better way to minimize this C# event repetition?

    - by Damien Wildfire
    I have a lot of code like this: public class Microwave { private EventHandler<EventArgs> _doorClosed; public event EventHandler<EventArgs> DoorClosed { add { lock (this) _doorClosed += value; } remove { lock (this) _doorClosed -= value; } } private EventHandler<EventArgs> _lightbulbOn; public event EventHandler<EventArgs> LightbulbOn { add { lock (this) _lightbulbOn += value; } remove { lock (this) _lightbulbOn -= value; } } // ... } You can see that much of this is boilerplate. In Ruby I'd be able to do something like this: class Microwave has_events :door_closed, :lightbulb_on, ... end Is there a similar shorter way of removing this boilerplate in C#?

    Read the article

  • Calling Web Service Functions Asynchronously from a Web Page

    - by SGWellens
    Over on the Asp.Net forums where I moderate, a user had a problem calling a Web Service from a web page asynchronously. I tried his code on my machine and was able to reproduce the problem. I was able to solve his problem, but only after taking the long scenic route through some of the more perplexing nuances of Web Services and Proxies. Here is the fascinating story of that journey. Start with a simple Web Service     public class Service1 : System.Web.Services.WebService    {        [WebMethod]        public string HelloWorld()        {            // sleep 10 seconds            System.Threading.Thread.Sleep(10 * 1000);            return "Hello World";        }    } The 10 second delay is added to make calling an asynchronous function more apparent. If you don't call the function asynchronously, it takes about 10 seconds for the page to be rendered back to the client. If the call is made from a Windows Forms application, the application freezes for about 10 seconds. Add the web service to a web site. Right-click the project and select "Add Web Reference…" Next, create a web page to call the Web Service. Note: An asp.net web page that calls an 'Async' method must have the Async property set to true in the page's header: <%@ Page Language="C#"          AutoEventWireup="true"          CodeFile="Default.aspx.cs"          Inherits="_Default"           Async='true'  %> Here is the code to create the Web Service proxy and connect the event handler. Shrewdly, we make the proxy object a member of the Page class so it remains instantiated between the various events. public partial class _Default : System.Web.UI.Page {    localhost.Service1 MyService;  // web service proxy     // ---- Page_Load ---------------------------------     protected void Page_Load(object sender, EventArgs e)    {        MyService = new localhost.Service1();        MyService.HelloWorldCompleted += EventHandler;          } Here is the code to invoke the web service and handle the event:     // ---- Async and EventHandler (delayed render) --------------------------     protected void ButtonHelloWorldAsync_Click(object sender, EventArgs e)    {        // blocks        ODS("Pre HelloWorldAsync...");        MyService.HelloWorldAsync();        ODS("Post HelloWorldAsync");    }    public void EventHandler(object sender, localhost.HelloWorldCompletedEventArgs e)    {        ODS("EventHandler");        ODS("    " + e.Result);    }     // ---- ODS ------------------------------------------------    //    // Helper function: Output Debug String     public static void ODS(string Msg)    {        String Out = String.Format("{0}  {1}", DateTime.Now.ToString("hh:mm:ss.ff"), Msg);        System.Diagnostics.Debug.WriteLine(Out);    } I added a utility function I use a lot: ODS (Output Debug String). Rather than include the library it is part of, I included it in the source file to keep this example simple. Fire up the project, open up a debug output window, press the button and we get this in the debug output window: 11:29:37.94 Pre HelloWorldAsync... 11:29:37.94 Post HelloWorldAsync 11:29:48.94 EventHandler 11:29:48.94 Hello World   Sweet. The asynchronous call was made and returned immediately. About 10 seconds later, the event handler fires and we get the result. Perfect….right? Not so fast cowboy. Watch the browser during the call: What the heck? The page is waiting for 10 seconds. Even though the asynchronous call returned immediately, Asp.Net is waiting for the event to fire before it renders the page. This is NOT what we wanted. I experimented with several techniques to work around this issue. Some may erroneously describe my behavior as 'hacking' but, since no ingesting of Twinkies was involved, I do not believe hacking is the appropriate term. If you examine the proxy that was automatically created, you will find a synchronous call to HelloWorld along with an additional set of methods to make asynchronous calls. I tried the other asynchronous method supplied in the proxy:     // ---- Begin and CallBack ----------------------------------     protected void ButtonBeginHelloWorld_Click(object sender, EventArgs e)    {        ODS("Pre BeginHelloWorld...");        MyService.BeginHelloWorld(AsyncCallback, null);        ODS("Post BeginHelloWorld");    }    public void AsyncCallback(IAsyncResult ar)    {        String Result = MyService.EndHelloWorld(ar);         ODS("AsyncCallback");        ODS("    " + Result);    } The BeginHelloWorld function in the proxy requires a callback function as a parameter. I tested it and the debug output window looked like this: 04:40:58.57 Pre BeginHelloWorld... 04:40:58.57 Post BeginHelloWorld 04:41:08.58 AsyncCallback 04:41:08.58 Hello World It works the same as before except for one critical difference: The page rendered immediately after the function call. I was worried the page object would be disposed after rendering the page but the system was smart enough to keep the page object in memory to handle the callback. Both techniques have a use: Delayed Render: Say you want to verify a credit card, look up shipping costs and confirm if an item is in stock. You could have three web service calls running in parallel and not render the page until all were finished. Nice. You can send information back to the client as part of the rendered page when all the services are finished. Immediate Render: Say you just want to start a service running and return to the client. You can do that too. However, the page gets sent to the client before the service has finished running so you will not be able to update parts of the page when the service finishes running. Summary: YourFunctionAsync() and an EventHandler will not render the page until the handler fires. BeginYourFunction() and a CallBack function will render the page as soon as possible. I found all this to be quite interesting and did a lot of searching and researching for documentation on this subject….but there isn't a lot out there. The biggest clues are the parameters that can be sent to the WSDL.exe program: http://msdn.microsoft.com/en-us/library/7h3ystb6(VS.100).aspx Two parameters are oldAsync and newAsync. OldAsync will create the Begin/End functions; newAsync will create the Async/Event functions. Caveat: I haven't tried this but it was stated in this article. I'll leave confirming this as an exercise for the student J. Included Code: I'm including the complete test project I created to verify the findings. The project was created with VS 2008 SP1. There is a solution file with 3 projects, the 3 projects are: Web Service Asp.Net Application Windows Forms Application To decide which program runs, you right-click a project and select "Set as Startup Project". I created and played with the Windows Forms application to see if it would reveal any secrets. I found that in the Windows Forms application, the generated proxy did NOT include the Begin/Callback functions. Those functions are only generated for Asp.Net pages. Probably for the reasons discussed earlier. Maybe those Microsoft boys and girls know what they are doing. I hope someone finds this useful. Steve Wellens

    Read the article

  • Is this a valid pattern for raising events in C#?

    - by Will Vousden
    Update: For the benefit of anyone reading this, since .NET 4, the lock is unnecessary due to changes in synchronization of auto-generated events, so I just use this now: public static void Raise<T>(this EventHandler<T> handler, object sender, T e) where T : EventArgs { if (handler != null) { handlerCopy(sender, e); } } And to raise it: SomeEvent.Raise(this, new FooEventArgs()); Having been reading one of Jon Skeet's articles on multithreading, I've tried to encapsulate the approach he advocates to raising an event in an extension method like so (with a similar generic version): public static void Raise(this EventHandler handler, object @lock, object sender, EventArgs e) { EventHandler handlerCopy; lock (@lock) { handlerCopy = handler; } if (handlerCopy != null) { handlerCopy(sender, e); } } This can then be called like so: protected virtual void OnSomeEvent(EventArgs e) { this.someEvent.Raise(this.eventLock, this, e); } Are there any problems with doing this? Also, I'm a little confused about the necessity of the lock in the first place. As I understand it, the delegate is copied in the example in the article to avoid the possibility of it changing (and becoming null) between the null check and the delegate call. However, I was under the impression that access/assignment of this kind is atomic, so why is the lock necessary? Update: With regards to Mark Simpson's comment below, I threw together a test: static class Program { private static Action foo; private static Action bar; private static Action test; static void Main(string[] args) { foo = () => Console.WriteLine("Foo"); bar = () => Console.WriteLine("Bar"); test += foo; test += bar; test.Test(); Console.ReadKey(true); } public static void Test(this Action action) { action(); test -= foo; Console.WriteLine(); action(); } } This outputs: Foo Bar Foo Bar This illustrates that the delegate parameter to the method (action) does not mirror the argument that was passed into it (test), which is kind of expected, I guess. My question is will this affect the validity of the lock in the context of my Raise extension method? Update: Here is the code I'm now using. It's not quite as elegant as I'd have liked, but it seems to work: public static void Raise<T>(this object sender, ref EventHandler<T> handler, object eventLock, T e) where T : EventArgs { EventHandler<T> copy; lock (eventLock) { copy = handler; } if (copy != null) { copy(sender, e); } }

    Read the article

  • Performance - FunctionCall vs Event vs Action vs Delegate

    - by hwcverwe
    Currently I am using Microsoft Sync Framework to synchronize databases. I need to gather information per record which is inserted/updated/deleted by Microsoft Sync Framework and do something with this information. The sync speed can go over 50.000 records per minute. So that means my additional code need to be very lightweight otherwise it will be a huge performance penalty. Microsoft Sync Framework raises an SyncProgress event for each record. I am subscribed to that code like this: // Assembly1 SyncProvider.SyncProgress += OnSyncProgress; // .... private void OnSyncProgress(object sender, DbSyncProgressEventArgs e) { switch (args.Stage) { case DbSyncStage.ApplyingInserts: // MethodCall/Delegate/Action<>/EventHandler<> => HandleInsertedRecordInformation // Do something with inserted record info break; case DbSyncStage.ApplyingUpdates: // MethodCall/Delegate/Action<>/EventHandler<> => HandleUpdatedRecordInformation // Do something with updated record info break; case DbSyncStage.ApplyingDeletes: // MethodCall/Delegate/Action<>/EventHandler<> => HandleDeletedRecordInformation // Do something with deleted record info break; } } Somewhere else in another assembly I have three methods: // Assembly2 public class SyncInformation { public void HandleInsertedRecordInformation(...) {...} public void HandleUpdatedRecordInformation(...) {...} public void HandleInsertedRecordInformation(...) {...} } Assembly2 has a reference to Assembly1. So Assembly1 does not know anything about the existence of the SyncInformation class which need to handle the gathered information. So I have the following options to trigger this code: use events and subscribe on it in Assembly2 1.1. EventHandler< 1.2. Action< 1.3. Delegates using dependency injection: public class Assembly2.SyncInformation : Assembly1.ISyncInformation Other? I know the performance depends on: OnSyncProgress switch using a method call, delegate, Action< or EventHandler< Implementation of SyncInformation class I currently don't care about the implementation of the SyncInformation class. I am mainly focused on the OnSyncProgress method and how to call the SyncInformation methods. So my questions are: What is the most efficient approach? What is the most in-efficient approach? Is there a better way than using a switch in OnSyncProgress?

    Read the article

  • Raising C# events with an extension method - is it bad?

    - by Kyralessa
    We're all familiar with the horror that is C# event declaration. To ensure thread-safety, the standard is to write something like this: public event EventHandler SomethingHappened; protected virtual void OnSomethingHappened(EventArgs e) { var handler = SomethingHappened; if (handler != null) handler(this, e); } Recently in some other question on this board (which I can't find now), someone pointed out that extension methods could be used nicely in this scenario. Here's one way to do it: static public class EventExtensions { static public void RaiseEvent(this EventHandler @event, object sender, EventArgs e) { var handler = @event; if (handler != null) handler(sender, e); } static public void RaiseEvent<T>(this EventHandler<T> @event, object sender, T e) where T : EventArgs { var handler = @event; if (handler != null) handler(sender, e); } } With these extension methods in place, all you need to declare and raise an event is something like this: public event EventHandler SomethingHappened; void SomeMethod() { this.SomethingHappened.RaiseEvent(this, EventArgs.Empty); } My question: Is this a good idea? Are we missing anything by not having the standard On method? (One thing I notice is that it doesn't work with events that have explicit add/remove code.)

    Read the article

  • How can I get an IObservable<T> in Rx from a "non-standard" event?

    - by Dan Tao
    Here's what I mean. Suppose I'm working with an API that exposes events, but these events do not follow the standard EventHandler or EventHandler<TEventArgs> signature. One event might look like this, for instance: Public Event Update(ByVal sender As BaseSubscription, ByVal e As BaseEvent) Now, typically, if I want to get an IObservable<TEventArgs> from an event, I can just do this: Dim updates = Observable.FromEvent(Of UpdateEventArgs)( _ target:=updateSource, _ eventName:="Update" _ ) But this doesn't work, because the Update event is not an EventHandler<UpdateEventArgs> -- in fact, there is no UpdateEventArgs -- it's basically just its own thing. Obviously, I could define my own class deriving from EventArgs (i.e., UpdateEventArgs), write another class to wrap the object providing the Update event, give the wrapper class its own Update event that is an EventHandler<UpdateEventArgs>, and get an IObservable<UpdateEventArgs> from that. But that's an annoying amount of work. Is there some way to create an IObservable<[something]> from a "non-standard" event like this, or am I out of luck?

    Read the article

  • "SpeechHypothesized event not raised"

    - by Jankhana
    Hi all, I need to detect the user voice when they pick-up the reciever on the other end. Because Modems usually start playing files (playback terminal) when the first ring goes there. So I planned to use speech recognition when they say "hello", it can start playing the file until wait for playing file. Or even any noise interference it can start speak. I accomplished this with few settings. I found few common words that my engine detects when we speak and the words that comes when it's ringing. It works fine as a stand alone application but if I try to integrate this with my application it just does not raises "SpeechHypothesized" event. I cant understand why this happens. If i see using a break point, the engine is having the delegate assign and invocation property also is initialized properly but than to is doesn't call the event. For calling I'm using C4F tapi manager and for speech recognition i'm using System.Speech library of .Net 3.5. The code for events is as follows : engine.SpeechDetected += new EventHandler<SpeechDetectedEventArgs>(engine_SpeechDetected); engine.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(engine_SpeechRecognized); engine.SpeechHypothesized+=new EventHandler<SpeechHypothesizedEventArgs> (engine_SpeechHypothesized); engine.SpeechRecognitionRejected += new EventHandler<SpeechRecognitionRejectedEventArgs>(engine_SpeechRecognitionRejected); All event's are raised except the speechhypothesized event. Any idea why this happens ????

    Read the article

  • In a Windows forms application, how can I setup can I set up the SelectedIndexChanged handle for 4 d

    - by Alex
    In a Windows forms application, within a DataGridView, I have 4 different DataGridCombobox controlshow can I set up the handler SelectedIndexChanged handler for the first combobox via the EditingControlShowing event. I added code for a second combobox but the SelectedIndexChanged didn't get wired up. Here's my code. Any advice would be appreciated. private ComboBox countryCombo; private EventHandler countryHandler; private ComboBox partCombo; private EventHandler partHandler; private void dataGridView2_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) { countryCombo = e.Control as ComboBox; if (countryCombo != null) { //remove any existing handler if there is one countryCombo.SelectedIndexChanged -= countryHandler; //add the new handler countryCombo.SelectedIndexChanged += new EventHandler(countryCombo_SelectedIndexChanged); } if (partCombo != null) { partCombo.SelectedIndexChanged -= partHandler; partCombo.SelectedIndexChanged += new EventHandler(partCombo_SelectedIndexChanged); } } private void countryCombo_SelectedIndexChanged(object sender, EventArgs e) { ComboBox box = (ComboBox) sender; //MessageBox.Show(box.Items.Count.ToString()); int rowNum = dataGridView2.CurrentCell.RowIndex; dataGridView2.BeginEdit(false); dataGridView2.Rows[0].Cells[2].Value = "abcdef"; dataGridView2.EndEdit(); } private void dataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e) { int cellColumn = e.ColumnIndex; //MessageBox.Show("Column is: " + cellColumn.ToString()); } private void partCombo_SelectedIndexChanged(object sender, EventArgs e) { ComboBox box = (ComboBox)sender; string partNumber = box.SelectedValue as string; // ToDo: now we need to get the HTSUS from the database so we can //populate the field int rowNum = dataGridView2.CurrentCell.RowIndex; dataGridView2.BeginEdit(false); dataGridView2.Rows[0].Cells[2].Value = "abcdef"; dataGridView2.EndEdit(); } } Al D.

    Read the article

  • mvc design in a card game

    - by Hong
    I'm trying to make a card game. some classes I have are: CardModel, CardView; DeckModel, DeckView. The deck model has a list of card model, According to MVC, if I want to send a card to a deck, I can add the card model to the deck model, and the card view will be added to the deck view by a event handler. So I have a addCard(CardModel m) in the DeckModel class, but if I want to send a event to add the card view of that model to the deck view, I only know let the model has a reference to view. So the question is: If the card model and deck model have to have a reference to their view classes to do it? If not, how to do it better? Update, the code: public class DeckModel { private ArrayList<CardModel> cards; private ArrayList<EventHandler> actionEventHandlerList; public void addCard(CardModel card){ cards.add(card); //processEvent(event x); //must I pass a event that contain card view here? } CardModel getCards(int index){ return cards.get(index); } public synchronized void addEventHandler(EventHandler l){ if(actionEventHandlerList == null) actionEventHandlerList = new ArrayList<EventHandler>(); if(!actionEventHandlerList.contains(l)) actionEventHandlerList.add(l); } public synchronized void removeEventHandler(EventHandler l){ if(actionEventHandlerList!= null && actionEventHandlerList.contains(l)) actionEventHandlerList.remove(l); } private void processEvent(Event e){ ArrayList list; synchronized(this){ if(actionEventHandlerList!= null) list = (ArrayList)actionEventHandlerList.clone(); else return; } for(int i=0; i<actionEventHandlerList.size(); ++i){ actionEventHandlerList.get(i).handle(e); } } }

    Read the article

  • How would I define "GetDataFromNumber" so that my class contains a definition?

    - by JB
    My code gets an error saying: 'Eagle_Eye_Class_Finder.GetSchedule' does not contain a definition for 'GetDataFromNumber' and no extension method 'GetDataFromNumber'. using System; using System.IO; using System.Data; using System.Text; using System.Drawing; using System.Data.OleDb; using System.Collections; using System.Windows.Forms; using System.ComponentModel; using System.Drawing.Printing; using System.Collections.Generic; namespace Eagle_Eye_Class_Finder { /// This form is the entry form, it is the first form the user will see when the app is run. /// public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.ProgressBar progressBar1; private System.Windows.Forms.PictureBox pictureBox1; private System.Windows.Forms.Button button2; private System.Windows.Forms.DateTimePicker dateTimePicker1; private IContainer components; private Timer timer1; private BindingSource form1BindingSource; public static Form Mainform = null; // creates new instance of second form YOURCLASSSCHEDULE SecondForm = new YOURCLASSSCHEDULE(); public Form1() { InitializeComponent(); // TODO: Add any constructor code after InitializeComponent call } /// Clean up any resources being used. protected override void Dispose(bool disposing) { if (disposing) { if (components != null) { components.Dispose(); } } base.Dispose(disposing); } #region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.components = new System.ComponentModel.Container(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1)); this.textBox1 = new System.Windows.Forms.TextBox(); this.progressBar1 = new System.Windows.Forms.ProgressBar(); this.pictureBox1 = new System.Windows.Forms.PictureBox(); this.button2 = new System.Windows.Forms.Button(); this.dateTimePicker1 = new System.Windows.Forms.DateTimePicker(); this.timer1 = new System.Windows.Forms.Timer(this.components); this.form1BindingSource = new System.Windows.Forms.BindingSource(this.components); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.form1BindingSource)).BeginInit(); this.SuspendLayout(); // // textBox1 // this.textBox1.BackColor = System.Drawing.SystemColors.ActiveCaption; this.textBox1.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.form1BindingSource, "Text", true, System.Windows.Forms.DataSourceUpdateMode.OnValidation, null, "900456317")); this.textBox1.Location = new System.Drawing.Point(328, 280); this.textBox1.Name = "textBox1"; this.textBox1.Size = new System.Drawing.Size(208, 20); this.textBox1.TabIndex = 2; this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged); // // progressBar1 // this.progressBar1.Location = new System.Drawing.Point(258, 410); this.progressBar1.MarqueeAnimationSpeed = 10; this.progressBar1.Name = "progressBar1"; this.progressBar1.Size = new System.Drawing.Size(344, 8); this.progressBar1.TabIndex = 3; this.progressBar1.Click += new System.EventHandler(this.progressBar1_Click); // // pictureBox1 // this.pictureBox1.BackColor = System.Drawing.SystemColors.ControlLightLight; this.pictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image"))); this.pictureBox1.Location = new System.Drawing.Point(680, 400); this.pictureBox1.Name = "pictureBox1"; this.pictureBox1.Size = new System.Drawing.Size(120, 112); this.pictureBox1.TabIndex = 4; this.pictureBox1.TabStop = false; this.pictureBox1.Click += new System.EventHandler(this.pictureBox1_Click); // // button2 // this.button2.Font = new System.Drawing.Font("Mistral", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.button2.Image = ((System.Drawing.Image)(resources.GetObject("button2.Image"))); this.button2.Location = new System.Drawing.Point(699, 442); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(78, 28); this.button2.TabIndex = 5; this.button2.Text = "OK"; this.button2.Click += new System.EventHandler(this.button2_Click); // // dateTimePicker1 // this.dateTimePicker1.Location = new System.Drawing.Point(336, 104); this.dateTimePicker1.Name = "dateTimePicker1"; this.dateTimePicker1.Size = new System.Drawing.Size(200, 20); this.dateTimePicker1.TabIndex = 6; this.dateTimePicker1.ValueChanged += new System.EventHandler(this.dateTimePicker1_ValueChanged); // // timer1 // this.timer1.Tick += new System.EventHandler(this.timer1_Tick); // // form1BindingSource // this.form1BindingSource.DataSource = typeof(Eagle_Eye_Class_Finder.Form1); // // Form1 // this.AcceptButton = this.button2; this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage"))); this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.ClientSize = new System.Drawing.Size(856, 556); this.Controls.Add(this.dateTimePicker1); this.Controls.Add(this.button2); this.Controls.Add(this.pictureBox1); this.Controls.Add(this.progressBar1); this.Controls.Add(this.textBox1); this.Name = "Form1"; this.Text = "Eagle Eye Class Finder"; this.Load += new System.EventHandler(this.Form1_Load); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.form1BindingSource)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); } #endregion /// The main entry point for the application. [STAThread] static void Main() { Application.Run(new Form1()); } public void Form1_Load(object sender, System.EventArgs e) { } public void textBox1_TextChanged(object sender, System.EventArgs e) { //allows only numbers to be entered in textbox string Str = textBox1.Text.Trim(); double Num; bool isNum = double.TryParse(Str, out Num); if (isNum) Console.ReadLine(); else MessageBox.Show("Enter A Valid ID Number!"); } public void button2_Click(object sender, System.EventArgs e) { string text = textBox1.Text; Mainform = this; this.Hide(); GetSchedule myScheduleFinder = new GetSchedule(); string result = myScheduleFinder.GetDataFromNumber(text);<<<-----MY PROBLEM if (!string.IsNullOrEmpty(result)) { MessageBox.Show(result); } else { MessageBox.Show("Enter A Valid ID Number!"); } } public void dateTimePicker1_ValueChanged(object sender, System.EventArgs e) { } public void pictureBox1_Click(object sender, System.EventArgs e) { } public void progressBar1_Click(object sender, EventArgs e) { //this.progressBar1 = new System.progressBar1(); //progressBar1.Maximum = 200; //progressBar1.Minimum = 0; //progressBar1.Step = 20; } private void timer1_Tick(object sender, EventArgs e) { //if (progressBar1.Value >= 200 ) //{ //progressBar1.Value = 0; //} //return; //} //progressBar1.Value != 20; } } }

    Read the article

  • Project compile perfectly but i get unhandled exception and have no idea why??? any clues?

    - by JB
    get unhandled exception that says: System.NullReferenceException: Object reference not set to an instance of an object. at Eagle_Eye_Class_Finder.GetSchedule.GetDataFromNumber(String ID) in C:\Users\Joshua Banks\Desktop\EET Project\Eagle Eye Class Finder\GetSchedule.cs:line 24 at Eagle_Eye_Class_Finder.Form1.button2_Click(Object sender, EventArgs e) in C:\Users\Joshua Banks\Desktop\EET Project\Eagle Eye Class Finder\Form1.cs:line 196 at System.Windows.Forms.Control.OnClick(EventArgs e) at System.Windows.Forms.Button.OnClick(EventArgs e) at System.Windows.Forms.Button.PerformClick() at System.Windows.Forms.Form.ProcessDialogKey(Keys keyData) at System.Windows.Forms.Control.ProcessDialogKey(Keys keyData) at System.Windows.Forms.TextBoxBase.ProcessDialogKey(Keys keyData) at System.Windows.Forms.Control.PreProcessMessage(Message& msg) at System.Windows.Forms.Control.PreProcessControlMessageInternal(Control target, Message& msg) at System.Windows.Forms.Application.ThreadContext.PreTranslateMessage(MSG& msg) Here is my Get Schedule Class: using System; using System.IO; using System.Data; using System.Text; using System.Drawing; using System.Data.OleDb; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Drawing.Printing; using System.Collections.Generic; namespace Eagle_Eye_Class_Finder { public class GetSchedule { public string GetDataFromNumber(string ID) { IDnumber[] IDnumbers = new IDnumber[3]; foreach (IDnumber IDCandidateMatch in IDnumbers) { if (IDCandidateMatch.ID == ID) { StringBuilder myData = new StringBuilder(); myData.AppendLine(IDCandidateMatch.Name); myData.AppendLine(": "); myData.AppendLine(IDCandidateMatch.ID); myData.AppendLine(IDCandidateMatch.year); myData.AppendLine(IDCandidateMatch.class1); myData.AppendLine(IDCandidateMatch.class2); myData.AppendLine(IDCandidateMatch.class3); myData.AppendLine(IDCandidateMatch.class4); //return myData; return myData.ToString(); } } return ""; } public GetSchedule() { IDnumber[] IDnumbers = new IDnumber[3]; IDnumbers[0] = new IDnumber() { Name = "Joshua Banks", ID = "900456317", year = "Senior", class1 = "TEET 4090", class2 = "TEET 3020", class3 = "TEET 3090", class4 = "TEET 4290" }; IDnumbers[1] = new IDnumber() { Name = "Sean Ward", ID = "900456318", year = "Junior", class1 = "ENGNR 4090", class2 = "ENGNR 3020", class3 = "ENGNR 3090", class4 = "ENGNR 4290" }; IDnumbers[2] = new IDnumber() { Name = "Terrell Johnson", ID = "900456319", year = "Sophomore", class1 = "BUS 4090", class2 = "BUS 3020", class3 = "BUS 3090", class4 = "BUS 4290" }; } public class IDnumber { public string Name { get; set; } public string ID { get; set; } public string year { get; set; } public string class1 { get; set; } public string class2 { get; set; } public string class3 { get; set; } public string class4 { get; set; } public static void ProcessNumber(IDnumber myNum) { StringBuilder myData = new StringBuilder(); myData.AppendLine(myNum.Name); myData.AppendLine(": "); myData.AppendLine(myNum.ID); myData.AppendLine(myNum.year); myData.AppendLine(myNum.class1); myData.AppendLine(myNum.class2); myData.AppendLine(myNum.class3); myData.AppendLine(myNum.class4); MessageBox.Show(myData.ToString()); } } } } Here is my Form 1 class: using System; using System.IO; using System.Data; using System.Text; using System.Drawing; using System.Data.OleDb; using System.Collections; using System.Windows.Forms; using System.ComponentModel; using System.Drawing.Printing; using System.Collections.Generic; namespace Eagle_Eye_Class_Finder { /// This form is the entry form, it is the first form the user will see when the app is run. /// public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.ProgressBar progressBar1; private System.Windows.Forms.PictureBox pictureBox1; private System.Windows.Forms.Button button2; private System.Windows.Forms.DateTimePicker dateTimePicker1; private IContainer components; private Timer timer1; private BindingSource form1BindingSource; public static Form Mainform = null; // creates new instance of second form YOURCLASSSCHEDULE SecondForm = new YOURCLASSSCHEDULE(); public Form1() { InitializeComponent(); // TODO: Add any constructor code after InitializeComponent call } /// Clean up any resources being used. protected override void Dispose(bool disposing) { if (disposing) { if (components != null) { components.Dispose(); } } base.Dispose(disposing); } #region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.components = new System.ComponentModel.Container(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1)); this.textBox1 = new System.Windows.Forms.TextBox(); this.progressBar1 = new System.Windows.Forms.ProgressBar(); this.pictureBox1 = new System.Windows.Forms.PictureBox(); this.button2 = new System.Windows.Forms.Button(); this.dateTimePicker1 = new System.Windows.Forms.DateTimePicker(); this.timer1 = new System.Windows.Forms.Timer(this.components); this.form1BindingSource = new System.Windows.Forms.BindingSource(this.components); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.form1BindingSource)).BeginInit(); this.SuspendLayout(); // // textBox1 // this.textBox1.BackColor = System.Drawing.SystemColors.ActiveCaption; this.textBox1.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.form1BindingSource, "Text", true, System.Windows.Forms.DataSourceUpdateMode.OnValidation, null, "900456317")); this.textBox1.Location = new System.Drawing.Point(328, 280); this.textBox1.Name = "textBox1"; this.textBox1.Size = new System.Drawing.Size(208, 20); this.textBox1.TabIndex = 2; this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged); // // progressBar1 // this.progressBar1.Location = new System.Drawing.Point(258, 410); this.progressBar1.MarqueeAnimationSpeed = 10; this.progressBar1.Name = "progressBar1"; this.progressBar1.Size = new System.Drawing.Size(344, 8); this.progressBar1.TabIndex = 3; this.progressBar1.Click += new System.EventHandler(this.progressBar1_Click); // // pictureBox1 // this.pictureBox1.BackColor = System.Drawing.SystemColors.ControlLightLight; this.pictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image"))); this.pictureBox1.Location = new System.Drawing.Point(680, 400); this.pictureBox1.Name = "pictureBox1"; this.pictureBox1.Size = new System.Drawing.Size(120, 112); this.pictureBox1.TabIndex = 4; this.pictureBox1.TabStop = false; this.pictureBox1.Click += new System.EventHandler(this.pictureBox1_Click); // // button2 // this.button2.Font = new System.Drawing.Font("Mistral", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.button2.Image = ((System.Drawing.Image)(resources.GetObject("button2.Image"))); this.button2.Location = new System.Drawing.Point(699, 442); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(78, 28); this.button2.TabIndex = 5; this.button2.Text = "OK"; this.button2.Click += new System.EventHandler(this.button2_Click); // // dateTimePicker1 // this.dateTimePicker1.Location = new System.Drawing.Point(336, 104); this.dateTimePicker1.Name = "dateTimePicker1"; this.dateTimePicker1.Size = new System.Drawing.Size(200, 20); this.dateTimePicker1.TabIndex = 6; this.dateTimePicker1.ValueChanged += new System.EventHandler(this.dateTimePicker1_ValueChanged); // // timer1 // this.timer1.Tick += new System.EventHandler(this.timer1_Tick); // // form1BindingSource // this.form1BindingSource.DataSource = typeof(Eagle_Eye_Class_Finder.Form1); // // Form1 // this.AcceptButton = this.button2; this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage"))); this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.ClientSize = new System.Drawing.Size(856, 556); this.Controls.Add(this.dateTimePicker1); this.Controls.Add(this.button2); this.Controls.Add(this.pictureBox1); this.Controls.Add(this.progressBar1); this.Controls.Add(this.textBox1); this.Name = "Form1"; this.Text = "Eagle Eye Class Finder"; this.Load += new System.EventHandler(this.Form1_Load); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.form1BindingSource)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); } #endregion /// The main entry point for the application. [STAThread] static void Main() { Application.Run(new Form1()); } public void Form1_Load(object sender, System.EventArgs e) { } public void textBox1_TextChanged(object sender, System.EventArgs e) { //allows only numbers to be entered in textbox string Str = textBox1.Text.Trim(); double Num; bool isNum = double.TryParse(Str, out Num); if (isNum) Console.ReadLine(); else MessageBox.Show("Enter A Valid ID Number!"); } public void button2_Click(object sender, System.EventArgs e) { string text = textBox1.Text; Mainform = this; this.Hide(); GetSchedule myScheduleFinder = new GetSchedule(); string result = myScheduleFinder.GetDataFromNumber(text); if (!string.IsNullOrEmpty(result)) { MessageBox.Show(result); } else { MessageBox.Show("Enter A Valid ID Number!"); } } public void dateTimePicker1_ValueChanged(object sender, System.EventArgs e) { } public void pictureBox1_Click(object sender, System.EventArgs e) { } public void progressBar1_Click(object sender, EventArgs e) { //this.progressBar1 = new System.progressBar1(); //progressBar1.Maximum = 200; //progressBar1.Minimum = 0; //progressBar1.Step = 20; } private void timer1_Tick(object sender, EventArgs e) { //if (progressBar1.Value >= 200 ) //{ //progressBar1.Value = 0; //} //return; //} //progressBar1.Value != 20; } } } here is my form 2 class: using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; namespace Eagle_Eye_Class_Finder { /// /// Summary description for Form2. /// public class YOURCLASSSCHEDULE : System.Windows.Forms.Form { public System.Windows.Forms.LinkLabel linkLabel1; public System.Windows.Forms.LinkLabel linkLabel2; public System.Windows.Forms.LinkLabel linkLabel3; public System.Windows.Forms.LinkLabel linkLabel4; private Button button1; /// Required designer variable. public System.ComponentModel.Container components = null; public YOURCLASSSCHEDULE() { // InitializeComponent(); // TODO: Add any constructor code after InitializeComponent call } /// Clean up any resources being used. protected override void Dispose(bool disposing) { if (disposing) { if (components != null) { components.Dispose(); } } base.Dispose(disposing); } #region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(YOURCLASSSCHEDULE)); this.linkLabel1 = new System.Windows.Forms.LinkLabel(); this.linkLabel2 = new System.Windows.Forms.LinkLabel(); this.linkLabel3 = new System.Windows.Forms.LinkLabel(); this.linkLabel4 = new System.Windows.Forms.LinkLabel(); this.button1 = new System.Windows.Forms.Button(); this.SuspendLayout(); // // linkLabel1 // this.linkLabel1.BackColor = System.Drawing.SystemColors.ActiveCaption; this.linkLabel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; this.linkLabel1.Font = new System.Drawing.Font("Times New Roman", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.linkLabel1.LinkArea = new System.Windows.Forms.LinkArea(0, 7); this.linkLabel1.LinkBehavior = System.Windows.Forms.LinkBehavior.HoverUnderline; this.linkLabel1.Location = new System.Drawing.Point(41, 123); this.linkLabel1.Name = "linkLabel1"; this.linkLabel1.Size = new System.Drawing.Size(288, 32); this.linkLabel1.TabIndex = 1; this.linkLabel1.TabStop = true; this.linkLabel1.Text = "Class 1"; this.linkLabel1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.linkLabel1.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel1_LinkClicked); // // linkLabel2 // this.linkLabel2.BackColor = System.Drawing.SystemColors.ActiveCaption; this.linkLabel2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; this.linkLabel2.Font = new System.Drawing.Font("Times New Roman", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.linkLabel2.LinkBehavior = System.Windows.Forms.LinkBehavior.HoverUnderline; this.linkLabel2.Location = new System.Drawing.Point(467, 123); this.linkLabel2.Name = "linkLabel2"; this.linkLabel2.Size = new System.Drawing.Size(288, 32); this.linkLabel2.TabIndex = 2; this.linkLabel2.TabStop = true; this.linkLabel2.Text = "Class 2"; this.linkLabel2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.linkLabel2.VisitedLinkColor = System.Drawing.Color.Navy; this.linkLabel2.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel2_LinkClicked); // // linkLabel3 // this.linkLabel3.BackColor = System.Drawing.SystemColors.ActiveCaption; this.linkLabel3.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; this.linkLabel3.Font = new System.Drawing.Font("Times New Roman", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.linkLabel3.LinkBehavior = System.Windows.Forms.LinkBehavior.HoverUnderline; this.linkLabel3.Location = new System.Drawing.Point(41, 311); this.linkLabel3.Name = "linkLabel3"; this.linkLabel3.Size = new System.Drawing.Size(288, 32); this.linkLabel3.TabIndex = 3; this.linkLabel3.TabStop = true; this.linkLabel3.Text = "Class 3"; this.linkLabel3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.linkLabel3.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel3_LinkClicked); // // linkLabel4 // this.linkLabel4.BackColor = System.Drawing.SystemColors.ActiveCaption; this.linkLabel4.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; this.linkLabel4.Font = new System.Drawing.Font("Times New Roman", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.linkLabel4.LinkBehavior = System.Windows.Forms.LinkBehavior.HoverUnderline; this.linkLabel4.Location = new System.Drawing.Point(467, 311); this.linkLabel4.Name = "linkLabel4"; this.linkLabel4.Size = new System.Drawing.Size(288, 32); this.linkLabel4.TabIndex = 4; this.linkLabel4.TabStop = true; this.linkLabel4.Text = "Class 4"; this.linkLabel4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.linkLabel4.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel4_LinkClicked); // // button1 // this.button1.BackColor = System.Drawing.SystemColors.ActiveCaptionText; this.button1.FlatAppearance.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(64))))); this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Popup; this.button1.Font = new System.Drawing.Font("Pristina", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.button1.ForeColor = System.Drawing.SystemColors.ActiveCaption; this.button1.ImageAlign = System.Drawing.ContentAlignment.TopCenter; this.button1.Location = new System.Drawing.Point(358, 206); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(101, 25); this.button1.TabIndex = 5; this.button1.Text = "Go Back"; this.button1.UseVisualStyleBackColor = false; this.button1.Click += new System.EventHandler(this.button1_Click); // // YOURCLASSSCHEDULE // this.AutoScaleBaseSize = new System.Drawing.Size(6, 15); this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage"))); this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.ClientSize = new System.Drawing.Size(790, 482); this.Controls.Add(this.button1); this.Controls.Add(this.linkLabel4); this.Controls.Add(this.linkLabel3); this.Controls.Add(this.linkLabel2); this.Controls.Add(this.linkLabel1); this.Font = new System.Drawing.Font("OldDreadfulNo7 BT", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.Name = "YOURCLASSSCHEDULE"; this.Text = "Your Classes"; this.Load += new System.EventHandler(this.Form2_Load); this.ResumeLayout(false); } #endregion public void Form2_Load(object sender, System.EventArgs e) { // if (text == "900456317") // { //} } public void linkLabel1_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e) { System.Diagnostics.Process.Start("http://www.georgiasouthern.edu/map/"); } private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { System.Diagnostics.Process.Start("http://www.georgiasouthern.edu/map/"); } private void linkLabel3_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { System.Diagnostics.Process.Start("http://www.georgiasouthern.edu/map/"); } private void linkLabel4_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { System.Diagnostics.Process.Start("http://www.georgiasouthern.edu/map/"); } private void button1_Click(object sender, EventArgs e) { Form1 form1 = new Form1(); form1.Show(); this.Hide(); } } }

    Read the article

  • Have a program/winform that outputs name and classes in message box, my objective is to write the cl

    - by JB
    Here is my Get Schedule Class: using System; using System.IO; using System.Data; using System.Text; using System.Drawing; using System.Data.OleDb; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Drawing.Printing; using System.Collections.Generic; namespace Eagle_Eye_Class_Finder { public class GetSchedule { public string GetDataFromNumber(string ID) { IDnumber[] IDnumbers = new IDnumber[3]; foreach (IDnumber IDCandidateMatch in IDnumbers) { if (IDCandidateMatch.ID == ID) { StringBuilder myData = new StringBuilder(); myData.AppendLine(IDCandidateMatch.Name); myData.AppendLine(": "); myData.AppendLine(IDCandidateMatch.ID); myData.AppendLine(IDCandidateMatch.year); myData.AppendLine(IDCandidateMatch.class1); myData.AppendLine(IDCandidateMatch.class2); myData.AppendLine(IDCandidateMatch.class3); myData.AppendLine(IDCandidateMatch.class4); //return myData; return myData.ToString(); } } return ""; } public GetSchedule() { IDnumber[] IDnumbers = new IDnumber[3]; IDnumbers[0] = new IDnumber() { Name = "Joshua Banks", ID = "900456317", year = "Senior", class1 = "TEET 4090", class2 = "TEET 3020", class3 = "TEET 3090", class4 = "TEET 4290" }; IDnumbers[1] = new IDnumber() { Name = "Sean Ward", ID = "900456318", year = "Junior", class1 = "ENGNR 4090", class2 = "ENGNR 3020", class3 = "ENGNR 3090", class4 = "ENGNR 4290" }; IDnumbers[2] = new IDnumber() { Name = "Terrell Johnson", ID = "900456319", year = "Sophomore", class1 = "BUS 4090", class2 = "BUS 3020", class3 = "BUS 3090", class4 = "BUS 4290" }; } public class IDnumber { public string Name { get; set; } public string ID { get; set; } public string year { get; set; } public string class1 { get; set; } public string class2 { get; set; } public string class3 { get; set; } public string class4 { get; set; } public static void ProcessNumber(IDnumber myNum) { StringBuilder myData = new StringBuilder(); myData.AppendLine(myNum.Name); myData.AppendLine(": "); myData.AppendLine(myNum.ID); myData.AppendLine(myNum.year); myData.AppendLine(myNum.class1); myData.AppendLine(myNum.class2); myData.AppendLine(myNum.class3); myData.AppendLine(myNum.class4); MessageBox.Show(myData.ToString()); } } } } Here is my Form 1 class: using System; using System.IO; using System.Data; using System.Text; using System.Drawing; using System.Data.OleDb; using System.Collections; using System.Windows.Forms; using System.ComponentModel; using System.Drawing.Printing; using System.Collections.Generic; namespace Eagle_Eye_Class_Finder { /// This form is the entry form, it is the first form the user will see when the app is run. /// public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.ProgressBar progressBar1; private System.Windows.Forms.PictureBox pictureBox1; private System.Windows.Forms.Button button2; private System.Windows.Forms.DateTimePicker dateTimePicker1; private IContainer components; private Timer timer1; private BindingSource form1BindingSource; public static Form Mainform = null; // creates new instance of second form YOURCLASSSCHEDULE SecondForm = new YOURCLASSSCHEDULE(); public Form1() { InitializeComponent(); // TODO: Add any constructor code after InitializeComponent call } /// Clean up any resources being used. protected override void Dispose(bool disposing) { if (disposing) { if (components != null) { components.Dispose(); } } base.Dispose(disposing); } #region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.components = new System.ComponentModel.Container(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1)); this.textBox1 = new System.Windows.Forms.TextBox(); this.progressBar1 = new System.Windows.Forms.ProgressBar(); this.pictureBox1 = new System.Windows.Forms.PictureBox(); this.button2 = new System.Windows.Forms.Button(); this.dateTimePicker1 = new System.Windows.Forms.DateTimePicker(); this.timer1 = new System.Windows.Forms.Timer(this.components); this.form1BindingSource = new System.Windows.Forms.BindingSource(this.components); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.form1BindingSource)).BeginInit(); this.SuspendLayout(); // // textBox1 // this.textBox1.BackColor = System.Drawing.SystemColors.ActiveCaption; this.textBox1.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.form1BindingSource, "Text", true, System.Windows.Forms.DataSourceUpdateMode.OnValidation, null, "900456317")); this.textBox1.Location = new System.Drawing.Point(328, 280); this.textBox1.Name = "textBox1"; this.textBox1.Size = new System.Drawing.Size(208, 20); this.textBox1.TabIndex = 2; this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged); // // progressBar1 // this.progressBar1.Location = new System.Drawing.Point(258, 410); this.progressBar1.MarqueeAnimationSpeed = 10; this.progressBar1.Name = "progressBar1"; this.progressBar1.Size = new System.Drawing.Size(344, 8); this.progressBar1.TabIndex = 3; this.progressBar1.Click += new System.EventHandler(this.progressBar1_Click); // // pictureBox1 // this.pictureBox1.BackColor = System.Drawing.SystemColors.ControlLightLight; this.pictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image"))); this.pictureBox1.Location = new System.Drawing.Point(680, 400); this.pictureBox1.Name = "pictureBox1"; this.pictureBox1.Size = new System.Drawing.Size(120, 112); this.pictureBox1.TabIndex = 4; this.pictureBox1.TabStop = false; this.pictureBox1.Click += new System.EventHandler(this.pictureBox1_Click); // // button2 // this.button2.Font = new System.Drawing.Font("Mistral", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.button2.Image = ((System.Drawing.Image)(resources.GetObject("button2.Image"))); this.button2.Location = new System.Drawing.Point(699, 442); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(78, 28); this.button2.TabIndex = 5; this.button2.Text = "OK"; this.button2.Click += new System.EventHandler(this.button2_Click); // // dateTimePicker1 // this.dateTimePicker1.Location = new System.Drawing.Point(336, 104); this.dateTimePicker1.Name = "dateTimePicker1"; this.dateTimePicker1.Size = new System.Drawing.Size(200, 20); this.dateTimePicker1.TabIndex = 6; this.dateTimePicker1.ValueChanged += new System.EventHandler(this.dateTimePicker1_ValueChanged); // // timer1 // this.timer1.Tick += new System.EventHandler(this.timer1_Tick); // // form1BindingSource // this.form1BindingSource.DataSource = typeof(Eagle_Eye_Class_Finder.Form1); // // Form1 // this.AcceptButton = this.button2; this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage"))); this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.ClientSize = new System.Drawing.Size(856, 556); this.Controls.Add(this.dateTimePicker1); this.Controls.Add(this.button2); this.Controls.Add(this.pictureBox1); this.Controls.Add(this.progressBar1); this.Controls.Add(this.textBox1); this.Name = "Form1"; this.Text = "Eagle Eye Class Finder"; this.Load += new System.EventHandler(this.Form1_Load); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.form1BindingSource)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); } #endregion /// The main entry point for the application. [STAThread] static void Main() { Application.Run(new Form1()); } public void Form1_Load(object sender, System.EventArgs e) { } public void textBox1_TextChanged(object sender, System.EventArgs e) { //allows only numbers to be entered in textbox string Str = textBox1.Text.Trim(); double Num; bool isNum = double.TryParse(Str, out Num); if (isNum) Console.ReadLine(); else MessageBox.Show("Enter A Valid ID Number!"); } public void button2_Click(object sender, System.EventArgs e) { string text = textBox1.Text; Mainform = this; this.Hide(); GetSchedule myScheduleFinder = new GetSchedule(); string result = myScheduleFinder.GetDataFromNumber(text); if (!string.IsNullOrEmpty(result)) { MessageBox.Show(result); } else { MessageBox.Show("Enter A Valid ID Number!"); } } public void dateTimePicker1_ValueChanged(object sender, System.EventArgs e) { } public void pictureBox1_Click(object sender, System.EventArgs e) { } public void progressBar1_Click(object sender, EventArgs e) { //this.progressBar1 = new System.progressBar1(); //progressBar1.Maximum = 200; //progressBar1.Minimum = 0; //progressBar1.Step = 20; } private void timer1_Tick(object sender, EventArgs e) { //if (progressBar1.Value >= 200 ) //{ //progressBar1.Value = 0; //} //return; //} //progressBar1.Value != 20; } } } here is my form 2 class: using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; namespace Eagle_Eye_Class_Finder { /// <summary> /// Summary description for Form2. /// </summary> public class YOURCLASSSCHEDULE : System.Windows.Forms.Form { public System.Windows.Forms.LinkLabel linkLabel1; public System.Windows.Forms.LinkLabel linkLabel2; public System.Windows.Forms.LinkLabel linkLabel3; public System.Windows.Forms.LinkLabel linkLabel4; private Button button1; /// Required designer variable. public System.ComponentModel.Container components = null; public YOURCLASSSCHEDULE() { // InitializeComponent(); // TODO: Add any constructor code after InitializeComponent call } /// Clean up any resources being used. protected override void Dispose(bool disposing) { if (disposing) { if (components != null) { components.Dispose(); } } base.Dispose(disposing); } #region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(YOURCLASSSCHEDULE)); this.linkLabel1 = new System.Windows.Forms.LinkLabel(); this.linkLabel2 = new System.Windows.Forms.LinkLabel(); this.linkLabel3 = new System.Windows.Forms.LinkLabel(); this.linkLabel4 = new System.Windows.Forms.LinkLabel(); this.button1 = new System.Windows.Forms.Button(); this.SuspendLayout(); // // linkLabel1 // this.linkLabel1.BackColor = System.Drawing.SystemColors.ActiveCaption; this.linkLabel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; this.linkLabel1.Font = new System.Drawing.Font("Times New Roman", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.linkLabel1.LinkArea = new System.Windows.Forms.LinkArea(0, 7); this.linkLabel1.LinkBehavior = System.Windows.Forms.LinkBehavior.HoverUnderline; this.linkLabel1.Location = new System.Drawing.Point(41, 123); this.linkLabel1.Name = "linkLabel1"; this.linkLabel1.Size = new System.Drawing.Size(288, 32); this.linkLabel1.TabIndex = 1; this.linkLabel1.TabStop = true; this.linkLabel1.Text = "Class 1"; this.linkLabel1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.linkLabel1.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel1_LinkClicked); // // linkLabel2 // this.linkLabel2.BackColor = System.Drawing.SystemColors.ActiveCaption; this.linkLabel2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; this.linkLabel2.Font = new System.Drawing.Font("Times New Roman", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.linkLabel2.LinkBehavior = System.Windows.Forms.LinkBehavior.HoverUnderline; this.linkLabel2.Location = new System.Drawing.Point(467, 123); this.linkLabel2.Name = "linkLabel2"; this.linkLabel2.Size = new System.Drawing.Size(288, 32); this.linkLabel2.TabIndex = 2; this.linkLabel2.TabStop = true; this.linkLabel2.Text = "Class 2"; this.linkLabel2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.linkLabel2.VisitedLinkColor = System.Drawing.Color.Navy; this.linkLabel2.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel2_LinkClicked); // // linkLabel3 // this.linkLabel3.BackColor = System.Drawing.SystemColors.ActiveCaption; this.linkLabel3.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; this.linkLabel3.Font = new System.Drawing.Font("Times New Roman", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.linkLabel3.LinkBehavior = System.Windows.Forms.LinkBehavior.HoverUnderline; this.linkLabel3.Location = new System.Drawing.Point(41, 311); this.linkLabel3.Name = "linkLabel3"; this.linkLabel3.Size = new System.Drawing.Size(288, 32); this.linkLabel3.TabIndex = 3; this.linkLabel3.TabStop = true; this.linkLabel3.Text = "Class 3"; this.linkLabel3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.linkLabel3.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel3_LinkClicked); // // linkLabel4 // this.linkLabel4.BackColor = System.Drawing.SystemColors.ActiveCaption; this.linkLabel4.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; this.linkLabel4.Font = new System.Drawing.Font("Times New Roman", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.linkLabel4.LinkBehavior = System.Windows.Forms.LinkBehavior.HoverUnderline; this.linkLabel4.Location = new System.Drawing.Point(467, 311); this.linkLabel4.Name = "linkLabel4"; this.linkLabel4.Size = new System.Drawing.Size(288, 32); this.linkLabel4.TabIndex = 4; this.linkLabel4.TabStop = true; this.linkLabel4.Text = "Class 4"; this.linkLabel4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.linkLabel4.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel4_LinkClicked); // // button1 // this.button1.BackColor = System.Drawing.SystemColors.ActiveCaptionText; this.button1.FlatAppearance.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(64))))); this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Popup; this.button1.Font = new System.Drawing.Font("Pristina", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.button1.ForeColor = System.Drawing.SystemColors.ActiveCaption; this.button1.ImageAlign = System.Drawing.ContentAlignment.TopCenter; this.button1.Location = new System.Drawing.Point(358, 206); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(101, 25); this.button1.TabIndex = 5; this.button1.Text = "Go Back"; this.button1.UseVisualStyleBackColor = false; this.button1.Click += new System.EventHandler(this.button1_Click); // // YOURCLASSSCHEDULE // this.AutoScaleBaseSize = new System.Drawing.Size(6, 15); this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage"))); this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.ClientSize = new System.Drawing.Size(790, 482); this.Controls.Add(this.button1); this.Controls.Add(this.linkLabel4); this.Controls.Add(this.linkLabel3); this.Controls.Add(this.linkLabel2); this.Controls.Add(this.linkLabel1); this.Font = new System.Drawing.Font("OldDreadfulNo7 BT", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.Name = "YOURCLASSSCHEDULE"; this.Text = "Your Classes"; this.Load += new System.EventHandler(this.Form2_Load); this.ResumeLayout(false); } #endregion public void Form2_Load(object sender, System.EventArgs e) { // if (text == "900456317") // { //} } public void linkLabel1_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e) { System.Diagnostics.Process.Start("http://www.georgiasouthern.edu/map/"); } private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { System.Diagnostics.Process.Start("http://www.georgiasouthern.edu/map/"); } private void linkLabel3_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { System.Diagnostics.Process.Start("http://www.georgiasouthern.edu/map/"); } private void linkLabel4_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { System.Diagnostics.Process.Start("http://www.georgiasouthern.edu/map/"); } private void button1_Click(object sender, EventArgs e) { Form1 form1 = new Form1(); form1.Show(); this.Hide(); } } }

    Read the article

  • Explicit C# interface implementation of interfaces that inherit from other interfaces

    - by anthony
    Consider the following three interfaces: interface IBaseInterface { event EventHandler SomeEvent; } interface IInterface1 : IBaseInterface { ... } interface IInterface 2 : IBaseInterface { ... } Now consider the following class that implements both IInterface1 and IInterface 2: class Foo : IInterface1, IInterface2 { event EventHandler IInterface1.SomeEvent { add { ... } remove { ... } } event EventHandler IInterface2.SomeEvent { add { ... } remove { ... } } } This results in an error because SomeEvent is not part of IInterface1 or IInterface2, it is part of IBaseInterface. How can the class Foo implement both IInterface1 and IInterface2?

    Read the article

  • WCF: How to detect new connections to WCF PerSession services ?

    - by Christian Toma
    I have a self-hosted WCF service with the InstanceContextMode set to PerSession. How can I detect new client connections (sessions) to my service from the host application and use that new session context to observe my service trough its events? Something like: [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)] public class MyService : IMyService { public event EventHandler ClientRegistered; public event EventHandler FileUploaded; } and from my host application to be able to do: ServiceHost svc = new ServiceHost(typeof(MyService)); svc.Open(); // something like: svc.NewSession += new EventHandler(...) //... public void SessionHandler(InstanceContext SessionContext) { MySessionHandler NewSessionHandler = new MySessionHandler(SessionContext); // From MySessionHandler I handle the service's events (FileUploaded, ClientRegistered) // for this session and notify the UI of any changes. NewSessionHandler.Handle(); }

    Read the article

  • HttpModule Init method is called several times - why?

    - by MartinF
    I was creating a http module and while debugging I noticed something which at first (at least) seemed like weird behaviour. When i set a breakpoint in the init method of the httpmodule i can see that the http module init method is being called several times even though i have only started up the website for debugging and made one single request (sometimes it is hit only 1 time, other times as many as 10 times). I know that I should expect several instances of the HttpApplication to be running and for each the http modules will be created, but when i request a single page it should be handled by a single http application object and therefore only fire the events associated once, but still it fires the events several times for each request which makes no sense - other than it must have been added several times within that httpApplication - which means it is the same httpmodule init method which is being called every time and not a new http application being created each time it hits my break point (see my code example at the bottom etc.). What could be going wrong here ? is it because i am debugging and set a breakpoint in the http module? It have noticed that it seems that if i startup the website for debugging and quickly step over the breakpoint in the httpmodule it will only hit the init method once and the same goes for the eventhandler. If I instead let it hang at the breakpoint for a few seconds the init method is being called several times (seems like it depends on how long time i wait before stepping over the breakpoint). Maybe this could be some build in feature to make sure that the httpmodule is initialised and the http application can serve requests , but it also seems like something that could have catastrophic consequences. This could seem logical, as it might be trying to finish the request and since i have set the break point it thinks something have gone wrong and try to call the init method again ? soo it can handle the request ? But is this what is happening and is everything fine (i am just guessing), or is it a real problem ? What i am specially concerned about is that if something makes it hang on the "production/live" server for a few seconds a lot of event handlers are added through the init and therefore each request to the page suddenly fires the eventhandler several times. This behaviour could quickly bring any site down. I have looked at the "original" .net code used for the httpmodules for formsauthentication and the rolemanagermodule etc but my code isnt any different that those modules uses. My code looks like this. public void Init(HttpApplication app) { if (CommunityAuthenticationIntegration.IsEnabled) { FormsAuthenticationModule formsAuthModule = (FormsAuthenticationModule) app.Modules["FormsAuthentication"]; formsAuthModule.Authenticate += new FormsAuthenticationEventHandler(this.OnAuthenticate); } } here is an example how it is done in the RoleManagerModule from the .NET framework public void Init(HttpApplication app) { if (Roles.Enabled) { app.PostAuthenticateRequest += new EventHandler(this.OnEnter); app.EndRequest += new EventHandler(this.OnLeave); } } Do anyone know what is going on? (i just hope someone out there can tell me why this is happening and assure me that everything is perfectly fine) :) UPDATE: I have tried to narrow down the problem and so far i have found that the Init method being called is always on a new object of my http module (contary to what i thought before). I seems that for the first request (when starting up the site) all of the HttpApplication objects being created and its modules are all trying to serve the first request and therefore all hit the eventhandler that is being added. I cant really figure out why this is happening. If i request another page all the HttpApplication's created (and their moduless) will again try to serve the request causing it to hit the eventhandler multiple times. But it also seems that if i then jump back to the first page (or another one) only one HttpApplication will start to take care of the request and everything is as expected - as long as i dont let it hang at a break point. If i let it hang at a breakpoint it begins to create new HttpApplication's objects and starts adding HttpApplications (more than 1) to serve/handle the request (which is already in process of being served by the HttpApplication which is currently stopped at the breakpoint). I guess or hope that it might be some intelligent "behind the scenes" way of helping to distribute and handle load and / or errors. But I have no clue. I hope some out there can assure me that it is perfectly fine and how it is supposed to be?

    Read the article

  • How to pass an event to a method and then subscribe to it?

    - by Ryan Peschel
    Event Handler public void DeliverEvent(object sender, EventArgs e) { } #1: This Works public void StartListening(Button source) { source.Click += DeliverEvent; } #2: And so does this.. public void StartListening(EventHandler eventHandler) { eventHandler += DeliverEvent; } But in #2, you cannot call the method because if you try something like this: StartListening(button.Click); You get this error: The event 'System.Windows.Forms.Control.Click' can only appear on the left hand side of += or -= Is there any way around that error? I want to be able to pass the event and not the object housing the event to the StartListening method.

    Read the article

  • C# Event Handlers automatically created by WinForms Designer

    - by RHaguiuda
    Just moved from VB.NET to C#. In VB to connect and Event Handler to a Sub we use the Handles clause. From what it seems, this do not exist in C#. After creating a simple application with a button I realize that Window Forms Designer automatically created an EventHandler to my button1_Click function (after I double clicked it), in Form1.Designer.cs with this code: this.button1.Click += new System.EventHandler(this.button1_Click); But, in VB, the WinForms Designer create the Handles clause in my class, in the function header. So, C# create the default EventHandler in designer file, while VB creates in main class with control resides. Is this correct? Am I missing something here?

    Read the article

  • How to pass around event as parameter in c#

    - by Jerry Liu
    Am writing unit test for a multi-threading application, where I need to wait until a specific event triggered so that I know the asyn operation is done. E.g. When I call repository.add(something), I wait for event AfterChange before doing any assertion. So I write a util function to do that. public static void SyncAction(EventHandler event_, Action action_) { var signal = new object(); EventHandler callback = null; callback = new EventHandler((s, e) => { lock (signal) { Monitor.Pulse(signal); } event_ -= callback; }); event_ += callback; lock (signal) { action_(); Assert.IsTrue(Monitor.Wait(signal, 10000)); } } However, the compiler prevents from passing event out of the class. Is there a way to achieve that?

    Read the article

  • List<string> doesn't update the UI when change occurs [WPF]

    - by Hard Turner
    <ListBox x:Name="MainList" HorizontalAlignment="Left" Height="468" Margin="10,10,0,0" VerticalAlignment="Top" Width="100" ItemsSource="{Binding Items,Mode=TwoWay}" DisplayMemberPath="Name"/> [Serializable()] public class MYcontainer : INotifyPropertyChanged,ISerializable { private List<MYClass> _items = new List<MYClass>(); public List<MYClass> Items { get{ return _items;} set { this._items =value; OnPropertyChanged("Items"); } public event PropertyChangedEventHandler PropertyChanged; public void OnPropertyChanged(string propertyName = null) { var eventHandler = this.PropertyChanged; if (eventHandler != null) eventHandler(this, new PropertyChangedEventArgs(propertyName)); } } when i add an item to "Items" the UI doesnt update, the binding is working fine, since if i closed the window and opened it again, the new items appear correctly what am i doing wrong? i know if i used observablecollection it will work fine, but shouldn't it work with List<? , i already have in another window a string[] property and it update fine

    Read the article

  • Actionscript: Switching back into previous function from event handler function

    - by J.Ded.
    I need to return to my original function after capturing an event (downloading something) with another function. The original function needs to return a value, which depends on the downloaded data. So, I'd like to pause original function for the time needed for the download and the eventhandler function to complete it's work, and resume it afterwards. The obvious way is to set a flag value (both the original function and the eventhandler are within the same class) and make the original function check it until the eventhandler function changes the flag. But that would be wasteful, and my AS is slow enough already:) [other parts of the application utilise some heavy graphics]. Is there another way? Like an event that gets captured "in the middle" of the function? Or some other form of flow control?

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >