Re: redraw pictureboxes in image????

Tech-Archive recommends: Speed Up your PC by fixing your registry



On 16 okt, 08:58, "Mike Williams" <mi...@xxxxxxxxxxxxxxxxx> wrote:
"Co" <vonclausow...@xxxxxxxxx> wrote in message

news:1192481474.485670.219180@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

(1) I have an Image, two pictureboxes and two textboxes on
a form. In the image I draw the pictureboxes and labels. The
left picturebox (sPrnt) is 600x600 and . . .
(2) I will try to make this understandable for you. I have two
records from a table which I want to compare. Then two icons
are displayed in an Image. They stand for the records. One icon
is large, the other one small. The large one is the Target record.
But I want to be able to switch the target record record . . .

Actually all that code you just posted doesn't really help me at all. In
fact it makes it more confusing because it includes all sorts of database
stuff that appears to be querying databases that I do not have at this end.
Also your code wraps very badly, with the line lengths being far too long
and it causes half of the code to appear in red when I paste it in at this
end. And you haven't answered the questions I asked in my previous response,
about the ScaleMode and other things.

Also, you have mentioned a few times that you are drawing stuff into the
Image Control, whereas in fact your code is of course doing no such thing.
It is merely placing some picture boxes and text boxes *on top of* the Image
Control. I assume that you actually realise that?

One other thing that caused me confusion until I sorted it out is the fact
that you mention "I want to click the icon on the left", whereas both icons
(if that is what you mean by the Picture Boxes) are displayed on top of each
other when I finally get your code to work. That's because you are setting
the size of the picture boxes *after* setting their position in accordance
with their size, whereas of course you should be setting the size *first*
(as in the modified code below). When I asked you to post code that actually
works I meant code that I could simply paste into a blank VB Form at this
end together with instructions as to what controls I should place on that
Form. All the database stuff you included prevents me from doing that and
the fact that dozens of lines of code appeared in red because of the "wrap"
problem did not help either.

Anyway, all that having been said, here's what I've condensed your code down
to as a sort of "test bed" program. Paste it into a VB Form containing two
Command Buttons, two Picture Boxes and one Image Control and run it. Is that
something like the display tyou are expecting at your end? If so, then what
do you want to do with it regarding this "switching" business. By the way,
your code is not currently setting the height of the text boxes and it is
also causing the text to fail to fully display because (at least at this
end) the picture Box is not quite wide enough for the text it contains.
That's because (at least on my system) a VB Text Box that has a Border at
design time (in the VB IDE) places its text one pixel to the right of the
left edge of the available width, and when your code sets it to Border = 0
at run time it still does so, resulting in the rightmost pixel of the text
failing to display if the TextBox Width is set equal to the width of the
text string (where the rightmost character is one that actually fills right
up to the edge of its cell, such as the character "m"). A Text Box that is
set to borderless at design time (in the IDE) does not behave like that, and
it displays its text starting at the very leftmost pixel and so all of it
fits properly. I'm not sure whether that is the bahaviour on all systems
(perhaps you and others here might like to check it out?) and it can
probably be fixed by sending the appropriate message to it, but in the
meantime perhaps you might like to set the width of the TextBox to the
equivalent of one pixel wider than the text it is required to contain.

Firstly here is some test code to check out the TextBox horizontal alignment
thing I mentioned if you (and anyone else?) would care to try it out for me.
Paste the code into a VB Form containing two TextBoxes and one Command
Button. Set the Borderstyle of Text1 to borderless in the IDE properties
window but leave Text2 with its normal fixed single border. Run the code and
click the button and carefully examine the text in both boxes:

Private Sub Command1_Click()
' set Text1 Border to none at design time
Dim s1 As String, p As Single
s1 = "Rum"
p = Me.TextWidth(s1)
Text2.BorderStyle = vbBSNone
Text1.Width = p: Text1.BackColor = vbCyan
Text2.Width = p: Text2.BackColor = vbCyan
Text1.Text = s1
Text2.Text = s1
End Sub

. . . and here (for Marco) is the testbed code for the Images and Picture
Box stuff. Paste it into a VB Form containing two Picture Boxes, two Command
Buttons and an Image Control. Amend the two relevant lines in the
Command1_Click event so that they refer to two pictures that exist on your
own system.

Option Explicit

Private Sub DisplayPictureBox(ByVal sImage As String, _
NewImage As StdPicture, sLink As String, _
sToolTip As String)
Dim PB As PictureBox
Dim TX As TextBox
Select Case sImage
Case "sPrnt"
Set PB = Picture1
Set TX = Text1
With PB
.BorderStyle = 0
.Visible = True
.AutoRedraw = True
.Width = 600
.Height = 600
.Left = Image1.Left + (Image1.Width / 4)
.Top = Image1.Top + (Image1.Height / 2) - .Height
.BackColor = vbWhite
.PaintPicture NewImage, 0, 0, .ScaleWidth, _
.ScaleHeight
.ToolTipText = sToolTip
End With
With TX
.Text = sLink
.BorderStyle = 0
.Width = Me.TextWidth(sLink)
.Left = PB.Left + (PB.Width \ 2) - (TX.Width \ 2)
.Top = PB.Top + 800
.Visible = True
.ForeColor = vbBlack
.BackColor = vbWhite
End With
Case "sChld"
Set PB = Picture2
Set TX = Text2
With PB
.BorderStyle = 0
.Visible = True
.AutoRedraw = True
.Width = 400
.Height = 400
.Left = Image1.Left + ((Image1.Width / 4) * 3) _
- .Width
.Top = Image1.Top + (Image1.Height / 2) - .Height
.BackColor = vbWhite
.PaintPicture NewImage, 0, 0, .ScaleWidth, _
.ScaleHeight
.ToolTipText = sToolTip
End With
With TX
.Text = sLink
.Width = Me.TextWidth(sLink)
.Left = PB.Left + (PB.Width \ 2) - (TX.Width \ 2)
.Top = PB.Top + 600
.Visible = True
.BorderStyle = 0
.ForeColor = vbBlack
.BackColor = vbWhite
End With
End Select
End Sub

Private Sub Form_Load()
Me.ScaleMode = vbTwips
Dim p1 As StdPicture, s1 As String, s2 As String
' amend the following two lines to point to pictures
' that exist on your own system
s1 = "c:\Temp\flower1.jpg" ' picture for Image Control
s2 = "c:\temp\Tulips.jpg" ' picture for pic boxes
Image1.Move 0, 0, 4000, 4000
Image1.Stretch = True
Image1.Picture = LoadPicture(s1)
Set p1 = LoadPicture(s2)
DisplayPictureBox "sPrnt", p1, "Rum", "Coke"
DisplayPictureBox "sChld", p1, "Whisky", "Gin"
End Sub

Mike,

I hope I read everything carefully.
I tried the code and it runs. The textbox thing I don't notice since
my textboxes
are already set to borderless.
When you now have this form with the image and the two pictureboxes
inside I want
to click on the left (big picture) and then it becomes small (like the
right one) at the
same time the small one gets big. Now the user has switched between
Parent and child
record. So the Child gets merged with the Parent record. Without
having clicked the left
one would be the Parent and on the right the Child would have been
merged with the Parent
on the left.

Marco

.


Quantcast