473,799 Members | 3,255 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

69 New Member
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 3685
GaryTexmo
1,501 Recognized Expert Top Contributor
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
Chocolade
69 New Member
Gary i couldnt find out how to use the trackbar.value i tried to add something like: this.trackBar1_ radar_images.Va lue = 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 Recognized Expert Top Contributor
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
4312
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 eliminated the JavaScript errors I was seeing. The fact that the target URL didn't execute was because certain variables weren't being passed to it. What I need to do is to pass a conditional variable to the target URL, when the form is submitted,...
0
3230
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 click and drag the scroll box (thumb track) the picturebox does not scroll until you release it. Is there a way to scroll the picturebox while you move the scrollbox (like when you scroll a web page)? Or do you have to use the scroll bar controls...
5
5804
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 criteria: 14174 x 7874 Pixels (111.61MPixels), 1 BitsPerPixel, 3200x3200 DPI, No Compression. The memory consumption for loading this image should be 13.31 MB (13,952,776 Bytes) (this is what IrfanView takes, http://www.irfanview.com/). I’m loading...
3
5401
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 trackBar1_Scroll so how do I print out the Scroll value?
2
1291
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" CommandName="Delete"></asp:But­tonColumn>
0
1806
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 automatic scrolling - that is, when a user clicks on the trackbar (on either side of the pointer) the pointer moves toward the clicked location. Is there anyway to disable this behavior?
3
1809
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 make a table with 2 columns and then for every one, depending on its position in the string i need to output a word and then go to the next 1 and output a dif word.... its amenities, winter activities and summer activities for cottages that i...
2
5940
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
3923
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, when the user moves his mouse over some sensible areas (that are other invisible small PictureBox), the cursor has to become a hand. In order to realize it, I wrote this code: private void stradario_MouseMove(object sender, MouseEventArgs...
0
1224
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, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint eGraphics = e.Graphics TryToCreateRec(eGraphics) PictureBox1.Refresh() End Sub Public Sub TryToCreateRec(ByVal eGraphics As Graphics) Dim blackPen As New Pen(Color.White,...
0
9687
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9541
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10484
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10228
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9072
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6805
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5463
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3759
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.