How do i pass the Frame information like points and connections to the new class List ?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
In Form1 im adding the new point/s coordinates:

<pre class="prettyprint private void button1_Click(object sender, EventArgs e)
{
halfX = pictureBox1.ClientRectangle.Width / 2;
halfY = pictureBox1.ClientRectangle.Height / 2;
Random rnd = new Random();
offsetX = rnd.Next(-10, 10);
offsetY = rnd.Next(-10, 10);
wireObject1.addPoint(halfX + offsetX, halfY + offsetY);
pictureBox1.Refresh();
numberOfPoints++;
label5.Text = "{X = " + (halfX + offsetX) + "}" + " " + "{Y = " + (halfY + offsetY) + "}";
label5.Visible = true;
label7.Visible = true;
label16.Text = numberOfPoints.ToString();
label16.Visible = true;
label15.Visible = true;
buttonLockMode = true;
button8.Enabled = true;
button10.Enabled = true;

}[/code]
In WireObject class im updating the points coordinates in two Lists:

<pre class="prettyprint public void addPoint(float x, float y)
{
Point_X.Add(x);
Point_Y.Add(y);
}[/code]
Point_X and Y are List<float>

Now in the trackBar1 scroll event i want to do that each time im moving the trackBar to the right it will get the points and connections if there any values and add it to a new class list.

<pre class="prettyprint private void trackBar1_Scroll(object sender, EventArgs e)
{
LoadPictureAt(trackBar1.Value, sender);
currentFrameIndex = trackBar1.Value;
textBox1.Text = "Frame Number : " + trackBar1.Value;

int idx = -1;

try
{
var w = wireObjectAnimation1._coordinatesList.First(a => a.FrameNumber == currentFrameIndex);
idx = wireObjectAnimation1._coordinatesList.IndexOf(w);
}
catch
{

}

if (idx > -1)
{
// *** When moving the trackBar1 scroll to the right ***\

if (idx == 0)
{
//*** If moved the scroll to the first frame to the left ***

// button8.Enabled = true;
}
wireObjectCoordinates1 = wireObjectAnimation1._coordinatesList[idx];
//...
//do the things you want to do when the list contains the object
wireObject1._point_X = new List<float>(wireObjectCoordinates1.Point_X);
wireObject1._point_Y = new List<float>(wireObjectCoordinates1.Point_Y);
}
else
{
// *** When moving the trackBar1 scroll to the right ***\
int currentFrameIndexRight = trackBar1.Value;
wireObjectCoordinates1 = new WireObjectCoordinates() { FrameNumber = currentFrameIndexRight };
WireObjectCoordinatesCloneFrame();
wireObjectAnimation1 = new WireObjectAnimation(this, wireObject1);
//wireObjectAnimation1.GetFrame(currentFrameIndexRight);
button1.Enabled = false;
button2.Enabled = false;
button3.Enabled = false;
button4.Enabled = false;
button8.Enabled = false;
SaveFormPicutreBoxToBitMapIncludingDrawings();

// *** When moving to the right if allready did a change on the points show it. If didnt do any changes yet show the last image changes from the left !!! *** \

//*** When clicking on the Start New Animation button right there in the event of this button click to add the first frame(0) to the wireobjectanimation List ***\
}

}[/code]
WireObjectAnimation is the class i want to update so i added there a new function called it GetFrame.

<pre class="prettyprint using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;
using DannyGeneral;

namespace AnimationEditor
{
class WireObjectAnimation
{
private List<WireObjectCoordinates> WireObjectCoordinatesList = new List<WireObjectCoordinates>();
private static bool saveOrLoad;
private static string settings_dir;
private static string settings_file;
private static OptionsFile setting_file;
private static string path_settings;
public TextBox tb;
private Form1 _frm = null;
private WireObject wo1 = null;
private WireObjectCoordinates wireObjectCoordinates1;

public WireObjectAnimation(Form1 frm, WireObject wo)
{

_frm = frm;
if (_frm != null)
{
tb = (TextBox)_frm.Controls["textBox4"];
}
saveOrLoad = false;
wo1 = wo;
if (wo1 != null)
{

}
}

public List<WireObjectCoordinates> _coordinatesList
{
get { return WireObjectCoordinatesList; } // to check if to keep in this List also connections.
}

public void LoadAnimation()
{
}

public void SaveAnimation()
{
for (int i = 0; i < WireObjectCoordinatesList.Count; i++)
{
// to make instance using OptionsFile for a new text file with the animation name in the file to put version name of base object and name of animation.
// also to loop through all frames and to make that the file will look like:
// Frame 0X = 122,133,144,155
// Frame 0Y = 122,155,177,134
// Frame 1X.... and so on...



}
}

public void Settings()
{
if (saveOrLoad == true)
{
path_settings = _frm.file1; // to check that if there only points not connected even then allow to save
// the error is since the connectionStart List was empty 0 since there were no connection between points !

// The animation text file will be save in the same directory of its base file the pbject file name directory !!!!!


settings_file = tb.Text + ".txt";
string t = Path.Combine(path_settings, settings_file);
setting_file = new OptionsFile(t);
}
else
{
setting_file = new OptionsFile(_frm.file1);
}
}

public WireObjectCoordinates GetFrame(int frameNumber)
{
wireObjectCoordinates1 = new WireObjectCoordinates() { FrameNumber = frameNumber }; // How ot add a frame dosent work yet \

_frm.WireObjectCoordinatesCloneFrame();
_coordinatesList.Add(wireObjectCoordinates1);


return wireObjectCoordinates1;
}
}
}[/code]
<br/>
In the trackbar1 scroll event im using wireObjectCoordinates class to hold there the coordinates and in wireObjectAnimation class im using it to update the List



<pre class="prettyprint public List<WireObjectCoordinates> _coordinatesList
{
get { return WireObjectCoordinatesList; }
}
[/code]
And this is the wireObjectcoordinates class:

<pre class="prettyprint using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AnimationEditor
{
class WireObjectCoordinates
{
public List<float> Point_X = new List<float>();
public List<float> Point_Y = new List<float>();

public WireObjectCoordinates()
{
}

public int FrameNumber { get; set; }
}
}
[/code]
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

What i need to do is when im moving the trackBar1 bar to the right it will update the List

<pre class="prettyprint _coordinatesList[/code]
in the wireObjectanimation class. If im moving the trackBar1 bar to the left so it wont update it.

But it dosent work.

I tried in the trackBar1 scroll event to use the GetFrame function but it didnt do anything.
The Lists are empty either in the wireObjectCoordinates class and in the wireObjectAnimation class.

Cant figure out why it dosent work.


<hr class="sig danieli

View the full article
 
Back
Top