I am creating aplication that displays images in many different ways using Picture Boxes. Single page with tabs, double page using fading in/out effect,
double page 'page flip' effect and single page auto scroll effect which I have problem with. I am dinamicaly creating picture boxes, loading images, placing
'path' to a file in tag and adding handler to each picture box. All fine...
When double clicking on the P.Box image is loaded in first P.Box .Code:Private Sub CoverPageContemp() For j As Integer = 1 To numControls 'MAIN PICTURE VIEW AREA picViewer = New PictureBox picViewer.Height = PIC_HEIGHT 'Assign height picViewer.Width = PIC_WIDTH '& width values to picBox picViewer.Name = "PicView" & j.ToString 'Name the current picBox - PicView0 picViewer.Location = ptLbl picViewer.BorderStyle = BorderStyle.FixedSingle TabControl2.SelectedTab.Controls.Add(picViewer) 'add control ptLbl.Y += PIC_HEIGHT + 5 'increase ptlbl.Y to place next picturebox to the bottom index = DataGridView3.SelectedRows.Item(j - 1).Index Dim chedk As Integer Dim NoImage As String Dim level As String CoverPage = 1 Dim myimage As Image = picViewer.Image Dim g As Graphics = Graphics.FromImage(myimage) Dim mainFont As Font Dim textStyle As New FontStyle mainFont = New Font("Pristina", 32, FontStyle.Bold) 'Times New Roman Dim textArea As Rectangle = New Rectangle(20, 250, 400, 100) Dim textFormat As StringFormat = New StringFormat textFormat.LineAlignment = StringAlignment.Center textFormat.Alignment = StringAlignment.Center Dim text As String = DataGridView3.Rows(index).Cells(2).Value g.DrawString(text, mainFont, Brushes.Black, textArea, textFormat) 'COMPOSER NAME Dim mainFont1 As Font Dim textStyle1 As New FontStyle mainFont1 = New Font("Monotype Corsiva", 48, FontStyle.Italic) Dim textArea1 As Rectangle = New Rectangle(0, 120, 440, 100) Dim textFormat1 As StringFormat = New StringFormat textFormat1.LineAlignment = StringAlignment.Center textFormat1.Alignment = StringAlignment.Center Dim text1 As String = DataGridView3.Rows(index).Cells(1).Value g.DrawString(text1, mainFont1, Brushes.Red, textArea1, textFormat1) picViewer.SizeMode = PictureBoxSizeMode.StretchImage Dim dgv3path As String = DataGridView3.Rows(index).Cells(0).Value picViewer.Tag = dgv3path picViewer.Cursor = Cursors.Hand ToolTip1.SetToolTip(picViewer, "Double_Click to View Sheet Music.") ToolTip1.ShowAlways = True ToolTip1.Active = True AddHandler picViewer.DoubleClick, AddressOf picViewer_Clicked 'Adding handler to each picture box g.Dispose() Next SplitContainer1.Visible = True SplitContainer1.BringToFront() SplitContainer1.Dock = DockStyle.Fill End Sub
Every additional image (frame) from .tif file is automaticly scroll from the top.Code:Private Sub picViewer_Clicked(ByVal sender As Object, ByVal e As System.EventArgs) If BookFormToolStripMenuItem1.CheckState = CheckState.Checked Then pathload = (DirectCast(sender, PictureBox).Tag) If currentpath = pathload Then Exit Sub End If currpage12 = 0 currpage22 = 0 totalPages1 = 0 currentpath = pathload Call doublebookstyle() ElseIf AutoScrollToolStripMenuItem.CheckState = CheckState.Checked Then pathload = (DirectCast(sender, PictureBox).Tag) If currentpath = pathload Then Exit Sub End If currpage12 = 0 currpage22 = 0 totalPages1 = 0 currentpath = pathload Call AutoScrollOnePage() End Sub
I am also using Paint Event of a PictureBox to display gradiant color to imitate shadow in front of the scrolling image.Code:Private Sub AutoScrollOnePage() If pathload Is Nothing Then Exit Sub End If Dim extention As String = pathload extention = extention.Substring(extention.LastIndexOf(".") + 1).ToLower If extention = "tif" Then fs1 = File.OpenRead(pathload) srcBmp = CType(Bitmap.FromStream(fs1), Bitmap) srcBmp1 = CType(Bitmap.FromStream(fs1), Bitmap) totalPages1 = CInt(srcBmp.GetFrameCount(FrameDimension.Page) - 1) Else Exit Sub End If Dim Tpcount As Integer = TabControl3.TabPages.Count For i As Integer = Tpcount - 1 To 1 Step -1 TabControl3.TabPages.RemoveAt(i) Next Dim autopage = New TabPage autopage.Name = "TabPg" & 1 TabControl3.TabPages.Add(autopage) autopage.Text = "Auto_Scroll" autopage.BackColor = Color.Silver autopage.AutoScroll = True autopage.BorderStyle = BorderStyle.Fixed3D TabControl3.SelectTab(autopage.Name) autopage.IsAccessible = True TestPictureC = New PictureBox TestPictureD = New PictureBox TestPictureC.Height = Image.FromFile(pathload).Height 'Assign height TestPictureC.Width = Image.FromFile(pathload).Width + 10 'Assign Width TestPictureC.SizeMode = PictureBoxSizeMode.Normal TestPictureC.BackColor = Color.White Dim ptloc As Integer = (TabControl3.Width - TestPictureC.Width) / 2 - 20 '140 Dim ptLbl As Point = New Point(ptloc, 1) 'the controls position TestPictureC.Location = ptLbl TestPictureC.BorderStyle = BorderStyle.None TabControl3.SelectedTab.Controls.Add(TestPictureC) 'add control TestPictureD.Height = Image.FromFile(pathload).Height 'Assign height TestPictureD.Width = Image.FromFile(pathload).Width '760 'Assign Width TestPictureD.SizeMode = PictureBoxSizeMode.CenterImage TestPictureD.BackColor = Color.White TestPictureD.Location = TestPictureC.Location TestPictureD.BorderStyle = BorderStyle.FixedSingle TabControl3.SelectedTab.Controls.Add(TestPictureD) For j As Integer = 0 To totalPages1 - 1 currentPage1 = j srcBmp1 = CType(Bitmap.FromStream(fs1), Bitmap) srcBmp1.SelectActiveFrame(FrameDimension.Page, currentPage1) TestPictureD.Image = srcBmp1 Dim currj1 As Integer = (totalPages1 + 1) - (totalPages1 - j) If currj1 > totalPages1 Then Exit Sub End If srcBmp.SelectActiveFrame(FrameDimension.Page, currj1) Tpic = 0 For i As Integer = 0 To TestPictureC.Height - 1 Step 1 AddHandler TestPictureD.Paint, AddressOf TestPicture0_paint TestPictureC.Height = i TestPictureC.Image = srcBmp TestPictureC.BringToFront() TestPictureD.Refresh() TestPictureC.Refresh() RemoveHandler TestPictureD.Paint, AddressOf TestPicture0_paint Application.DoEvents() Next Next RemoveHandler TestPictureD.Paint, AddressOf TestPicture0_paint End Sub
The problem is: if I let the event finish displaying all pages(frames) then there is no problem with double clicking different P.Box and run different file.Code:Private Sub TestPicture0_paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) If AutoScrollToolStripMenuItem.CheckState = CheckState.Checked Then Tpic += 1 Dim rect As Rectangle = New Rectangle(0, Tpic - 2, TestPictureC.Width, 20) Dim lgb As New System.Drawing.Drawing2D.LinearGradientBrush(rect, Color.Gray, Color.Transparent, Drawing2D.LinearGradientMode.Vertical) e.Graphics.FillRectangle(lgb, rect) e.Dispose() End If End Sub
However, if I double click a different P.Box when first event is still runing then
file gets open run as it should but when finish, it starts displaying the file again ?
Sorry for posting so much code, but I wanted you to check what am I doing wrong. Thanks for any help..( I had to shorten the first code_to many characters in the post..)




Reply With Quote