help me plz with this code

marwanz_102
01-24-2005, 02:20 PM
hi
i need help with the following prog which does something called smith chart
(try it), i want to clear anything that is outside the red circle
what should i do?


Private Sub Command1_Click()
Dim x As Double
Dim y As Double
Dim r As Double
Dim d As Double
Dim t As Double
Dim m As Double

Form2.ScaleHeight = 354
Form2.ScaleWidth = 411
Form2.ScaleMode = pixel

x = 411 / 354
x = 1.1 * x
Form2.Scale (-x, 1.1)-(x, -1.1)
Form2.Show
r = 15
t = 10
For i = 0 To 8
m = 1 / t
Form2.Circle (1, m), m
Form2.Circle (1, -m), m
t = t / 2

Form2.Circle (0, 0), 1, &HFF&
y = 1 / (1 + r)
d = r / (1 + r)
Form2.Circle (d, 0), y
r = r / 2
Next i


End Sub


thanks

noi_max
01-24-2005, 03:01 PM
Here's an idea, but it needs to be worked out.

This may not be the solution you're after... but here goes.

Use a picbox instead of a form. Then, set a region for the picbox relative to the circle you've drawn.

The problem is, the CreateEllipticRgn creates a region based on a bounding rectangle, and your circle is created by a center point and a radius.

The other api used would be the SetWindowRgn
This would 'crop' the picturebox in question to a round region.

I figured it might be easier to figure a way to crop the image to the circle, rather than try to erase what's around it.

Does that sound right?

Anyway, just an idea...

passel
01-25-2005, 10:29 AM
Another possibility, which I can't try now, that might work if you drew your Red Circle last ((since it appears to
be a constant radius, it probably doesn't need to be inside the loop), and drawing it after the other
circles would make sure that it had a contiguous border), would be to do a floodfill (API call) at a point outside the
red circle, with red being the border color. That should wipeout everything outside the red circle, but
like I said, I can't try it at the moment.

Yet, another possibility, would be to simply create a mask to match your Radius 1 circle,
and apply the mask using bitblt with the appropriate Raster OP do clear the area outside the
circle. The mask and raster op will depend on whether you want the area outside cleared to
black or white, or some other color.

passel
01-25-2005, 05:26 PM
Ok, I'm home now so have access to VB.
I decided to give a try to the bitblt method.

But, rather than actually use bitblt decided to go with PaintPicture which is pretty much
a VB version of Stretchblt (but acts on stdPictures rather than DCs).
Another difference between Stretchblt and PaintPicture is that Stretchblt requires
values in pixels, whereas PaintPicture uses the Scale of the object.
That is another good reason for using PaintPicture because of your User Defined Scale.

I added a Picturebox to Form2. I turned off its border, set its Visible property
to False, and set its AutoRedraw property to True.

Then I modified your code like this.


Option Explicit

Private Sub Command1_Click()
Dim x As Double
Dim y As Double
Dim r As Double
Dim d As Double
Dim t As Double
Dim m As Double
Dim i As Integer
Form2.Cls
' Form2.ScaleHeight = 354 'All this has no effect since it is modifying the scale not the size
' Form2.ScaleWidth = 411 'of the picturebox. You change the scale again below, so this code is meaningless
' Form2.ScaleMode = vbPixels '<---note you had pixel here which was undefined

x = 411 / 354
x = 1.1 * x
Form2.Scale (-x, 1.1)-(x, -1.1)
Form2.Show
r = 15
t = 10
For i = 0 To 8
m = 1 / t
Form2.Circle (1, m), m
Form2.Circle (1, -m), m
t = t / 2

y = 1 / (1 + r)
d = r / (1 + r)
Form2.Circle (d, 0), y
r = r / 2
Next i
Form2.Circle (0, 0), 1, &HFF&
With Form2
'Set the picturebox to be the same size as the client area of the form.
Form2.Picture1.Move .ScaleLeft, .ScaleTop, .ScaleWidth, Abs(.ScaleHeight)
.Picture1.Cls 'clear any previous image in the picturebox
.Picture1.Scale (-x, 1.1)-(x, -1.1) 'set its scale to match the one in the form
.Picture1.FillStyle = vbSolid 'Draw a filled circle (fillcolor defaulted to black)
.Picture1.Circle (0, 0), 1, 0 'A black, filled circle of area to remain
.PaintPicture .Picture1.Image, .ScaleLeft, .ScaleTop, , , , , , , vbSrcPaint 'Or backcolor to area outside the circle
End With
End Sub


This code assumes the backcolor of your Form and the backcolor of the Picturebox are
the same, which they should be by default. If you changed the backcolor of the form,
then you should change the backcolor of the picturebox as well.

Caveat:
This works because you are using black lines in your drawing.
If your lines were of other colors then a black on white mask should be created and
another work area (picturebox) would be needed if you didn't want the area outside
the red circle to be white (or you could create the mask twice, black on white and
then white on your background color, and the second mask applied with the AND raster OP (vbSrcAnd)

noi_max
01-25-2005, 10:00 PM
Wow, that's cool.

I could add that after testing this I set the form's autoredraw property to True and it eliminated the little flicker I was getting as it was being rendered.

But I'm mostly posting to give kudos to passel for his cool solution :huh: :D

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum