473,385 Members | 1,893 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to use a trackbar to scroll through images in picturebox but cant make it

I want to do few things with it:

1. If the user is moving the trackbar the bar it self to the left wich is the start it will stop if he is using the mouse or the mouse wheel or the keyboards it will stop on the most left and when he gets to the most right side it will stop there too.

2. I want that the user will be able to move the bar in three ways: with keyboards image by image with the mouse pointer drag it from side to side fast and by the nouse scroll button.

So using the mouse wheel i did a;;ready and the user can scroll throught the images with the mouse wheel. And i did it that only when the user click on the picturebox and its in fullscreen only then he can scroll between the images. Now i want to add the TrackBar.

So first this is the code of the event when the user click on the picturebox1 and make it on fullscreen:

Expand|Select|Wrap|Line Numbers
  1. private void pictureBox1_Click(object sender, EventArgs e)
  2.          {
  3.              Button picturebox1button;
  4.              picturebox1button = new Button();
  5.              this.Controls.Add(picturebox1button);
  6.              picturebox1button.Click+=new EventHandler(picturebox1button_Click);
  7.  
  8.             if (button_switch == true)
  9.              {
  10.                  formInitialLocation = this.Location;
  11.                  formInitialSize = this.Size;
  12.                  this.FormBorderStyle = FormBorderStyle.None;
  13.                  this.Bounds = Screen.PrimaryScreen.Bounds;
  14.                  pictureBox1.Dock = DockStyle.Fill;
  15.                  pictureBox1.BringToFront();
  16.                  button_switch = false;
  17.                  this.button_legend_1.Visible = true;
  18.                  this.button_legend_1.Size = Properties.Resources.radar_scale_heb.Size;
  19.                  this.button_legend_1.Image = Properties.Resources.radar_scale_heb;
  20.                  this.button_legend_1.BringToFront();
  21.                  this.button_legend_1.Location = new Point(Screen.GetWorkingArea(this).Width - button_legend_1.Width, 24);
  22.                  this.button_legend_1.Enabled = true;
  23.                  this.button_legend_2.Visible = true;
  24.                  this.button_legend_2.Width = 350;
  25.                  this.button_legend_2.Location = new Point(Screen.GetWorkingArea(this).Width - button_legend_2.Width, button_legend_1.Height+30);
  26.  
  27.                 picturebox1button.Visible = true;
  28.                  picturebox1button.BringToFront();
  29.                  picturebox1button.Location = new Point(Screen.GetWorkingArea(this).Width - 260 , 24+button_legend_1.Height+50);
  30.                  picturebox1button.Enabled = true;
  31.                  picturebox1button.Width = 260;
  32.                  picturebox1button.Text = "Save image as screen size resolution";
  33.  
  34.                 this.trackBar1_radar_images.Visible = true;
  35.                  trackBar1_radar_images.Location = new Point(Screen.GetWorkingArea(this).Width - 250, 24 + button_legend_1.Height + 80);
  36.                  trackBar1_radar_images.Width = 250;
  37.                  trackBar1_radar_images.BringToFront();
  38.                  trackBar1_radar_images.SmallChange = 1;
  39.                  trackBar1_radar_images.LargeChange = 5;
  40.                  trackBar1_radar_images.TickStyle = TickStyle.BottomRight;
  41.                  trackBar1_radar_images.TickFrequency = 1;
  42.                  trackBar1_radar_images.BringToFront();
  43.                  trackBar1_radar_images.Show();
  44.                  if (sf == null)
  45.                  {
  46.                  }
  47.                  else
  48.                  {
  49.                      int it;
  50.                      string Next_File;
  51.                      it = last_image_file(); // ליישם גם על הלויין.
  52.                      Next_File = sf + @"\radar" + it.ToString("D3") + ".jpg";
  53.                      FileInfo myinf = new FileInfo(Next_File);
  54.                      DateTime time = myinf.CreationTime;
  55.                      this.button_legend_2.Text = "Last downloaded file is : " + myinf.Name + " At date : " + time;
  56.                      this.button_legend_2.BringToFront();
  57.                      this.button_legend_2.Enabled = true;
  58.                  }
  59.              }
  60.              else
  61.              {
  62.                  this.FormBorderStyle = FormBorderStyle.FixedSingle;
  63.                  this.Dock = DockStyle.None;
  64.                  pictureBox1.Dock = DockStyle.None;
  65.                  button_switch = true;
  66.                  this.Location = formInitialLocation;
  67.                  this.Size = formInitialSize;
  68.                  this.button_legend_1.Enabled = false;
  69.                  this.button_legend_1.Visible = false;
  70.                  this.button_legend_2.Enabled = false;
  71.                  this.button_legend_2.Visible = false;
  72.                  trackBar1_radar_images.Visible = false;
  73.              }
  74.          }
  75.  
You can see there im using to setup the trackbar1.

Now the code of the onmousewheel event :
Expand|Select|Wrap|Line Numbers
  1.  protected override void OnMouseWheel(MouseEventArgs e)
  2.          {
  3.              trackBar1_radar_images.Scroll+=new EventHandler(trackBar1_radar_images_Scroll);
  4.                  DirectoryInfo dir1 = new DirectoryInfo(sf);
  5.                  file_info_mouse_wheel = dir1.GetFiles("radar*.jpg");
  6.                  file_info_mouse_wheel = file_info_mouse_wheel.OrderBy((b) => b.LastWriteTime).ToArray();
  7.                  DirectoryInfo dir2 = new DirectoryInfo(satellite_dir);
  8.                  file_info_mouse_wheel_satellite = dir2.GetFiles("satellite*.jpg");
  9.                  file_info_mouse_wheel_satellite = file_info_mouse_wheel_satellite.OrderBy((b) => b.LastWriteTime).ToArray();
  10.                  base.OnMouseWheel(e);
  11.                  if (pictureBox1.Dock == DockStyle.Fill)
  12.                  {
  13.                          if (e.Delta > 0)
  14.                          {
  15.                              file_indexs--;
  16.                              if (file_indexs <= 0)
  17.                                file_indexs = file_info_mouse_wheel.Length - 1;
  18.                            /*  trackBar1_radar_images.Minimum = 0;
  19.                              trackBar1_radar_images.Maximum = file_info_mouse_wheel.Length;
  20.                              trackBar1_radar_images.Value = file_info_mouse_wheel.Length - 1;*/
  21.  
  22.                             LoadPictureAt(file_indexs);
  23.                          }
  24.                          else if (e.Delta < 0)
  25.                          {
  26.                              file_indexs++;
  27.                              if (file_indexs >= file_info_mouse_wheel.Length)
  28.                                  file_indexs = 0;
  29.                            /*  trackBar1_radar_images.Value = file_indexs;
  30.                              trackBar1_radar_images.Minimum = 0;
  31.                              trackBar1_radar_images.Maximum = file_info_mouse_wheel.Length;*/
  32.  
  33.                             LoadPictureAt(file_indexs);
  34.  
  35.                         }
  36.                  }
  37.                  if (pictureBox2.Dock == DockStyle.Fill)
  38.                  {
  39.                      if (e.Delta > 0)
  40.                      {
  41.                          satellite_file_indexs--;
  42.                          if (satellite_file_indexs <= 0)
  43.                              satellite_file_indexs = file_info_mouse_wheel_satellite.Length + 1;
  44.  
  45.                         LoadPictureAtSatellite(satellite_file_indexs);
  46.  
  47.                     }
  48.                      else if (e.Delta < 0)
  49.                      {
  50.                          satellite_file_indexs++;
  51.                          if (satellite_file_indexs >= file_info_mouse_wheel_satellite.Length)
  52.                              satellite_file_indexs = 0;
  53.                          LoadPictureAtSatellite(satellite_file_indexs);
  54.                      }
  55.                  }
  56.          }
  57.  
  58.         private void trackBar1_radar_images_Scroll(object sender, EventArgs e)
  59.          {
  60.              trackBar1_radar_images.Value = file_indexs;
  61.              trackBar1_radar_images.Minimum = 0;
  62.              trackBar1_radar_images.Maximum = file_info_mouse_wheel.Length;
  63.          }
  64.  
I tried to use the trackbar1 Scroll event and before it i tried to use the trackbar1 inside where i check the mouse delta e.delta but it dosent work good.

The next two events im not sure if they are important:
Expand|Select|Wrap|Line Numbers
  1. private bool LoadPictureAt(int nIndex)
  2.          {
  3.              bool bRet = false;
  4.              if (sf == null)
  5.              {
  6.              }
  7.              else
  8.              {
  9.                  if (nIndex >= 0 && nIndex < file_info_mouse_wheel.Length)
  10.                  {
  11.                      nindex_radar = nIndex;
  12.                      pictureBox1.Load(file_info_mouse_wheel[nIndex].FullName);
  13.                      bRet = true;
  14.                  }
  15.              }
  16.              return bRet;
  17.  
  18.         }
  19.          private bool LoadPictureAtSatellite(int nIndexs)
  20.          {
  21.              bool aRet = false;
  22.              if (nIndexs >= 0 && nIndexs < file_info_mouse_wheel_satellite.Length)
  23.              {
  24.                  nindexs_satellite = nIndexs;
  25.                  pictureBox2.Load(file_info_mouse_wheel_satellite[nIndexs].FullName);
  26.                  aRet = true;
  27.              }
  28.              return aRet;
  29.          }
  30.  
So the only things i need to do is as i mentioned above with the trackbar1

First only on picturebox1 then i want to make the same with picturebox2

When i mean moving the trackbar the bar to the left so its the start so it will show the first image in the index 001 and when its to the mose of the right it will show the last image wich is the last image downloaded.

So on the most left it will be the oldest image and on the most right the most newest image.

And if its possible to use/fix/repair/use my code the one i copied/paste here.

Thanks a lot.
Apr 20 '11 #1
3 3663
GaryTexmo
1,501 Expert 1GB
I'm not sure how to approach this one since you've kind of asked about a lot. I'll dive into the trackbar thing, and if you're still having trouble with the other stuff we can look at that too.

Your images, they're in a list right? Well, could you use the track bar's value property to control the index in the list, which in turn tells you what image you're displaying?

I think if I were to do it, that's how I would start. From your code, it looks like you're kind of starting to do that, so can you maybe tie it into the track bar?

One last thing, and maybe a bit of advice that you can take or leave. I'd consider loading your images at the start (unless there will be many, and large ones at that, or they'll change on disk frequently and you want to see updates) because every time you cycle your image you're going to be loading the image from the file over and over. It's much faster to load it once and show the cached version and it also cuts down on your disk access time. As somewhat mentioned though, that might not be desirable. Like, loading 10gb of photos into memory might not be the way to go if you're browsing a large picture folder ;)
Apr 20 '11 #2
Gary i couldnt find out how to use the trackbar.value i tried to add something like: this.trackBar1_radar_images.Value = file_indexs according to my code but its giving me error say it should be between minimum and maximum.
Apr 20 '11 #3
GaryTexmo
1,501 Expert 1GB
Yea, the minimum and maximum are values on the TrackBar object that you set. It looks like the default maximum is 10 and the default minimum is 0. If the value of file_indexs doesn't fit within that range, that's probably why you're getting the error.

I'd suggest, when you load your image list, set the track bar's maximum to the length of the file list.

*Edit: You might also want to consider using a ScrollBar, as it might provide a bit nicer of a view than a TrackBar... but ultimately it's up to you :D
Apr 20 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Orest Kinasevych | last post by:
Okay, I made sense of the earlier suggestions and realized I was on the right track -- I appreciate the feedback which got me to this point. The suggestions posted here indeed worked and...
0
by: Paul Loveless | last post by:
Hi all. I have a user control that contains a picturebox within a panel with the panel set to autoscroll the picturebox. One thing that I have noticed with the default functionality is when you...
5
by: Sharon | last post by:
I’m writing a Windows application. In the form I have a Panel and inside the panel I have a PictureBox control. I’m loading the PictureBox control with BMP image that has the following...
3
by: Geoff Cox | last post by:
Hello, I am using Visual C++ 2005 Express Beta 2 and cannot sort out how to use the Scroll property value for a trackBar. Under Event properties the name for the Scroll property is...
2
by: androoo | last post by:
Hi I am learing how to use the grid in asp.net. Im trying to replace the button columns with nice friendly images. So : <asp:ButtonColumn Text="Delete"...
0
by: deko | last post by:
I'm using VS05/.NET 2.0 with a TrackBar control in a Windows Forms application. I need to be able to manually scroll the trackbar (hold down left mouse button and drag), but I need to prevent...
3
by: Kentor | last post by:
hello, im trying to make a little loop, but i cant figure it out... i have a string with a bunch of 1s and 0s in it: 110101010101111010101 .... i need to count the number of 1s divide it by 2 and...
2
by: gupta.amber | last post by:
Hi, As a newbie to C# application programing ...I would like to know is there a way to disable the user scroling of standard track bar programatically... Thanks in advance
1
by: id86 | last post by:
Hello everybody! I've a problem with MouseMove event in a C# project using Visual Studio 2005. This is my situation: there is a PictureBox (bigger than the panel in which it is) and I want that,...
0
by: swagatikasahoo | last post by:
how to display all lines if i will scroll the picturebox. hi, ok i m sending the code. ****************************************************** Private Sub PictureBox1_Paint(ByVal sender As Object,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.