JerryShaw 46 Posting Pro in Training

This is what i have tried. I get no errors but the database is not changing as per the stored procedure which does work when run within sql.

private void approveestBN_Click(object sender, EventArgs e)
    {


        int @estno;            
        int.TryParse(startestnoCB.Text,out estno);


        SqlCommand cmd = new SqlCommand();
        cmd.CommandText = "EstimateApproval";
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.Add("@estno", SqlDbType.Int);            
    } 

end quote.

Where is your SqlConnection assignment to the SqlCommand ?
Where is your value assignment to the cmdParameter ?
Where is your Execute command on cmd ?

JerryShaw 46 Posting Pro in Training

Hopefully this will make more sense to you.
You declare a delegate method with no parameters. You want to assign two instances of this delegate and each will be assigned to a seperate method.

Each method must have the same parameter list as the delegate (which you do have).

Your attempt at assigning an event (+=) is totally wrong. Don't confuse event handlers with delegates. Delegates basically define a method call syntax. You can assign any method that has the same list of parameters to an instance of the delegate.

In the code snipet, I create an instance of Hello to a variable named g1. The delegate takes a single parameter which is the name of the method that will be called.

Then you invoke (call) the instance to cause the assigned method to be executed.

public delegate void Hello();
        public delegate void Hello2(string value);

        static void Main(string[] args)
        {
            // Assign g1 to the Goodmorning() method
            Hello g1 = new Hello(Goodmorning);
            // Assign g2 to the Goodevening() method
            Hello g2 = new Hello(Goodevening);
            Hello2 g3 = new Hello2(Salutations);
            // Invoke both methods through the delegate
            g1();
            g2();
            g3("Good Afternoon");
            // Wait for the user to press a key to exit
            Console.WriteLine("<press any key to exit>");
            Console.ReadKey();
        }

        public static void Goodmorning()
        {
           Console.WriteLine("Good Morning");
        }

        public static void Goodevening()
        {
            Console.WriteLine("Good Evening");
        }
        public static void Salutations(string value)
        {
            Console.WriteLine(value);
        }
ddanbe commented: Good explanation! +4
JerryShaw 46 Posting Pro in Training

fi.FullName

JerryShaw 46 Posting Pro in Training

CheckListBox is subclassed from ListBox. The SelectionMode is valid in the ListBox control, but only None and Single in the CheckListBox. It is not a true error! But, the programmer should have overridden the property and used a subset, or just a bool to allow selection or not.

Multi select is not valid due to the way the internal check on click method works with the SelectionMode.

They obviously needed to keep it because they wanted to let the None to be allowed...
// Jerry

JerryShaw 46 Posting Pro in Training

Take a look at FileSystemWatcher (a component in the tool box).
It will detect when new files have been added to a directory.

Otherwise, you can use something like this is a timed loop:

DirectoryInfo dirinfo = new DirectoryInfo("C:\\temp");
   foreach (FileInfo fi in dirinfo.GetFiles("info_*"))
   {
         // do something with file
         fi.Delete();
   }
JerryShaw 46 Posting Pro in Training

You do not need to use the GetBytes. It is available if you need to do special things with that byte array, however you want the entire array as you originally placed it into the database.

SqlCommand cmd = new SqlCommand("Select ImageHash from SIMILAR WHERE ID=26", con); 
            con.Open(); 
            rdr = cmd.ExecuteReader(); 
            rdr.Read();
            byte[] temp = (byte[])rdr["ImageHash"];

// Jerry

JerryShaw 46 Posting Pro in Training

As danielernesto said, store it to a column type that supports byte arrays such as Image or VarBinary(max).

// Jerry

JerryShaw 46 Posting Pro in Training
DataGridView dgv = new DataGridView();
dgv.CellValueChanged += new DataGridViewCellEventHandler(dgv_CellValueChanged);
JerryShaw 46 Posting Pro in Training

Thank You JerryShaw.. You Saved me a lot of Time .

Welcome.... Don't forget to mark this as Solved :)

JerryShaw 46 Posting Pro in Training

If you really don't need an SQL Server, then you can use XML.
Let me explain, On many projects I use a locally saved DataSet for all kinds of purposes, storing configuration, multi-media, and even storing serialized classes.

The DataSet class has an WriteXml method that will save the entire DataSet as an XML file. It has a ReadXml method that allows you to repopulate your applications dataset when you need it.

To get started, Create a dataset on your form, or special class, or DLL. Add the desired Tables, and columns with Types. You can even setup relationships similar to foreign keys between the tables.

Setup your form just like you would for any database centric application using binding sources, etc. (although this is optional).

Your application starts off with no data in the dataset, so let your user add data to the tables using your form. Once your user wants to save the data, then use

_myDataSet.WriteXml(_myFileName,XmlWriteMode.WriteSchema);

Now when the user starts the application, check to see if your filename exists, and if it does, use

_myDataSet.ReadXml(_myFileName);

Okay, now you have a local database contained in a DataSet. Now to perform SQL type queries, you can use the Table.Select method.
Lets assume you have a table named "Payroll" contained in your dataset. Lets say you want to get all the records for department "Engineering". (If you want all that start with Enginerring, you can use the LIKE 'Engineering%' qualifier, very …

sid78669 commented: Superb! He should be a prof!! +1
JerryShaw 46 Posting Pro in Training

If you want the listbox on the Main form to be updated when something happens on the other class, you need to create an event in the other class, and subscribe to it from the main form.

If you want the event to provide you with some information then you will need to either use an existing delegate or create your own.

You will want to create a simple arguments class to contain the information you want passed back to the main form.

class FooArgs
{
       private string _text;
       public string Text
       {  
            get{return _text;}
            private set{_text = value;}
       }
       public FooArgs (string value)
      {
          Text = value;
      }
}

You can put anything else you want into that FooArgs class that you need.

Next you want to setup a delegate for it, and assign an event in the Foo class.

public delegate void FooChanged(object sender, FooArgs e)
   public event FooChanged onFooChanged;

Now in your Foo class, when you want to notify the main form of some change:

public void DoSomething(string something)
{
      if( onFooChanged != null )
          onFooChanged(this, new FooArgs("erata"));
}

In the main form class, you would assign this event handler.

Foo foo = new Foo();
   foo.FooChanged += FooChanged(someFooHandler);

Give it a try... I free handed this, so hopefully there are no errors.
// Jerry

JerryShaw 46 Posting Pro in Training

Not knowing the layout of your application, I will make the assumption that you have the ListView on the main form.
You have some other form or class that is called upon to do something and you want something to appear in the ListView of the main form.

The problem Is the Scoping of the ListView instance. You need to send that instance to the other class, or make it public (modifier on the poperty editor <frowned upon>) on the main form, and make sure the class can see this instance.

Lets say your main form is named form1, your ListView is named listview1, and your other class is named Foo.

// Pass ListView into the constructor of Foo
Foo _foo = new Foo( listview1 );
_foo.DoSomething();

// OR pass it to a method of Foo
Foo _foo = new Foo();
_foo.DoSomething( listview1 );


class Foo
{
     private ListView _listview;
     public Foo( ListView listview)
    {
         this._listview = listview;
    }

    public  void DoSomething()
    {
         _listview.Items.Add("Test from Foo");
    }
}

OR

class Foo
{

     public void DoSomething( ListView listview )
     {
          listview.Items.Add("Another Test from Foo");
      }
}
JerryShaw 46 Posting Pro in Training

As LizR said, binding is the best approach, however you can manually locate the Customer in the table and populate the address text box.

string custName = combobox.Text;
DataRow[] addressInfo = custData.Select(string.Format("Customer='{0}'",custName));
if(addressInfo.Length > 0)
{
    edStreet.Text = (string)addressInfo[0]["Street"];
    edCity.Text = (string)addressInfo[0]["City"];
    // and so on...
}

Hope this helps,
Jerry

JerryShaw 46 Posting Pro in Training
char[] space = new char[1] { ' ' };
Console.WriteLine("Enter in numbers");
int nAnswer;
string[] answer = Console.ReadLine().Split(space
           ,StringSplitOptions.RemoveEmptyEntries);
                
List<int> myArray = new List<int>();
foreach(string str in answer)
     if( Int32.TryParse(str,out nAnswer) )
                    myArray.Add(nAnswer);

// Your answer can be pulled from the list using:
int[] result = myArray.ToArray();
JerryShaw 46 Posting Pro in Training

Make sure your catalog is set to the correct database. Currently it is set to master which is the primary system database.

JerryShaw 46 Posting Pro in Training

IsBackGround
Quote from Visual Studio 2008 on-line help
A thread is either a background thread or a foreground thread. Background threads are identical to foreground threads, except that background threads do not prevent a process from terminating. Once all foreground threads belonging to a process have terminated, the common language runtime ends the process. Any remaining background threads are stopped and do not complete.


My Info - a background thread is more forgiving than a foreground thread. The main application can not stop while any foreground threads are active. All background threads are automatically aborted when the main thread (the application) terminates.

JerryShaw 46 Posting Pro in Training

When dealing with threads, consider the timing involved. The Start() is an invocation and not a direct call to the target thread function.
Therefore, (in your example), the Main has had no interupts to prevent it from completing before the thread function begins.
If you were to cause the main to sleep for a couple milliseconds after the Start, it would allow the thread function to startup before the Main completed (eg interupt).

The the static assignment allows the function to invoke quickly (timing).
Just because it is static does not mean it will always startup in the desired order, again timing.

Add a using System.Threading, and after the Start() call, use Thread.Sleep(2) and you should find the desired results even if the thread function is not static.
You may also wish to set the thread's IsBackground property to true before it is started. This will help the thread to perform better outside the main thread activity.

Hope this helps..
Jerry

JerryShaw 46 Posting Pro in Training

string MyString = string.format("INSERT INTO tblUsers(userID, Name, Position)
VALUES('{0}','{1}','{2}'", txId.Text, txtUser.Text, txtPosition.Text );

JerryShaw 46 Posting Pro in Training

You forgot to assign the SqlConnection to your adapter.

JerryShaw 46 Posting Pro in Training

Have you tried using a tab delimited file and give it the xls extenstion ?
Excel will open the file and treate it like an xls file.

// Jerry

JerryShaw 46 Posting Pro in Training

See attached from CodeProject

JerryShaw 46 Posting Pro in Training

There are a number of approaches, but the easiest way would be to just pass the Main.cs label1 object to the second form, and let the buttons set its text.

Add the label as a parameter to the contructor.

India india = new India(label1);
.....

In the India.cs file setup the constructor and a variable

private Label mainLabel = null;

public India( Label mainLabel )
{
   this. mainLabel = mainLabel;
...
}

private void onSomeButtonClick(object sender, EventArgs e)
{
     Button myBtn = (Button)sender;
     mainLabel.Text = myBtn.Text;
....
}

Just typed this off the top of my head, so you may have to play with it, but I think you get the idea.

// Jerry

JerryShaw 46 Posting Pro in Training

Here is what I did in the violationsForm1 class that is a bit different than yours.

namespace harcaype
{
    public partial class violationsForm1 : Form
    {
        mainForm parentForm = null;
        public violationsForm1(mainForm parentForm)
        {
            InitializeComponent();
            this.parentForm = parentForm;
        }

        public ListViewItem _listViewFrequent
        {
            get { return (ListViewItem)listViewFrequent.FocusedItem.Clone(); }
        }


        private void selectToolStripMenuItem_Click(object sender, EventArgs e)
        {
            parentForm._listViewFreq = _listViewFrequent;
            Close();
        }
    }
}

and here is the mainForm

namespace harcaype
{
    public partial class mainForm : Form
    {
        public mainForm()
        {
            InitializeComponent();
        }

        public ListViewItem _listViewFreq
        {
            set
            { listViewNewData.Items.Add(value); }
        }

        private void fileVioToolStripMenuItem_Click(object sender, EventArgs e)
        {
            violationsForm1 vform1 = new violationsForm1(this);
            vform1.ShowDialog();
            vform1.Dispose();
        }

    }
}

I don't see where you are populating the violations listview, so I just through in some dummy data.
It moves data back to the main without any issues...
The only thing I did was change your constructor and parentForm property to be specifc to the mainForm class. If you really intend on using the violations form for multiple form classes, then I suggest you create an interface class, and use that in the constructor and form classes to allow dot-net to address properties without concern for the actual form class it is using.

// Jerry

JerryShaw 46 Posting Pro in Training

okay, Give me a few minutes to run your code into VS and try to duplicate your problem.

JerryShaw 46 Posting Pro in Training
private void mnuSelect_Click(object sender, EventArgs e)
        {
            //MessageBox.Show(listViewFrequent.FocusedItem.Text);
            
            mainForm frm = new mainForm();
            frm._listViewFreq = _listViewFrequent;
            frm.Show();
            this.Close();         
        }

Why are you doing this ? mainForm frm = new mainForm();
Should'nt it be (mainForm)parentForm._listViewFreq = _listViewFrequent;

// Jerry

JerryShaw 46 Posting Pro in Training

Maybe you should send more code so I can see what you are trying to do. Everytime that you recreate that form, it calls initializecomponents which gives you a new blank listview.

JerryShaw 46 Posting Pro in Training

The ListviewItem is an object in a collection that belongs to a different listview.
To copy it to the other list, you have to clone it, or remove it (decouple) from its current collection and post it into its new parent.

public ListViewItem _listViewFrequent        
{            
    get { return (ListViewItem)listViewFrequent.FocusedItem.Clone(); }        
}

private void mnuSelect_Click(object sender, EventArgs e)
        {  
            mainForm frm = new mainForm();
            frm._listViewFreq = _listViewFrequent;
            frm.Show();
            this.Close();         
        }

??? Also, listview does not allow adding of STRINGS. Please help. ???
Explain ... maybe I can show you how to do what you want with strings.

// Jerry

JerryShaw 46 Posting Pro in Training

Get the data from the database with a new statement:
select byEmail from ContactDetails where byEmail = 'Y'

Then in c#:
foreach(DataRow row in YourDataSet.Tables["YourTable"].Rows)
sendYourEmailTo( row["byEmail"].ToString() );

Or if you already have the dataset loaded...
DataRow[] emailers = YourDataSet.Tables["YourTable"].Select("byEmail = 'Y'");
foreach(DataRow row in emailers)
sendYourEmailTo( row["byEmail"].ToString() );

Or if using an SqlDataReader...
SqlConnection conn = new SqlConnection( YourConnectionString );
SqlCommand cmd = new SqlCommand("select byEmail from ContactDetails where byEmail = 'Y'",conn);
conn.Open();
SqlDataReader row = cmd.ExecuteReader();
while (row.Read())
{
sendYourEmailTo( row["byEmail"].ToString() );
}
conn.Close();

// Jerry
PS: Just typed off the top of my head, so verify syntax before use.

JerryShaw 46 Posting Pro in Training

Well, you can see what happens when you turn the int into a hex.

int x = 123;
string hex = "0x" + x.ToString("X");
JerryShaw 46 Posting Pro in Training

Why not just use its handle?

string pname="notepad";

foreach (Process theprocess in Myprocess)
{
if (theprocess.ProcessName == pname)
{
postmessage( theprocess.Handle, WM_SYSCOMMAND, SC_MINIMIZE, 0);
break;
}
}
JerryShaw 46 Posting Pro in Training

Knowledgelover,

Let’s re-visit your original request.
You want to have a means of storing and retrieving secured setup information for your application.

To be persistent, it means either writing something to the registry or to a file (I will make the distinction even though the registry is also a file).

Don't get hung-up on file extensions. There is no standard for "info" files that I am aware of. IOW there is no commonly used association with any particular viewer for a file with this extension.

The easiest approach is to use the Properties | Settings item in the solution explorer.
Expand the Properties tree item in the solution explorer.
Select (double-click) the Settings.settings tree node.
A grid will appear.
I will assume that you want to strore two pieces of information. I will assume the first is named “UserName”, and the second will be “Password”.
In the first available row in the settings grid, enter the name of the variable “UserName”.
Enter a new row and set the name to “Password”.

The settings file will be saved as the name of your executable with the extension of “.config”. Example MyApplication.exe will have a file named MyApplication.exe.config
This config file is your info file. It will contain XML.

In your c# code you can read and write this information.

private void button1_Click(object sender, EventArgs e)
{
   string un = Properties.Settings.Default.UserName;
   string up = Properties.Settings.Default.Password;
   MessageBox.Show(string.Format("UserName={0}\r\nPassword={1}",un,up));
}
JerryShaw 46 Posting Pro in Training

Knowlgelover,

A file is a file. Please explain "an info file is not an ordinary file that is represented by an IO" ?
Any non-corrupted file (and even corrupted files with the right viewer) can be opened an viewed by a user/hacker.

// Jerry

JerryShaw 46 Posting Pro in Training

Since no one has told you the standard ways yet..

Look at Property Settings

The next options are using home grown XML files, INI files or the Registry.

// Jerry

JerryShaw 46 Posting Pro in Training

The use of the Dataset allows you to save itself as an XML file to disk.
This means that the next time you load your application, the dataset can repopulate itself by loading the XML file.

This technique allows you to store and retrieve any kind of configuration information you could ever need. You can load multiple tables in the dataset, and all of them are saved with one line of code to save the entire dataset as an XML file.

// Saving a dataset to Disk
string FileName = "MyFileName.xml";
// VrfDataSet is my Configuration Dataset
VrfDataSet.WriteXml(FileName, XmlWriteMode.WriteSchema);
// Loading a dataset
string FileName = "MyFileName.xml";
if( File.Exists(FileName) )
{
     VrfDataSet.Clear();
            try
            {
                VrfDataSet.ReadXml(Filename);

.
.
.

Now you can use full flown database functionality to manage, find, etc any of your configuration information...

This Dataset is not connected to a real database... it is just a managed XML container that you can store connection strings, Bitmaps, a user supplied Icon for your app.. Just about anything you want to store in a configuration media.

// Jerry

JerryShaw 46 Posting Pro in Training

There are many ways to do this task, and I will let the others on this board give you the standard way(s) of doing this.

One method I have been using lately is quite simple, and does not require you to learn XML syntax or file IO management, or any of that stuff.

I drop a Dataset component on the main application.
I setup at least one table with the kind of information I want to persist. Briefcase Model.

When the application starts up, it will look for a file, and if found, the dataset will load it. Now all of my configuration information is found in the dataset. If I need to make changes to the configuration, I just make the changes to the dataset contents. When the application closes, I save the dataset to my filename.
One additional advantage is that I do not have to create a bunch of variables to maintain configuration information... It is already in my dataset along with Names, Types, etc.

The advantage of this method is that I can store multiple configurations, multiple types of configuration information, Bitmaps, documents, anything you want to stick into a DataTable.
Another advantage is that I can filter the configuration information for the currently logged on user (let each user customize the application to meet their needs).

Why read and write XML when you can just let the Dataset component do it for you.
Dataset XML files …

JerryShaw 46 Posting Pro in Training

choudhuryshouvi,

The code you sent earlier produced a different error on my machine.

This modified code below does run on my system. I changed the first assignment to drop the trailing backslash, and instead of using the OpenSubKey, I use the CreateSubKey. An old trick I learned way back is that the CreateSubKey WIN API call does the same thing as the OpenSubKey, except that it will also automatically create the subkey if it does not already exist.


// Jerry

private void cmdRead_Click()
        {
           RegistryKey HKCU=Registry.CurrentUser;
           RegistryKey subKeys=HKCU.CreateSubKey("Software\\VB and VBA Program Settings\\Company\\Login Status");
           subKeys.SetValue("Status", "Logged In");
           subKeys.Close();
           HKCU.Close();
        }
JerryShaw 46 Posting Pro in Training

See if you can do it manually using RegEdit.
I think you will discover the problem as you navigate to the node where you are expecting to write the value.

JerryShaw 46 Posting Pro in Training

The account must exist on the remote computer, or in the active directory where that account has rights to the computer.

Optionally, you can use impersonation of an existing account on the remote pc.

Even though it is a service account, it still must comply with all Windows security requirements.

//Jerry

JerryShaw 46 Posting Pro in Training

The target computer "MUST" have dot net installed , and the correct version of dot net to run a c# Windows form application.

If you are saying that it doesn't run in a seperate folder on your development machine, then you either 1) have a partial path hard-coded, or 2) you are missing one or more files required by the application.

// Jerry

JerryShaw 46 Posting Pro in Training

If you really need to do it in a listbox then look at:
OwnerDrawListBoxWithIcons

Most folks use a ListView instead because it does everything a listbox can do (and more) and handles the image easier through its smallimagelist property. If you want to see some code on using the listview, let me know.

// Jerry

JerryShaw 46 Posting Pro in Training

I have no idea why anyone would ever want to do this, but here you go...

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            comboBox1.SelectedIndexChanged -= comboBox1_SelectedIndexChanged;
            int i = Convert.ToInt32(comboBox1.SelectedItem.ToString());
            int j = Convert.ToInt32(comboBox1.Items[comboBox1.Items.Count - 1]) -i;
            
            comboBox1.Items.Clear();
            for (int z = 1; z <= j ; z++)
                comboBox1.Items.Add(z.ToString());
            if(comboBox1.Items.Count > 0)
                comboBox1.Text = comboBox1.Items[comboBox1.Items.Count - 1].ToString();
            comboBox1.SelectedIndexChanged += comboBox1_SelectedIndexChanged;
        }

// Jerry

JerryShaw 46 Posting Pro in Training

Yes you can do this. I have a service that does this type of work for archiving files.
Remember that a mapped drive is in the context of the currently logged on user. A Windows service runs in its own context. So, your mapped drive may not be visible to the windows service account.
If the service account has the security rights to the remote machine, then you can perform IO with it using the fully qualified path.

I use a fully qualified path instead of a mapped drive. You may have to either have your service create the mapping on startup, or just use the full path.

JerryShaw 46 Posting Pro in Training

If you are talking about the dropdown height, there is a property for that setting.

JerryShaw 46 Posting Pro in Training

First off, your scoping is wrong.

You have declared this in your constructor:
col c1 = new col();

The milisecond that your constructor exits, c1 is out of scope and ready for the garbage collector.

Declare your components (not initialize them, just declare them) in the class but not inside the constructor or any other method:

public partial class Form1 : Form
    {
        private col c1 = null;

        public Form1()
        {
            InitializeComponent();
            this.Text = "Nim";
            c1 = new col();

// Jerry

majestic0110 commented: Nice work mate! +2
JerryShaw 46 Posting Pro in Training

Change:
("c:/data/theData.txt",
TO
("c:\\data\\theData.txt",

and try it again.

// Jery

JerryShaw 46 Posting Pro in Training

DOS commands occur in "that" process. So, the cmdshell does accept the and act upon the CD directive, however, once that command shell closes, the process of changing directories has nothing to do with the next command shell directive because it would be in a new shell.

Maybe what you are looking for can be found at this URL
http://www.codeproject.com/KB/miscctrl/commandprompt.aspx

JerryShaw 46 Posting Pro in Training

big_B,

Okay, there are several ways to do it, so this example is but one of them.
I have two forms , first form has a button, second form has a timer, and two labels.
The one second timer simply posts the time to label1.
The second label is used to illustrate passing a string value from the main thread(or any other thread) to update its text.

// Form1
public partial class Form1 : Form
    {
        private Form2 f2 = null;
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (f2 != null)
                f2.setLabelText("Hello World");
            else
            {
                Thread x = new Thread(LoadF2);
                x.IsBackground = true;
                x.Start();
            }
        }

        delegate void f2Unloaded(object sender, FormClosedEventArgs e);
        void f2_FormClosed(object sender, FormClosedEventArgs e)
        {
            if (button1.InvokeRequired)
            {
                f2Unloaded d = new f2Unloaded(f2_FormClosed);
                this.Invoke(d, new object[] { sender, e });
            }
            else
            {
                f2 = null;
            }
        }

        private void LoadF2()
        {
            f2 = new Form2();
            f2.FormClosed +=new FormClosedEventHandler(f2_FormClosed);
            f2.ShowDialog();
        }
    }

The button on form1 will either post text to form2 or start form2 in a new thread depending on if form2 is active.
If it is currently null (not active), then create a new thread, and call the LoadF2 method.
We have to know when the thread has released form2, so we assign an event handler to its FormClosed event.
It starts form2 as modal. This is important, because if you just show form2, then the thread will exit, automatically disposing …

JerryShaw 46 Posting Pro in Training

Here is an example. You can also tack on a p.WaitForExit(); if needed.

using System.Diagnostics;
.
.
.
            Process p = new Process();
            p.StartInfo.FileName = "IPCONFIG";
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.Arguments = "/all";
            p.StartInfo.RedirectStandardOutput = true;
            p.Start();
            textBox1.Text = p.StandardOutput.ReadToEnd();

// Jerry
if this solves your issue, please remember to mark it as solved.

JerryShaw 46 Posting Pro in Training

The question just has to be asked..... Why are you invoking the second form this way ?

If your intent is to have the first form freeze and wait until the second form closes, then why not just show the second form as model using ShowDialog() ? That is the normal behaviour in windows applications.

Launching a second form from a thread has no advantage. When a form is launched in a windows application is stacks the form instances on the main application list of forms. This is how the windows dispatcher finds the form.

You can show many forms at once using show, all of them capable of accepting user interaction.
You can cause all forms to freeze by using ShowDialog on a form. When it exits, focus it brought back to the form that launched it.

If the Form is in another thread (yes you can do this... although not a good idea) then communicating with it has to be done through delegates to event handlers that will invoke into the owning thread. Alot more trouble than it is worth, since Windows can handle anything you need to do in the main thread. You can feed the second form from a thread easily enough, and is the main way programmers do it.

// Jerry

JerryShaw 46 Posting Pro in Training

Ok, to make this work more efficiently, I added another constructor to your Fraction class:
Just allows me to pass it a string. You can move the parsing up into FractionMatrix if you have to.

public Fraction(string value)
        {
            string[] nd = value.Split('/');
            SetFraction(Int32.Parse(nd[0]), Int32.Parse(nd[1]));
        }

Next, I modified your FractionMatrix.SetValues method to this:

public void SetValues(string  value)        
        {
            string[] elements = value.Replace("[", string.Empty).Replace("]", string.Empty).Trim().Split(';');
            string[] fSet;

            for (int i = 0; i < 3; i++)            
            {
                fSet = elements[i].Trim().Split(' ');
                for (int j = 0; j < 3; j++)                
                {
                    arr[i, j] = new Fraction(fSet[j]);
                }            
            }        
        }

Above you will see that I condition the incoming data into a 3 element string array.
This gets split into the 3 individual fraction strings. Finally each of those strings are passed to the Fraction constructor.

And Finally, I modified your FractionMatrix.ToString() override method to this:

public override string ToString()        
        {
            string result = "[";
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    result += " " + arr[i, j].ToString() + " ";
                }
                if(i<2)
                    result += ";";
            }
            result += "]";

            return result;
        }

I can pass in the string, watch the debuger move the data aound, and finally have the ToString() pass the data back out, and it comes out just like it was sent in (round trip confirms the data munging was done correctly).

Have Fun,
Jerry