S-10 Man
August 27th, 2001, 07:33 PM
Is there a way to have a very large picture behind a picture box and be able to move the picture box around the large picture showing different views?? Thanks a lot.
|
Click to See Complete Forum and Search --> : Mini-Map Type Effect S-10 Man August 27th, 2001, 07:33 PM Is there a way to have a very large picture behind a picture box and be able to move the picture box around the large picture showing different views?? Thanks a lot. Cakkie August 28th, 2001, 01:33 AM The picturebox control has a PaintPicture method. This allows you to specify the location of where it needs to start drawing. ' This would look like the view has moved right Picture1.PaintPicture LoadPicture("somepic.bmp"), -100, 0 ' This would look like the view has moved left Picture1.PaintPicture LoadPicture("somepic.bmp"), 100, 0 ' This would look like the view has moved down Picture1.PaintPicture LoadPicture("somepic.bmp"), 0, -100 ' This would look like the view has moved up Picture1.PaintPicture LoadPicture("somepic.bmp"), 0, 100 Tom Cannaerts slisse@planetinternet.be Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook shree August 28th, 2001, 07:35 AM I have given below the form code of a project from which you can start with. Copy this code and paste onto either WordPad or Word and save it as a text file. Give it the name frmScroll.frm Now start VB by double clicking on frmScroll.frm. You will get one error while loading. Click on Yes. Set the picture property of picture3 to a large image. Now click on the CheckBox. When it is checked, the image will fit, when not, you can scroll through the image. When working with graphics, make sure that the picture boxes have AutoRedraw set to true and ScaleMode is set to Pixel. To make the program respond faster, you can use StretchBlt. I used PaintPicture for a quick solution. VERSION 5.00 Begin VB.Form Form1 Caption = "Form1" ClientHeight = 9030 ClientLeft = 60 ClientTop = 345 ClientWidth = 9540 LinkTopic = "Form1" ScaleHeight = 602 ScaleMode = 3 'Pixel ScaleWidth = 636 StartUpPosition = 3 'Windows Default Begin VB.CheckBox Check1 Caption = "Fit" Height = 375 Left = 8040 TabIndex = 5 Top = 840 Width = 1095 End Begin VB.VScrollBar VScroll1 Height = 7815 Left = 7560 TabIndex = 4 Top = 120 Width = 255 End Begin VB.HScrollBar HScroll1 Height = 255 Left = 360 TabIndex = 3 Top = 7920 Width = 7215 End Begin VB.PictureBox Picture3 Appearance = 0 'Flat AutoRedraw = -1 'true AutoSize = -1 'true BackColor = &H80000005& BorderStyle = 0 'None ForeColor = &H80000008& Height = 9465 Left = 8160 Picture = "Form1.frx":0000 ScaleHeight = 631 ScaleMode = 3 'Pixel ScaleWidth = 926 TabIndex = 2 Top = 5520 Visible = 0 'false Width = 13890 End Begin VB.PictureBox Picture1 Appearance = 0 'Flat AutoRedraw = -1 'true BackColor = &H80000005& BorderStyle = 0 'None ForeColor = &H80000008& Height = 7815 Left = 360 ScaleHeight = 521 ScaleMode = 3 'Pixel ScaleWidth = 481 TabIndex = 0 Top = 120 Width = 7215 Begin VB.PictureBox Picture2 Appearance = 0 'Flat AutoRedraw = -1 'true AutoSize = -1 'true BackColor = &H80000005& BorderStyle = 0 'None ForeColor = &H80000008& Height = 7815 Left = 0 ScaleHeight = 521 ScaleMode = 3 'Pixel ScaleWidth = 481 TabIndex = 1 Top = 0 Width = 7215 End End End Attribute VB_Name = "Form1" Attribute VB_GlobalNameSpace = false Attribute VB_Creatable = false Attribute VB_PredeclaredId = true Attribute VB_Exposed = false private Sub ScrollPicBox(picSource as PictureBox, picContain as PictureBox, picTemp as PictureBox, Fit as Integer, HScroll1 as HScrollBar, VScroll1 as VScrollBar) Dim Hgt as Integer, Wdth as Integer, CopyMode as Long Dim TopCorner as Integer, LeftCorner as Integer Dim SC as Integer, LC as Integer Dim X as Long CopyMode = &HCC0020 If Fit = 0 then picSource.Picture = picTemp.Image else Hgt = picTemp.Height Wdth = picTemp.Width If Hgt > picContain.Height And Wdth > picContain.Width then If Hgt / picContain.Height > Wdth / picContain.Width then Wdth = Wdth * picContain.Height / Hgt Hgt = picContain.Height else Hgt = Hgt * picContain.Width / Wdth Wdth = picContain.Width End If else If Hgt > picContain.Height then Wdth = Wdth * picContain.Height / Hgt Hgt = picContain.Height else If Wdth > picContain.Width then Hgt = Hgt * picContain.Width / Wdth Wdth = picContain.Width End If End If End If picSource.Height = Hgt picSource.Width = Wdth picSource.PaintPicture picTemp.Image, 0, 0, Wdth, Hgt, 0, 0, picTemp.Width, picTemp.Height, CopyMode End If TopCorner = (picContain.Height - picSource.Height) / 2 If TopCorner < 0 then TopCorner = 0 picSource.Top = TopCorner LeftCorner = (picContain.Width - picSource.Width) / 2 If LeftCorner < 0 then LeftCorner = 0 picSource.Left = LeftCorner If picSource.Width > picContain.Width then HScroll1.Visible = true HScroll1.Max = picSource.Width - picContain.Width SC = HScroll1.Max * 0.01 If SC < 1 then SC = 1 HScroll1.SmallChange = SC LC = HScroll1.Max * 0.1 If LC < 1 then LC = 1 HScroll1.LargeChange = LC else HScroll1.Visible = false End If If picSource.Height > picContain.Height then VScroll1.Visible = true VScroll1.Max = picSource.Height - picContain.Height SC = VScroll1.Max * 0.01 If SC < 1 then SC = 1 VScroll1.SmallChange = SC LC = VScroll1.Max * 0.1 If LC < 1 then LC = 1 VScroll1.LargeChange = LC else VScroll1.Visible = false End If End Sub private Sub Check1_Click() ScrollPicBox Picture2, Picture1, Picture3, Check1.Value, HScroll1, VScroll1 End Sub private Sub VScroll1_Change() Picture2.Top = -VScroll1.Value End Sub private Sub HScroll1_Change() Picture2.Left = -HScroll1.Value End Sub codeguru.com
Copyright Internet.com Inc., All Rights Reserved. |