I will be showing how to pass data between two forms in VB .NET. I will be using two forms, two classes which we will define, a delegate, an event, and an event handler. It is my first tutorial and is a bit long because I wanted to make it easy to follow. If you want to skip the explanation and just see the code, scroll down to "The short version:" Here is what I will be using: * A form named: MainFrm * A form named: ChildFrm * A class named: ScheduleInfo * A class named: ValueUpdatedEventsArgs An instance …

Member Avatar
Member Avatar
+4 forum 8

I’m working on a little matrix class for my own use and because for me, it is just fun! Now I noticed a lot (10 and more) of the methods always seem to follow the same pattern: - Iterate over the rows - For each row iterate over the columns - Do something with each element of the matrix An example: // <returns>the zero matrix</returns> public static MMatrix Zero(int row, int col) { MMatrix MA = new MMatrix(r, c); for (int i = 0; i < row; i++) { for (int j = 0; j < col; j++) { MA[i, …

Member Avatar
Member Avatar
+0 forum 9

The idea for this snippet came from vegaseat, who wrote a very nifty RPN calculator in Python, simulating a switch/case statement, something that Python is missing. See this code on page 19 in the projects for beginners thread on the Python software development forum. In my opinion, he did a very good job. So I posed myself a goal: write something equal in C# and, although it was tempting to use: don’t use a case statement. Here is the result. The only thing that C# seems to lack here is the use of variable parameters. One could play with different …

Member Avatar
Member Avatar
+1 forum 4

I will be showing how to pass data between two forms in C#. I will be using two forms, two classes which we will define, a delegate, an event, and an event handler. It is a bit long because I wanted to make it easy to follow. If you want to skip the explanation and just see the code, scroll down to "The short version:" * A form named: MainFrm * A form named: ChildFrm * A class named: ScheduleInfo * A class named: ValueUpdatedEventsArgs An instance of ChildFrm will be created and shown when clicking a button on the …

Member Avatar
Member Avatar
+4 forum 1

The luxuries we now have in the amount of pixels on a screen to draw some amazing graphs with, were lacking in the early days of computing. Most of the time you had to resort to rude printed output. It wasn’t that bad always. Sometimes it was and still is sufficient; just to have a quick preview of what a function would look like. Here I present some code that does just that. It plots a function to the console. I included a screen dump(which passed through Paint) just to show what it looks like. You could also use the …

Member Avatar
Member Avatar
+1 forum 2

Hi all, I'm writing a simple application in C# but I'm having an annoying ArgumentOutOfRangeException thrown by Invoke() saying "Text length must be less than 64 characters long.". Is this usual that strings passed through delegates have to be shorter than 64 characters? What's the usual neat way around it? Do I have to box it in some container class? The code is here: public enum StatusIcons { NoChange, Idle, Download, Fail, Reply, ShuttingDown, Pause } ; public void updateStatus(string description, StatusIcons icon = StatusIcons.NoChange, string tooltip = null) { if (this.InvokeRequired) { System.Diagnostics.Debug.Print("invoke {0},{1}: \r\n{2}\r\n{3}", description.Length, tooltip!= null ? …

Member Avatar
Member Avatar
+0 forum 2

I want to write a program interrupts when the receive buffer for the serial port has received some data. I have done a little a bit of research and I believe C# word for interrupt is delegate. Apologies if I'm barking up the wrong tree but I want to know if there is method other than polling the read buffer of the serial port. I have used interrupts before but only in C on a PIC. Basically is it possible in C#? Cheers

Member Avatar
Member Avatar
+0 forum 3

Hello. I've seen some tutorials, but I can't find one that particularly suits my needs. What I'm trying to do is this: I have a form that contains an object. I want this object to be able to modify its parent form when an event for it is thrown. The problem is that this object does not have a reference to the form's fields. Where can I find a nice, beginner-friendly tutorial that provides a sample that's easy to reproduce in a large application? Thanks.

Member Avatar
Member Avatar
+0 forum 3

Hello, I'm creating a game editor and I'm at the current stage that I would like the ability to attach scripts to objects (by selecting the string of the method name to be called). That would be saved into the object's scripts to load / run array. That shouldn't be too difficult, the part I'm having trouble with is finding a method to dynamically call functions at runtime based on what script they need to run. Keep in mind this "script" is just C# code. I need to run the scripts efficiently at game runtime and I can't have complicated …

Member Avatar
Member Avatar
+0 forum 3

I'v just gone through delegates concept in C# and understood that delegates are references to methods. to add reference to the delegate object they are using new. Similarly in multicast delegate they are using new for addition of methods as well as deletion of methods. Uptill now i was in belief that new is used for memory allocation than why new is required for removing referencing also. Please throw lights about usage of new keyword for referencing and dereferencing methods.

Member Avatar
Member Avatar
+0 forum 1

Okay so about a year ago I took a usual college class on C# and since have been addicted to the language, I love writting in it. But I have been puzzled by an issue that I have never figured out, and I decided it's finally time to ask for some help. Okay so call me a noob, but I have no clue what the purpose is for 'static' when it comes to programming (yeah I know sad), and that has to deal with the issue I am having. I learned about delegates from my class (which I think are …

Member Avatar
Member Avatar
+0 forum 8

In Robot.h: #include "Motores.h" namespace SoftRobot { ... public ref class Robot : public System::Windows::Forms::Form { .... public: void ComunicarEnviar(System::String^ EnvDados); private: System::Void Robot_Load(System::Object^ sender, System::EventArgs^ e) { Motores ^newMDIChild = gcnew Motores(); newMDIChild->MdiParent = this; newMDIChild->Show(); } }; } In Global.cpp: #include "Robot.h" using namespace SoftRobot; void Robot::ComunicarEnviar(System::String^ EnvDados) { //send data } In Motore.h namespace SoftRobot { ... public ref class Motores : public System::Windows::Forms::Form { public: Motores(void) { InitializeComponent(); // //TODO: Add the constructor code here // } ... void EnvMDEPwmL(); private: System::Void Motores_Load(System::Object^ sender, System::EventArgs^ e) { Robot::ComunicarEnviar("dados"); } }; } In Motores.cpp #include "Motores.h" using …

Member Avatar
Member Avatar
+0 forum 1

Hi everyone. I'm having trouble emitting a call to a delegate whose type is unfinished at the time of the emit. I'll elaborate: I'm trying to dynamically (i.e., with a [inlinecode]TypeBuilder[/inlinecode]) create the following class: [code=C#] public MyClass { // Delegate type. The 'firstArgument' will be 'this', i.e., this is an open instance method: // the implicit argument is here given explicitly, in 'firstArgument'. // (below there's a link explaining open instance methods; I couldn't get it to work within // the code block) public delegate Object DirectReadAccessor<T>(T firstArgument); // Array of delegates. T has been replaced with MyClass because …

Member Avatar
Member Avatar
+0 forum 3

Way back years ago I tried to understand [B]delegates[/B]. See the snippet how I did it.

Member Avatar
Member Avatar
+0 forum 1

The End.