Click to See Complete Forum and Search --> : Need help with DCs...
Hi all.
I seem to be having some trouble with DCs.
How can I create a compatible DC of a picturebox? Can anyone bump in a little code, please? I can't seem to make this work.
By the way, maybe its just that I don't understand DCs correctly: I have an app which uses 4 picboxes. 3 of them are just used as buffers I use to Bitblit into the main Picturebox (the only visible one). Can I use DCs for the buffer picboxes instead? Shouldn't that make my app faster and lighter weight?
Thanks for your help, which is gretly needed!
kedaman
Oct 29th, 2000, 03:21 PM
Shouldn't be hard to do
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
YourDC = CreateCompatibleDC(picture1.hdc)
Thanks man, but I need a little more info:
I entered the code you just gave me, but then can the DC is just a long variable; I can't type YourDC.Scalewidth and YourDC.ScaleHeight and so on...
Even though applying GDI commands works, how do I modify the properties of the DC? Do I have to delete it and recreate it everytime the picturebox will get resized?
Thanks for replying.:D
kedaman
Oct 29th, 2000, 06:18 PM
Eh, the DC doesn't have those properties, it's the bitmap that has them you might want to attach a bitmap you create with Createcompatiblebitmap, using Selectobject.
hbitmap = CreateCompatibleBitmap(Form1.hdc, 100, 100) 'creates a bitmap with dimensions 100X100
SelectObject Yourdc, hbitmap
'remember to delete your DC's later before you unload your app:
DeleteDC Yourdc
DeleteObject hbitmap
I'll try this.
Thanks again!
It appears to work fine.
Thanks again, man.
MoMad
Oct 30th, 2000, 11:35 AM
hey, i have a similar question, but this question is not about dc and stuff....
I am trying to make a picture box duplicate.....
I currently know of two methods for duplicateing the picturebox and i am looking for a better way to dupe it...
method 1:
(at design time)
create an array of 10 pictures and stack them on top of each other and evrytime some one presses the "duplicate" button, one will just move down... and so on... (not too smooth because after 10, there will be no more...)
method 2:
(at design-time)
i will create an imagebox as follows:
Object: picLetters()
Property: Index
Value/Setting: 0 to 10
and then the do the same as method 1... note that the value/setting for Index property is a constant 0 to 10 and not dynamic...
Basically I want to be able to do method 2 at runtime instead of design time...
Example: (but doesnt work)
Private Sub Command1_Click()
Dim tempTxt As String
Dim textLen, i As Integer
Dim picLetters() As PictureBox
tempTxt = LCase(Text1.Text) 'the name
textLen = Len(tempTxt) 'length of the name
ReDim picLetters(0 To textLen) As PictureBox
For i = 0 To textLen
''get an image for each letter of the name; "block_[letter].gif"
picLetters(i) = LoadPicture(App.Path & "/images/block_" & Mid(tempTxt, i + 1, 1) & ".gif")
picLetters(i).Top = picLetters(i - 1).Top + 1000 'move picBox 1000 units below previous picBox
Next i
End Function
can anyone please help?
Thank you.
Add this code:
'Declaration
Private Picboxes() as PictureBox1
Redim Preserve Picboxes(0 to textlen)
For i = 0 to textlen
Set Picboxes(i) = New PictureBox1
Picboxes(i).top = whereeveryouwant
Picboxes(i).left = whereeveryouwant
'
'
'....your code...
'
'
next
Picturebox1 is an existing picturebox in your form. It will be copied as run time for every:
Set Picboxes(i) = New PictureBox1
That will create an array of pictureboxes . You should be able to apply the code you typed in your thread.
Good luck!
Forget about the whole "Redim Preserve" statement, I didn't see you already had it in your code.
The code I've typed earlier is totally wrong. Ignore it. It works greate with forms, but not with pictureboxes.
Sorry for the mistake....
MoMad
Oct 31st, 2000, 03:33 PM
hey thanks everyone, I finally got it it to work... my code just needed to 'load' the image boxes instead of trying to create new ones since they were on an array.
anyways, its working now... so thanks to evryone that helped.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.