Question Add new page as image (?)

Joined
Sep 15, 2011
Messages
17
Programming Experience
3-5
Hello dear forum,

My question is a bit hard to explain, but I will try my best:

Imagine a have a painting program with a PictureBox, which I can paint on.
I would like to have the ability to press "Next Page", and the program shall store my current image/page as "Page#" (where # is the number), and create a new one, which I can draw on. I should then be able to click "Previous Page", and get my previous image/page (in this case, "Page1"), and be able to edit/view that.

So I have a PictureBox which is the "viewer", and then I have a lot of images, which are the pages.
The way I would do it, is that I would store them locally as files, and call them "Page1", "Page2" and etc. in a folder.

But I would assume, that this will require a bit processing power, and slow down the program - it will also cause problems, if for example "Page3" would be deleted - then the current "Page4" should be renamed to "Page3" and etc and etc....

IS THERE AN EASIER WAY OF DOING THIS?
Like maybe storing these images as variables, or something?

Is it even possible to declare a variable like:

VB.NET:
Dim intNumber As New Integer = 2
Dim page + intNumber As New PictureBox

So, now I would have "page2" as a new PictureBox?
As far as I know, that's not possible - well, not the way I do it.

Any help would be appreciated - Thanks in advance!
Martin.
 
A PictureBox does't not store anything and nothing can be stored from it. PictureBox control just displays an image, and as a control window it can also be used as 'canvas' for dynamic painting from its Paint event handler.
Depending on what you intend to do, that is the information you must store.
If for example you going to draw on bitmaps you can store those bitmaps, for example in a List(Of Bitmap), which is a list collection acting as a dynamic array.
 
Store each file?

Aaah, I see.

But should I then export and store each image as a .bmp file, or isn't there a way to store them in the cache?
Because I know that you can declare Bitmaps in-code, but is it possible to declare them dynamically? :O
 
If by cache you mean memory then, yes, all variable values are stored in memory. How long depends on variable scope. Scope in Visual Basic
 
Aha!

Hmm, but what I though of, was just storing each image as a bitmap in a Temp folder :)
Because, is it possible to declare variables with dynamic names?

Like if i have an integer variable "intPage" and then i would like to create a variable, which is called "Page" + the intPage variable?
 
It is a simple task to build a custom wrapper around the Bitmap class (this is not exactly the same thing as inheritance, but is close). You could do something like this:

VB.NET:
Public Class MyBitmap
  ' Public properties that you want to add to a Bitmap object.  Add as many as you want here.
  Public Name As String
  Public PageNumber As Integer

  ' The Bitmap object we want to "wrap"
  Public Bitmap As System.Drawing.Bitmap

  Public Sub New()
    ' You might need to create a bitmap object to prevent Invalid Object exceptions
  End Sub
End Class
 
Like if i have an integer variable "intPage" and then i would like to create a variable, which is called "Page" + the intPage variable?
In its most basic form that is just a Dictionary(Of String, Bitmap), in other words a collection of variables indexed by a string key.
Grouping object properties as a new type as azuckerman points out is also an option.
 
Seems a bit too complicated, and I don't think I will use it :)
I have created a code, which saves the pages as images into a folder, and loads them as a stream, when I change a page.

Now, I need to generate a grid with all the pages as click-able images, HOW THE #%¤§!? ? :D

My idea so far:

When the "View all pages" button is clicked, a new form/window appears, and thumbnails for each "page.bmp" file are created/generated.
One should be able to click a thumbnail, and then the form will close, and the page will be changed to the page, that the user clicked.

Is this even possible? I could image, that I should draw a PictureBox via code for each "page.bmp" file, but how to make it click-able? :D
 

Latest posts

Back
Top