Cannot enter text from class to textbox in form - c#

Cannot enter text from class to textbox in form.
We set a keypress event in the MyTreeView class.
The text box cannot contain characters.
What should I do?
*set of textBox1.
*Change Modifiers for textBox1 properties from private to public
*Change keypress event from private to public
*(It didn't work well, so I keep it private now.)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;
namespace treeview
{
public partial class Form1 : System.Windows.Forms.Form
{
MyTreeView m_tree_view = new MyTreeView();
public Form1()
{
try
{
InitializeComponent();
System.Windows.Forms.TreeNode[] tree1 = new System.Windows.Forms.TreeNode[2];
m_tree_view.Location = new System.Drawing.Point(0, 0);
m_tree_view.Size = ClientSize;
m_tree_view.AllowDrop = true;
tree1[0] = new System.Windows.Forms.TreeNode("TreeNode1");
tree1[1] = new System.Windows.Forms.TreeNode("TreeNode2");
m_tree_view.Nodes.Add("Node1");
Controls.Add(m_tree_view);
}
catch
{
}
}
//This is the code I added.
private void Form1_Load(object sender, EventArgs e)
{
}
}
public class MyTreeView : System.Windows.Forms.TreeView
{
public MyTreeView()
{
try
{
//This is the code I added.
KeyPress += MyTreeView_KeyPress;
}
catch
{
}
}
//This is the code I added.
private void MyTreeView_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
Console.WriteLine("key_press_ok");
//error code↓
//textBox1.Text = "sample";
}
}
}

If you want just to click an button and then print some text i don't understand why you are making another class.
Will be good to make your code efficient and not complicated.
In the main class
private void SendText_Click(object sender, EventArgs e)
{
textBox1.Text = "hi";
}
But if you want to make it complicated and make a class you shuld return i variable and send it to the other class the you can use it.
Learn how to use Public and private first and then use them.
You shuld have a public class which send data and the private to recive and process.

add (Exception ex) to your try catch.
so do:
try
{
// your code
}
catch (Exception ex)
{
MessageBox.Show(ex, "Error in (add where the error is)");
Console.WriteLine(ex);
}
So you will get a detailed Exception Message, maybe it helps you or maybe you will post it here, so we can see what the problem is.
And because you have System.Windows.Forms in your Using Directive
using System.Windows.Forms;
so
System.Windows.Forms.TreeNode[] tree1 = new System.Windows.Forms.TreeNode[2];
is redundant and can be shortened to:
TreeNode[] tree1 = new TreeNode[2];

Related

Show always active form in winforms

I need to show form that will be always on a top level.
I use TopMost and TopLevel flags and call Activate method after Show.
But another window might steal Activate flag.
How I can fix it so that after creating a window, other windows cannot become active until this window is closed?
upd: it work only if execute app from output folder and don't work if run app with debug from IDE.
The following code will open a form (TestForm) when the program is started. TestForm contains a button, that when clicked, will create a new form (a new instance of TestForm in the code below, but it could be a different form, if desired)--which won't be visible until the current form is closed. When the current form is closed, the new form will become visible and the original form will be disposed.
Try the following to see if it gives you the desired result:
Create a new class (TestFormEventArgs)
In Visual Studio menu, click Project
Select Add New Item
Select Class (Name: TestFormEventArgs.cs)
Click Add
TestFormEventArgs.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Activate2ndFormWhen1stFormCloses
{
public delegate void TestFormNewFormRequestedEventHandler(object sender, TestFormEventArgs e);
public class TestFormEventArgs : System.EventArgs
{
public int CurrentFormNumber { get; private set; } = 1;
public TestForm Frm { get; private set; } = null;
public TestFormEventArgs(TestForm frm, int currentFormNumber)
{
this.Frm = frm;
this.CurrentFormNumber = currentFormNumber;
}
}
}
Create a new Form (TestForm)
In Visual Studio menu, click Project
Select Add New Item
Select Form (Windows Forms) (Name: TestForm.cs)
Click Add
Add button to TestForm (btnOpenNewForm)
In Visual Studio menu, click View
Select Toolbox
Click Button
Drag mouse over the top of TestForm, and click the mouse to add the button to TestForm
In Visual Studio menu, click View
Select Properties Window
Click the button on the form
In the Properties Window, set the following properties: (Name): btnOpenNewForm; Text: Open New Form
On TestForm, double-click btnOpenNewForm which will create btnOpenNewForm_Click event handler.
Double-click TestForm to go to the code. Modify the code for TestForm.cs:
TestForm.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Activate2ndFormWhen1stFormCloses
{
public partial class TestForm : Form
{
public event TestFormNewFormRequestedEventHandler NewFormRequested;
private int _currentFormNumber = 1;
TestForm _frmOther = null;
public TestForm()
{
InitializeComponent();
//set value
this.Text = "TestForm 1";
}
public TestForm(string frmText, int currentFormNumber)
{
InitializeComponent();
//set value
this.Text = frmText;
this._currentFormNumber = currentFormNumber;
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void SendUpdates(TestForm frm, int currentFormNumber)
{
//check if there are subscribers
if (NewFormRequested != null)
{
//create a new instance of TestFormEventArgs
TestFormEventArgs valueArgs = new TestFormEventArgs(frm, currentFormNumber);
//raise event
NewFormRequested(this, valueArgs);
}//if
}
private void btnOpenNewForm_Click(object sender, EventArgs e)
{
string frmText = String.Format("TestForm {0}", _currentFormNumber + 1);
//create new instance
_frmOther = new TestForm(frmText, _currentFormNumber + 1);
//set properties
_frmOther.StartPosition = FormStartPosition.CenterScreen;
_frmOther.Visible = false;
SendUpdates(_frmOther, _currentFormNumber);
}
}
}
Change Program.cs code to the following:
Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;
namespace Activate2ndFormWhen1stFormCloses
{
static class Program
{
static TestForm _currentFrm = null;
static Queue<TestForm> _frmQ = new Queue<TestForm>();
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
//place form in Queue
_frmQ.Enqueue(new TestForm());
while(_frmQ.Count > 0)
{
//dequeue
_currentFrm = _frmQ.Dequeue();
//subscribe to events
_currentFrm.FormClosed += CurrentFrm_FormClosed;
_currentFrm.NewFormRequested += CurrentFrm_NewFormRequested;
Application.Run(_currentFrm);
}
}
private static void CurrentFrm_NewFormRequested(object sender, TestFormEventArgs e)
{
Debug.WriteLine("CurrentFrm_NewFormRequested: " + e.Frm.Text);
//add form to Queue
_frmQ.Enqueue(e.Frm);
}
private static void CurrentFrm_FormClosed(object sender, FormClosedEventArgs e)
{
TestForm frm = (TestForm)sender;
Debug.WriteLine("CurrentFrm_FormClosed: " + frm.Text);
try
{
//unsubscribe from events
_currentFrm.FormClosed -= CurrentFrm_FormClosed;
_currentFrm.NewFormRequested -= CurrentFrm_NewFormRequested;
_currentFrm.Dispose();
_currentFrm = null;
}
catch(Exception ex)
{
Debug.WriteLine("Error: " + ex.Message);
}
}
}
}
Try ShowDialog() instead of Show() method.
ShowDialog() will make the other form that is open Disabled and the current form is the only one that is Enabled.

Passing txtBox values between forms

I have always had trouble with this issue, i think i need to learn how it works, i have FormMain (my main form) and a second form (FormAddUrls) when i open form2 (FormAddUrls) i want to pass the multitextbox value back to the main form (FormMain)
I know in VB it's as simple as saying: FormMain.txtBoxUrls.Text = finalOutput; but not as easy in C#.
(form1) - FormMain
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Windows.Forms;
using WraithProjectCreator;
using IronPdf;
using System.Text;
namespace GSAProjectCreator
{
public partial class FormMain : Form
{
private IniParser m_Parser = null;
public FormMain()
{
InitializeComponent();
}
private void btnShowUrlsForm_Click(object sender, EventArgs e)
{
FormAddUrls fau = new FormAddUrls();
fau.Show();
}
}
}
(form2) - FormAddUrls
using GSAProjectCreator;
using System;
using System.Text;
using System.Windows.Forms;
namespace WraithProjectCreator
{
public partial class FormAddUrls : Form
{
public FormAddUrls()
{
InitializeComponent();
}
private void btnAddUrls_Click(object sender, EventArgs e)
{
StringBuilder builder = new StringBuilder();
builder.Append("{");
foreach (string line in txtBoxURLsMass.Lines)
{
//Helpers.returnMessage(line);
builder.Append(line + "|");
}
builder.Append("}");
string finalOutput = "";
if (builder.ToString().Contains("|}")) {
finalOutput = builder.ToString().Replace("|}", "}");
}
//FormMain.txtBoxUrls.Text = finalOutput;
this.Close();
}
}
}
I have ommited a lot of form1's code to leave the basic structure, i'm trying to pass back finalOutput from form2 to form1 (the txtBoxUrls.Text) text box, any help would be appreciated.
It depends on how you want to use the main form - you could have a static property which you could set (which would update the text for all main form instances).
If you only have one main form, and have a reference to it when you create the FormAddUrls object then you should just change the constructor to accept a MainForm (or as generic a type as possible), store the reference as a field and update the property on it when the button is clicked:
public partial class FormAddUrls : Form
{
private readonly Form _parentForm;
public FormAddUrls(MainForm parent)
{
_parentForm = parent;
InitializeComponent();
}
private void btnAddUrls_Click(object sender, EventArgs e)
{
StringBuilder builder = new StringBuilder();
builder.Append("{");
foreach (string line in txtBoxURLsMass.Lines)
{
//Helpers.returnMessage(line);
builder.Append(line + "|");
}
builder.Append("}");
string finalOutput = "";
if (builder.ToString().Contains("|}")) {
finalOutput = builder.ToString().Replace("|}", "}");
}
if(_parentForm != null)
_parentForm.txtBoxUrls.Text = finalOutput;
this.Close();
}
}

Change button text from another class in another namespace

I have a problem changing text from another class in another namespace. I have the first Form1 class :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
static Form1 mainForm;
[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool AllocConsole();
public static String LinkToApi = "http://google.com/api/";
public static Comunicator comunicator;
public static int debug = 5;
public Form1()
{
InitializeComponent();
AllocConsole(); // allow console
if(Form1.debug >= 3) Console.WriteLine("Application started");
comunicator = new Comunicator();
mainForm = this;
}
private void TestButton_Click(object sender, EventArgs e)
{
TestButton.Text = "Loading";
comunicator.TestConnection();
}
}
}
and this Comunicator class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.Collections.Specialized;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.IO;
using System.Threading;
namespace WindowsFormsApplication1
{
public class Comunicator
{
private String action = "idle";
public static Thread Start(Action action)
{
Thread thread = new Thread(() => { action(); });
thread.Start();
return thread;
}
public Comunicator()
{
}
public void TestConnection()
{
if (Form1.debug >= 3) Console.WriteLine("Testing connection");
// thread test
Start(new Action(ApiTest));
}
public void ApiTest()
{
if (Form1.debug >= 3) Console.WriteLine("API test begin");
// Create a request for the URL.
WebRequest request = WebRequest.Create("http://www.bogotobogo.com/index.php");
// If required by the server, set the credentials.
request.Credentials = CredentialCache.DefaultCredentials;
// Get the response.
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
// Display the status.
Console.WriteLine(response.StatusDescription);
// Get the stream containing content returned by the server.
Stream dataStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader(dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd();
// Display the content.
Console.WriteLine(responseFromServer);
// Cleanup the streams and the response.
reader.Close();
dataStream.Close();
response.Close();
// Console.Read();
if (Form1.debug >= 3) Console.WriteLine("API test end");
// Form1.StaticTestButton.Text = "Loaded"; <---- CHANGE HERE
}
}
}
which is not even a form class (I want to keep everything nice and clean). I want to change the TestButton text into "LOADED" but i get an error when I try to do that as if Form1.TestButton does not exist in Comunicator class.
I have tried to instantiate the class, I made a couple of variables static ... nothing, still getting error.
What is the problem? How may I solve this?
The request must be asynchronous, that's why I am using threads.
You should separate concerns, and you shouldn't communicate with UI in class which is not related to UI.
You should rewrite your code.
But as quick fix you should do the following.
In class Comunicator, you can do such field.
private readonly Action<string> _notifySimpleMessageAction;
Then add to Communicator constructor parameter notifyFunction. Code in constructor:
_notifySimpleMessageAction = notifyFunction
After that you should create Communicator in following manner:
communicator = new Communicator((notification)=>
{
StaticTestButton.BeginInvoke((MethodInvoker)(() => StaticTestButton.AppendText(notification)));
});
Then at the end of your method you should do
_notifySimpleMessageAction("Loaded")
Controller class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ControllerDemonstrator
{
public class Controller
{
public event EventHandler CommunicatorDataLoaded;
public event EventHandler FormTestConnection;
private Form1 _form;
private Communicator _communicator;
public Form1 MainForm
{
get { return _form; }
}
public Controller()
{
_form = new Form1(this);
_form.TestConnection += _form_TestConnection;
_form.FormClosed += _form_FormClosed;
_communicator = new Communicator(this);
_communicator.DataLoaded += _communicator_DataLoaded;
}
public void Start()
{
_form.Show();
}
void _form_FormClosed(object sender, System.Windows.Forms.FormClosedEventArgs e)
{
// put any code to clean up the communicator resources (if needed) here
// --------------------------------------------------------------------
_communicator = null;
// Then exit
// ---------
Application.Exit();
}
private void _communicator_DataLoaded(object sender, EventArgs e)
{
if (null != CommunicatorDataLoaded)
{
CommunicatorDataLoaded(sender, e);
}
}
private void _form_TestConnection(object sender, EventArgs e)
{
if (null != FormTestConnection)
{
FormTestConnection(sender, e);
}
}
}
}
Basic form with one button (_testButton):
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ControllerDemonstrator
{
public partial class Form1 : Form
{
public event EventHandler TestConnection;
public Form1(Controller controller)
{
InitializeComponent();
controller.CommunicatorDataLoaded += controller_CommunicatorDataLoaded;
}
void controller_CommunicatorDataLoaded(object sender, EventArgs e)
{
_testButton.Text = "Loaded";
}
private void _testButton_Click(object sender, EventArgs e)
{
if (null != TestConnection)
{
TestConnection(this, new EventArgs());
}
}
}
}
Communicator class (everything has been stripped out, you will need to add in your logic):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ControllerDemonstrator
{
public class Communicator
{
public event EventHandler DataLoaded;
public Communicator(Controller controller)
{
controller.FormTestConnection += controller_FormTestConnection;
}
private void controller_FormTestConnection(object sender, EventArgs e)
{
// put your code that does the connection here
// -------------------------------------------
if (null != DataLoaded)
{
DataLoaded(this, new EventArgs());
}
}
}
}
And in your Program.cs (assuming that is how you are starting your application):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ControllerDemonstrator
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Controller c = new Controller();
Application.Run(c.MainForm);
}
}
}
With this kind of design, the communicator doesn't know about the form and vice verse. You can expand it out to have different kind's of communicators/forms/etc and have the controller keep track of everything. It is also much easier to test code like this as you can test each separate piece on it's own since they don't depend on each other. This is a quick and dirty implementation. Do some research on the Model View Controller design pattern (not Microsoft MVC for asp.Net, but the actual design pattern). It is more code up-front to code an application with the MVC design pattern but it makes it easier to test and more maintainable.

Return Value Between Classes

How do I get a button click on a form to send the return of a called method to another class? Here is the pseudo code of what I have and any help would be greatly appreciated...
[Class Library]
using System;
using System.Runtime.InteropServices;
using System.Text;
using System.Collections.Generic;
using System.Linq;
namespace Auto
{
GUID Info
public interface IAuto
{
string SendToOtherApp();
}
COM Info
public class Auto : IAuto
{
public string tbox1;
NAVForm frm1 = new NAVForm();
public Auto()
{
}
public string SendToOtherApp()
{
frm1.ShowDialog();
tbox1 = NAVForm.UseThis();
return tbox1;
}
}
}
[Form]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Auto
{
public partial class NAVForm : Form
{
public NAVForm()
{
InitializeComponent();
}
private void NAVForm_Load(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
UseThis(textBox1.Text);
}
public string UseThis(string txt)
{
if (txt.Trim().Length != 0)
{
return txt;
}
else
{
return "didn't work";
}
}
}
}
I want to get the return value from public string UseThis(string txt) into public string SendToOtherApp() which is visible to the other system that is calling this.
I am obviously new to C# so I am also very open to an overall critique of the project and best practices.
This is what I have done and it works great. In our ERP I run the codeunit, which calls the automation variable which is tied to the "OpenThis()" method. My form opens, I enter text in the textbox, click OK, it closes the from and the ERP pops a messagebox displaying the text from the message box. What do you C# experts think about this build? I am very interested in your thoughts on this solution so please let me know.
Class Library.....
using System;
using System.Runtime.InteropServices;
using System.Text;
using System.Collections.Generic;
using System.Linq;
namespace NavAutomation
{
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
[Guid("5D83B4FE-45E6-410E-A075-AD635F5F0354")]
[ComVisible(true)]
public interface INavAutomation
{
string HelloWorld();
object OpenThis();
}
[ComVisible(true)]
[Guid("B7806CE5-862A-4407-9A3E-14CE8A9FB83A")]
[ClassInterface(ClassInterfaceType.None)]
public class NavAutomation : INavAutomation
{
public NavAutomation()
{
}
public object OpenThis()
{
using (var form = new NAVForm())
{
var result = form.ShowDialog();
return form.RetVal1;
}
}
}
}
Form.....
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace NavAutomation
{
public partial class NAVForm : Form
{
public NAVForm()
{
InitializeComponent();
}
private void NAVForm_Load(object sender, EventArgs e)
{
}
public string RetVal1 { get; set; }
private void button2_Click(object sender, EventArgs e)
{
if (textBox1.Text.Trim().Length != 0)
{
this.RetVal1 = textBox1.Text;
}
else
{
this.RetVal1 = "didn't work";
}
this.Close();
}
}
}
I am not sure if i got your goals right but here is the code that when called from a from, shows another modal form with a textbox, you enter a value into that textbox and close this modal form to find that value in that textbox returned to the first form that called for the show of the modal form.
CLASS LIBRARY
using System;
using System.Runtime.InteropServices;
using System.Text;
using System.Collections.Generic;
using System.Linq;
namespace Auto
{
public interface IAuto
{
string SendToOtherApp();
}
public class Auto : IAuto
{
public string tbox1;
NAVForm frm1 = new NAVForm();
public Auto()
{
}
public string SendToOtherApp()
{
frm1.ShowDialog();
tbox1 = frm1.UseThis(frm1.textBox1.Text);
return tbox1;
}
}
}
A FROM THAT CALLS TO SHOW A MODAL FORM
namespace Auto
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Auto auto = new Auto();
string returnedString = auto.SendToOtherApp(); // the string filled at the modal form text boxed will be returned to this variable
}
}
THE FORM THAT WILL BE SHOWED AS MODAL FORM
namespace Auto
{
public partial class NAVForm : Form
{
public NAVForm()
{
InitializeComponent();
}
public string UseThis(string txt)
{
if (txt.Trim().Length != 0)
{
return txt;
}
else
{
return "didn't work";
}
}
private void button1_Click(object sender, EventArgs e)
{
UseThis(textBox1.Text);
}
}
}
Please note that the access modifier of textBox1 at NAVForm should be set to public in order for it to be visible to class Auto
Let me know if i misunderstood something to correct it.

Subroutines in C#

I'm a bit new to C#, and not quite sure how to call a subroutine. Here's what I'm trying to do:
private void button1_Click(object sender, EventArgs e)
{
// Call whatever subroutine you like
StartExstream();
}
public void StartExstream()
{
// Do Stuff Here
}
Unfortunately for me, this doesn't work. I'm getting a "Only assignment, call, increment, decrement, and new object expressions can be used as a statement" error.
How do I call my StartExstream sub from my Button1_Click event?
Thanks,
Jason
EDIT:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
// Call whatever subroutine you like
StartExstream();
}
public void StartExstream()
{
tcpExstream.Service1Client MyTCP = new tcpExstream.Service1Client();
string ExStreamPath;
string datPath;
string optPath;
// My Working Arguments
ExStreamPath = #"C:\Program Files\Exstream\Dialogue 6.1\Engine.exe";
datPath = #"-FILEMAP=DataFile,\\Dev-srv1\Exstream\LetterWriterApp\Input Files\Data Files\SAVEezkazivaftf40s452ndayb45.dat";
optPath = #"-CONTROLFILE=C:\Exstream\Development\LetterWriter\ControlFiles\Letter.opt";
// Hong's Arguments
//ExStreamPath = #"C:\Program Files\Exstream\Dialogue 6.1\Engine.exe";
//datPath = #"-FILEMAP=DataFile,C:\Exstream\development\AGDocGenerator\TempFiles\DataFiles\Data_456231_1598.xml";
//optPath = #"-CONTROLFILE=C:\Exstream\development\AGDocGenerator\ExstreamDialogue\ControlFiles\AGDocGenerator.opt";
// Kick It!
MyTCP.StartExStream(datPath, optPath, ExStreamPath);
// Extra line of code for breaking point
optPath = "nothing";
}
}
}
First
If the Routine is in the same class than there you can directly call the routine by just writing name of it
Example
private void AnotherMethod()
{
// Call whatever subroutine you like
MyRutine();
}
Second
If its not in the same class you need to create instance of the class which contains routine and than you can use that object to call you routine
Example
MyClass c = new MyClass();
c.MyRutine();
You have to have this all in a namespace and then in a class for this to work.
namespace some.namespace
{
public class myclass
{
private void button1_Click(object sender, EventArgs e)
{ // Call whatever subroutine you like
StartExstream();
}
public void StartExstream()
{ // Do Stuff Here
}
}
}
OK, based on the further post, Your code
tcpExstream.Service1Client MyTCP = new tcpExstream.Service1Client();
is trying to create an object of a type that isn't a type but a member of a type.
instead you would use something like
WhateverTypeTcpExstreamIs MyTCP = new WhateverTypeTcpExstreamIs();
MyTCP.Service1Client = tcpExstream.Service1Client();

Categories