From: Webbiz on 10 Mar 2010 00:57 I'm still working on my graphics understanding but have a need to do something pretty quick for now. So I thought someone might tell me how to do this quickly. Here is my function that draws these RED DIAMONDS on my picturebox. Private Sub DrawFDDiamonds(pic As PictureBox, x As Long, y As Long) Dim p1 As POINTAPI, x1 As Long, y1 As Long Dim oldPen As Long, oldBrush As Long Dim pen1 As Long Dim brush1 As Long Dim FDDiamond(1 To 4) As POINTAPI FDDiamond(1).x = 0: FDDiamond(1).y = 0 ' start point FDDiamond(2).x = -8: FDDiamond(2).y = 15 FDDiamond(3).x = 0: FDDiamond(3).y = 30 FDDiamond(4).x = 8: FDDiamond(4).y = 15 ' pen1 = CreatePen(PS_SOLID, 1, rgb(160, 0, 0)) brush1 = CreateSolidBrush(rgb(250, 80, 80)) x1 = pic.ScaleX(x - pic.scaleleft, pic.ScaleMode, vbPixels) y1 = pic.ScaleY(y - pic.ScaleTop, pic.ScaleMode, vbPixels) SetWindowOrgEx pic.hdc, -x1, -y1, p1 ' set origin ' oldPen = SelectObject(pic.hdc, pen1) oldBrush = SelectObject(pic.hdc, brush1) Polygon pic.hdc, FDDiamond(1), 4 SetWindowOrgEx pic.hdc, p1.x, p1.y, p1 ' restore original origin ' SelectObject pic.hdc, oldPen SelectObject pic.hdc, oldBrush End Sub I want to include a WHITE text character inside the red diamond. What line or lines can I quickly add to this function that will do that? Let's say that my declaration is... Private Sub DrawFDDiamonds(pic As PictureBox, x As Long, y As Long, Optional Char as String) So whatever is passed as "Char" is printed in the center of the red diamond in white. Appreciate it. Webbiz
From: Nobody on 10 Mar 2010 01:29 "Webbiz" <nospam(a)noway.com> wrote in message news:tucep5hkol9vsgu9snque6agn631k3ak7u(a)4ax.com... > I want to include a WHITE text character inside the red diamond. What > line or lines can I quickly add to this function that will do that? pic.CurrentX = 100 pic.CurrentY = 100 pic.Print "A"; If using the API, use TextOut(), or ExtTextOut().
From: Mike Williams on 10 Mar 2010 02:06 "Webbiz" <nospam(a)noway.com> wrote in message news:tucep5hkol9vsgu9snque6agn631k3ak7u(a)4ax.com... > I'm still working on my graphics understanding but have > a need to do something pretty quick for now. So I thought > someone might tell me how to do this quickly. > Here is my function that draws these RED DIAMONDS > on my picturebox [code snipped]. > I want to include a WHITE text character inside the red > diamond. What line or lines can I quickly add to this > function that will do that? Here's a quick ten minute bash at it, which is a bit rough and ready at the moment but which should be okay for the time being, although it does of course need a little more work if it is to take everything into account. As it stands the code assumes that you have left the PictureBox at its default setting of FontTransparent True and that you will be able to add code yourself to set the font name and to set it to a suitable size, although extra code could of course be added to do those things. It is also a bit "rough and ready" in that it assumes the actual glyph of the character you wish to print is approximately centred within its own character cell in the font you are using, which is not always the case, but again you could add code to check the "black box" details of the character glyph so that you could position it correctly within your diamond shape whether it is centred within its cell or not. Those things can be added if necessary, although you might find that it is suitable for your needs as it stands. Anyway, here's the code you need to add. It should be inserted in your existing code immediately after the line that calls the Polygon function and immediately before the line that uses SetWindowOrgEx to restore the origin to its original condition. You will of course also need to add the appropriate declarations etc (DrawText, SetTextColor, the RECT Type and the three constants) and perhaps a little bit of code to check that the optional Char parameter that your modified function will use is actually present. Dim r1 As RECT, oldColor As Long r1.Left = FDDiamond(2).x r1.Right = FDDiamond(4).x + 1 r1.Top = FDDiamond(1).y r1.Bottom = FDDiamond(3).y + 1 oldColor = SetTextColor(pic.hdc, vbWhite) DrawText pic.hdc, Char, Len(Char), r1, DT_SINGLELINE _ Or DT_CENTER Or DT_VCENTER SetTextColor pic.hdc, oldColor Mike
From: Webbiz on 10 Mar 2010 03:31 On Wed, 10 Mar 2010 07:06:08 -0000, "Mike Williams" <Mike(a)WhiskyAndCoke.com> wrote: >"Webbiz" <nospam(a)noway.com> wrote in message >news:tucep5hkol9vsgu9snque6agn631k3ak7u(a)4ax.com... > >> I'm still working on my graphics understanding but have >> a need to do something pretty quick for now. So I thought >> someone might tell me how to do this quickly. >> Here is my function that draws these RED DIAMONDS >> on my picturebox [code snipped]. >> I want to include a WHITE text character inside the red >> diamond. What line or lines can I quickly add to this >> function that will do that? > >Here's a quick ten minute bash at it, which is a bit rough and ready at the >moment but which should be okay for the time being, although it does of >course need a little more work if it is to take everything into account. As >it stands the code assumes that you have left the PictureBox at its default >setting of FontTransparent True and that you will be able to add code >yourself to set the font name and to set it to a suitable size, although >extra code could of course be added to do those things. It is also a bit >"rough and ready" in that it assumes the actual glyph of the character you >wish to print is approximately centred within its own character cell in the >font you are using, which is not always the case, but again you could add >code to check the "black box" details of the character glyph so that you >could position it correctly within your diamond shape whether it is centred >within its cell or not. Those things can be added if necessary, although you >might find that it is suitable for your needs as it stands. Anyway, here's >the code you need to add. It should be inserted in your existing code >immediately after the line that calls the Polygon function and immediately >before the line that uses SetWindowOrgEx to restore the origin to its >original condition. You will of course also need to add the appropriate >declarations etc (DrawText, SetTextColor, the RECT Type and the three >constants) and perhaps a little bit of code to check that the optional Char >parameter that your modified function will use is actually present. > >Dim r1 As RECT, oldColor As Long >r1.Left = FDDiamond(2).x >r1.Right = FDDiamond(4).x + 1 >r1.Top = FDDiamond(1).y >r1.Bottom = FDDiamond(3).y + 1 >oldColor = SetTextColor(pic.hdc, vbWhite) >DrawText pic.hdc, Char, Len(Char), r1, DT_SINGLELINE _ > Or DT_CENTER Or DT_VCENTER >SetTextColor pic.hdc, oldColor > >Mike > Thanks Mike. I went this route and it seems to be working. If sChar <> "" Then hFont = CreateFont(18, 0, 0, 0, 400, 0, 0, 0, 0, 0, 0, 0, 0, "Arial") hOldFont = SelectObject(pic.hdc, hFont) iRet = SetTextColor(pic.hdc, rgb(255, 255, 255)) iRet = TextOut(pic.hdc, -4, 6, sChar, 1) iRet = DeleteObject(hFont) End If I don't know if what I did might have consequences depending on screen resolutions on other systems and such. On my system the font size was perfect within the size of the diamonds drawn, white and lightly bold. I hard coded the x,y of TextOut in respects to my FDDiamond coordinates. Do you see anything out of whack in this? Thanks. Webbiz
From: Mike Williams on 10 Mar 2010 04:32
"Webbiz" <nospam(a)noway.com> wrote in message news:21mep5h4i9surhklf0s3i8s3mj7q230ark(a)4ax.com... > Thanks Mike. > I went this route and it seems to be working. > If sChar <> "" Then > hFont = CreateFont(18, 0, 0, 0, 400, 0, 0, 0, 0, 0, 0, 0, 0, > "Arial") > hOldFont = SelectObject(pic.hdc, hFont) > iRet = SetTextColor(pic.hdc, rgb(255, 255, 255)) > iRet = TextOut(pic.hdc, -4, 6, sChar, 1) > iRet = DeleteObject(hFont) > End If > I don't know if what I did might have consequences depending > on screen resolutions on other systems and such. On my system > the font size was perfect within the size of the diamonds drawn, > white and lightly bold. I hard coded the x,y of TextOut in > respects to my FDDiamond coordinates. I can only give it a quick glance because I'm off for a little break in Yorkshire and The Lake Distrcit in an hour or so, but it looks okay. You're setting the font size in pixels rather than points, so it should match reasonably well with the pixel size of your diamond shape on all systems at all dpi settings. The only problem you might have is if you change the font name or font size, or the size of your diamonds, because you are setting the position of the top left corner of the character cell relative to the diamond wheras the code I posted centralises the character regardless of its point (or pixel) size. Otherwise it looks okay though. Mike |