How can i add the value of trackBar1 in range to a List ?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
When running the program if the user check a checkbox1 it will show a panel wich there the user can select by clicking left and right on the mouse and mark two bars. For example the user put the first mark on 20 then the second one on 40. The trackBar1
move when the user mark them.
The first mark variable called Start the second one called End.
Now i need to find the number of images between the Start and End and convert them to file names and put all the files names between Start and End into the list.

This is the code of the panel with the trackBar1:

<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; using System;
<span style="color:Blue; using System.Collections.Generic;
<span style="color:Blue; using System.ComponentModel;
<span style="color:Blue; using System.Drawing;
<span style="color:Blue; using System.Data;
<span style="color:Blue; using System.Linq;
<span style="color:Blue; using System.Text;
<span style="color:Blue; using System.Windows.Forms;
<span style="color:Blue; using System.Drawing.Drawing2D;

<span style="color:Blue; namespace WindowsFormsApplication1
{
<span style="color:Blue; public <span style="color:Blue; partial <span style="color:Blue; class MyTrackPanelss : UserControl
{
<span style="color:Blue; public <span style="color:Blue; int Start { <span style="color:Blue; get; <span style="color:Blue; set; }
<span style="color:Blue; public <span style="color:Blue; int End { <span style="color:Blue; get; <span style="color:Blue; set; }

<span style="color:Blue; private <span style="color:Blue; int _tbPadding = 14;
<span style="color:Blue; private <span style="color:Blue; float _penWidth = 15F;

<span style="color:Blue; public <span style="color:Blue; int TBPadding { <span style="color:Blue; get { <span style="color:Blue; return _tbPadding; } }
<span style="color:Blue; public <span style="color:Blue; float PenWidth { <span style="color:Blue; get { <span style="color:Blue; return _penWidth; } }

<span style="color:Blue; public MyTrackPanelss()
{
InitializeComponent();
Start = 0;
End = <span style="color:Blue; this.trackBar1.Maximum;

}

<span style="color:Blue; private <span style="color:Blue; void panel1_Paint(<span style="color:Blue; object sender, PaintEventArgs e)
{
<span style="color:Blue; using (SolidBrush b = <span style="color:Blue; new SolidBrush(SystemColors.ControlDark))
e.Graphics.FillRectangle(b, <span style="color:Blue; this.ClientRectangle);
<span style="color:Blue; using (GraphicsPath gPath = <span style="color:Blue; new GraphicsPath())
{
gPath.AddLine(<span style="color:Blue; new Point(_tbPadding, 0), <span style="color:Blue; new Point(_tbPadding, panel1.ClientSize.Height - 2));
gPath.AddLine(<span style="color:Blue; new Point(<span style="color:Blue; this.trackBar1.ClientSize.Width - _tbPadding, panel1.ClientSize.Height - 2),
<span style="color:Blue; new Point(<span style="color:Blue; this.trackBar1.ClientSize.Width - _tbPadding, 0));

<span style="color:Blue; using (SolidBrush sb = <span style="color:Blue; new SolidBrush(SystemColors.ActiveCaption))
e.Graphics.FillPath(sb, gPath);

e.Graphics.DrawPath(Pens.Black, gPath);
}

<span style="color:Blue; int maxRange = <span style="color:Blue; this.trackBar1.Maximum - <span style="color:Blue; this.trackBar1.Minimum;
<span style="color:Green; //_tbPadding for end and start of ticks of trackbar
<span style="color:Blue; double rangeOne = ((<span style="color:Blue; this.panel1.ClientSize.Width - _tbPadding * 2.0) / (<span style="color:Blue; double)maxRange);
<span style="color:Blue; if (End < Start)
{
<span style="color:Blue; int tmp = End;
End = Start;
Start = tmp;
}

<span style="color:Blue; if (End == Start)
{
MessageBox.Show(<span style="color:#A31515; "You cannot select start point and end point on the same place");
}
<span style="color:Blue; float xVal = (<span style="color:Blue; float)(_tbPadding + (Start * rangeOne));
<span style="color:Blue; float xVal2 = (<span style="color:Blue; float)(_tbPadding + (End * rangeOne));

<span style="color:Blue; if (Start >= <span style="color:Blue; this.trackBar1.Minimum)
{
<span style="color:Blue; using (Pen greenPen = <span style="color:Blue; new Pen(Color.Green, _penWidth))
{
e.Graphics.DrawLine(greenPen, <span style="color:Blue; new PointF(xVal, 1), <span style="color:Blue; new PointF(xVal, <span style="color:Blue; this.panel1.ClientSize.Height - 2));
<span style="color:Blue; using (Pen p = <span style="color:Blue; new Pen(Color.Black))
{
p.StartCap = LineCap.ArrowAnchor;
e.Graphics.DrawLine(p, <span style="color:Blue; new PointF(xVal, 1), <span style="color:Blue; new PointF(xVal, <span style="color:Blue; this.panel1.ClientSize.Height - 2));
}
e.Graphics.DrawString((Start+1).ToString(), <span style="color:Blue; this.Font, Brushes.Black, <span style="color:Blue; new PointF(xVal, <span style="color:Blue; this.panel1.ClientSize.Height / 2F));
}
}

<span style="color:Blue; if (End <= <span style="color:Blue; this.trackBar1.Maximum)
{
<span style="color:Blue; using (Pen redPen = <span style="color:Blue; new Pen(Color.Red, _penWidth))
{
SizeF s = e.Graphics.MeasureString(End.ToString(), <span style="color:Blue; this.Font);
e.Graphics.DrawLine(redPen, <span style="color:Blue; new PointF(xVal2, 1), <span style="color:Blue; new PointF(xVal2, <span style="color:Blue; this.panel1.ClientSize.Height - 2));
<span style="color:Blue; using (Pen p = <span style="color:Blue; new Pen(Color.Black))
{
p.StartCap = LineCap.ArrowAnchor;
e.Graphics.DrawLine(p, <span style="color:Blue; new PointF(xVal2, 1), <span style="color:Blue; new PointF(xVal2, <span style="color:Blue; this.panel1.ClientSize.Height - 2));
}
<span style="color:Blue; if (xVal2 - xVal > s.Width + redPen.Width)
e.Graphics.DrawString((End+1).ToString(), <span style="color:Blue; this.Font, Brushes.Black, <span style="color:Blue; new PointF(xVal2 - s.Width, <span style="color:Blue; this.panel1.ClientSize.Height / 2F));
<span style="color:Blue; else
e.Graphics.DrawString((End+1).ToString(), <span style="color:Blue; this.Font, Brushes.Black, <span style="color:Blue; new PointF(xVal2, <span style="color:Blue; this.panel1.ClientSize.Height / 2F));
}
}

<span style="color:Blue; string t = <span style="color:#A31515; "click left to specify start, right to specify end";
SizeF sz = e.Graphics.MeasureString(t, <span style="color:Blue; this.Font);
e.Graphics.DrawString(t, <span style="color:Blue; this.Font, Brushes.Black, <span style="color:Blue; new PointF((<span style="color:Blue; this.panel1.ClientSize.Width - sz.Width) / 2F, 0));
}

<span style="color:Blue; private <span style="color:Blue; void panel1_MouseClick(<span style="color:Blue; object sender, MouseEventArgs e)
{
<span style="color:Blue; int maxRange = <span style="color:Blue; this.trackBar1.Maximum - <span style="color:Blue; this.trackBar1.Minimum;
<span style="color:Green; //_tbPadding for end and start of ticks of trackbar
<span style="color:Blue; double rangeOne = ((<span style="color:Blue; this.panel1.ClientSize.Width - _tbPadding * 2.0) / (<span style="color:Blue; double)maxRange);
<span style="color:Blue; if (e.Button == MouseButtons.Left && e.X >= _tbPadding && e.X <= panel1.ClientSize.Width - _tbPadding)
{
<span style="color:Blue; int i = (<span style="color:Blue; int)((e.X - _tbPadding) / rangeOne);
Start = i;
trackBar1.Value = i;

<span style="color:Blue; this.panel1.Invalidate();
}

<span style="color:Blue; if (e.Button == MouseButtons.Right && e.X >= _tbPadding && e.X <= panel1.ClientSize.Width - _tbPadding + rangeOne)
{
<span style="color:Blue; int i = (<span style="color:Blue; int)((e.X - _tbPadding) / rangeOne);
End = i;
trackBar1.Value = i;

<span style="color:Blue; this.panel1.Invalidate();
}
}
}
}

[/code]
<br/>
And this is the form code where i need to use the Start and End variables in the bottom i have a button2_Click event when im clicking this button i need it to create the List<string> from the images between the Start and End variables from the MyTrackPanel.cs

The thing is that im using the panel trackBar1 only to scroll between the images i need now to get the images names according to the Start and the End marks and create a List from the images in between Start and End.

<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; using System;
<span style="color:Blue; using System.Collections.Generic;
<span style="color:Blue; using System.ComponentModel;
<span style="color:Blue; using System.Data;
<span style="color:Blue; using System.Drawing;
<span style="color:Blue; using System.Linq;
<span style="color:Blue; using System.Text;
<span style="color:Blue; using System.Windows.Forms;
<span style="color:Blue; using System.IO;
<span style="color:Blue; using unfreez_wrapper;

<span style="color:Blue; namespace WindowsFormsApplication1
{
<span style="color:Blue; public <span style="color:Blue; partial <span style="color:Blue; class Picturebox2_Fullscreen : Form
{
<span style="color:Blue; bool startEnd;
UnFreezWrapper unfreez;
FileInfo[] file_info_mouse_wheel;
<span style="color:Blue; string satellite_images_download_directory;
TrackBar trackBar1 = <span style="color:Blue; null;
<span style="color:Blue; public Picturebox2_Fullscreen()
{
InitializeComponent();
startEnd = <span style="color:Blue; false;
unfreez = <span style="color:Blue; new UnFreezWrapper();
<span style="color:Green; //splitContainer1.SplitterDistance = 594;
myTrackPanelss1.panel1.Enabled = <span style="color:Blue; false;
myTrackPanelss1.panel1.Visible = <span style="color:Blue; false;
trackBar1 = myTrackPanelss1.trackBar1;
label2.Visible = <span style="color:Blue; false;
label3.Visible = <span style="color:Blue; false;
<span style="color:Blue; if (satellite_images_download_directory == <span style="color:#A31515; "")
{
trackBar1.Enabled = <span style="color:Blue; false;
}
<span style="color:Blue; else
{
trackBar1.Enabled = <span style="color:Blue; true;
trackBar1.Select();
satellite_images_download_directory = Options_DB.Get_Satellite_Images_Download_Directory();
DirectoryInfo dir1 = <span style="color:Blue; new DirectoryInfo(satellite_images_download_directory);
file_info_mouse_wheel = dir1.GetFiles(<span style="color:#A31515; "*.png");
<span style="color:Blue; if (file_info_mouse_wheel.Count() == 0)
{
<span style="color:Blue; return;
}
<span style="color:Blue; else
{
trackBar1.Minimum = 0;
trackBar1.Maximum = file_info_mouse_wheel.Length - 1;
<span style="color:Green; //trackBar1.Value = file_info_mouse_wheel.Length - 1;
<span style="color:Blue; this.myTrackPanelss1.End = trackBar1.Maximum;
trackBar1.ValueChanged += <span style="color:Blue; new EventHandler(trackBar1_Scroll);
trackBar1.Value = file_info_mouse_wheel.Length - 1;
label2.Text = <span style="color:#A31515; "Overall Number Of Images: " + file_info_mouse_wheel.Length;
label3.Text = <span style="color:#A31515; "Image Name: " + file_info_mouse_wheel[trackBar1.Value].FullName;
label2.Visible = <span style="color:Blue; true;
label3.Visible = <span style="color:Blue; true;

}
}
<span style="color:Green; /*trackBar1.Select();
trackBar1.Invalidate();
trackBar1.Refresh();
pictureBox1.Invalidate();
pictureBox1.Refresh();*/
}

<span style="color:Blue; private <span style="color:Blue; void splitContainer1_Panel1_DoubleClick(<span style="color:Blue; object sender, EventArgs e)
{
<span style="color:Blue; this.Close();
}

<span style="color:Blue; private <span style="color:Blue; void splitContainer1_Panel2_DoubleClick(<span style="color:Blue; object sender, EventArgs e)
{
<span style="color:Blue; this.Close();
}

<span style="color:Blue; private <span style="color:Blue; void pictureBox1_DoubleClick(<span style="color:Blue; object sender, EventArgs e)
{
<span style="color:Blue; this.Close();
}


<span style="color:Green; /* private bool LoadPictureAtSatellite(int nIndex)
{ // To check and compare with picturebox1_fullscreen.cs to see if picturebox1_fullscreen.cs is working good then compare between picturebox1_fullscreen and picutrebox2_fullscreen and do the same
// in picutrebox2_fullscreen as it is in picturebox1_fullscreen !
bool bRet = false;

if (nIndex >= 0 && nIndex < file_info_mouse_wheel.Length)
{
pictureBox1.Load(file_info_mouse_wheel[nIndex].FullName);
bRet = true;
}
return bRet;

}*/

<span style="color:Blue; private <span style="color:Blue; bool LoadPictureAtSatellite(<span style="color:Blue; int nIndex, <span style="color:Blue; object c)
{

<span style="color:Blue; bool bRet = <span style="color:Blue; false;

<span style="color:Blue; if (nIndex >= 0 && nIndex < file_info_mouse_wheel.Length)
{
<span style="color:Blue; if (c.Equals(trackBar1))

pictureBox1.Load(file_info_mouse_wheel[nIndex].FullName);
bRet = <span style="color:Blue; true;

}
<span style="color:Blue; return bRet;

}

<span style="color:Blue; private <span style="color:Blue; void trackBar1_Scroll(<span style="color:Blue; object sender, EventArgs e)
{
label2.Visible = <span style="color:Blue; true;
label3.Visible = <span style="color:Blue; true;
LoadPictureAtSatellite(trackBar1.Value, sender);
label2.Text = <span style="color:#A31515; "Overall Number Of Images: " + file_info_mouse_wheel.Length;
label3.Text = <span style="color:#A31515; "Image Name: " + file_info_mouse_wheel[trackBar1.Value].FullName;
}


<span style="color:Blue; public PictureBox picturebox1_Satellite(PictureBox pb1)
{
pictureBox1.Image = pb1.Image;
<span style="color:Blue; return pictureBox1;
}

<span style="color:Blue; public <span style="color:Blue; string picturebox1_lastFile_Satellite(<span style="color:Blue; string last_file)
{
pictureBox1.Load(last_file);
<span style="color:Blue; return last_file;
}

<span style="color:Blue; private <span style="color:Blue; void checkBox1_CheckedChanged(<span style="color:Blue; object sender, EventArgs e)
{
<span style="color:Blue; if (checkBox1.Checked)
{
startEnd = <span style="color:Blue; true;
myTrackPanelss1.panel1.Enabled = <span style="color:Blue; true;
myTrackPanelss1.panel1.Visible = <span style="color:Blue; true;
}
<span style="color:Blue; else
{
myTrackPanelss1.panel1.Enabled = <span style="color:Blue; false;
myTrackPanelss1.panel1.Visible = <span style="color:Blue; false;
}
}

<span style="color:Blue; private <span style="color:Blue; void button2_Click(<span style="color:Blue; object sender, EventArgs e)
{


}

}
}


[/code]
<br/>
Thanks. <hr class="sig danieli

View the full article
 
Back
Top