Results 1 to 7 of 7

Thread: drawing text??

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2002
    Posts
    39

    Question drawing text??

    i want to put some text over an image, in vb6 i would have just used a label, but labels in .net cant have proper transparency for some reason, i have serched this forum and the only solution is to draw the text on, i have used the following code but the text appers with sight colour round the side the colour changes depending on what part of the text it is. i have seen this happen below with xp's true type and transparency, is this whats causing it and can it be stopped??

    Code:
    Dim g As Graphics = PictureBox1.CreateGraphics
    Dim mybrush As New SolidBrush(Color.Black)
    Dim myFont As New Font("Microsoft Sans Serif", 8.5, FontStyle.Regular, GraphicsUnit.Point, 5)
    g.DrawString(message, myFont, mybrush, 10, 30)
    g.DrawString(stext, myFont, mybrush, 10, 40)
    Last edited by spike232; Jul 6th, 2002 at 11:04 AM.

  2. #2
    Addicted Member
    Join Date
    Dec 2000
    Location
    Novosibirsk, Russia
    Posts
    170

    Answer

    I think the Image control or whatever it's called now should have a property exposing its device context as an object, like Canvas or something. This canvas should have appropriate methods for outputting text. Otherwise, you can declare TextOut API and draw text using Image1.hDc like we used to do in VB6. You will need to do this at appropriate time so that the image is drawn first, so you will need to do this in Refresh event of the Image or subclass the image control and intercept WM_PAINT message, painting here.

    Labels here are really a waste of resources. I heard that there is a StaticText control, try it, maybe it has transparency capabilities.

    Best,
    Stanislav
    Stanislav Okhvat
    [email protected]
    VB, PHP

  3. #3
    Addicted Member
    Join Date
    Dec 2000
    Location
    Novosibirsk, Russia
    Posts
    170
    I haven't really read your question to the end, sorry. What are you saying about transparency issues in XP? Please provide all the code you're using right now, maybe I can help.

    Best,
    Stanislav
    Stanislav Okhvat
    [email protected]
    VB, PHP

  4. #4

    Thread Starter
    Member
    Join Date
    Jul 2002
    Posts
    39
    all the code is above, the onely other thing is a picture box added to the form.

    when the text is drawn their is a slight colourd outline (usualy kind of rainbow colourd)

    the text also looks bold when it is not

    i have seen simalar things occur with xp's true type when antiatlesing text on a transparent background, but i do not know if this is the cause

  5. #5
    Addicted Member
    Join Date
    Dec 2000
    Location
    Novosibirsk, Russia
    Posts
    170
    Hi again,
    You should really try to use regular API TextOut or DrawText function. The text is always drawn with transparent background. All you need to do is use SelectObject to select a font handle, set text color and use one of the above functions. If the rainbow color around the text is gone, you will need to consult MSDN on Graphics.DrawString method. Also, the text functions do not need a brush - at least in normal Windows API - instead you use SetTextColor function on the device context. I am not familiar with the NET framework that much, but I think DrawString should have an additional parameter for text color or Graphics object has SetTextColor or similar method for specifying text color.

    I also suspect there should be a different method for drawing text since Windows API has at least three different functions for drawing text and all of them accept different parameters (TextOut, TabbedTextOut, DrawText, DrawTextEx).

    Hope this helps,
    Stanislav
    Stanislav Okhvat
    [email protected]
    VB, PHP

  6. #6
    Addicted Member
    Join Date
    Dec 2000
    Location
    Novosibirsk, Russia
    Posts
    170
    Another thing,

    I just looked in API-Guide and here's the NET example for DrawText that they provide:

    Imports System
    Imports System.Windows.Forms
    Imports System.Drawing
    Public Module modmain
    Sub Main()
    'The KPD-Team 2001
    'URL: http://www.allapi.net/dotnet/
    'E-Mail: [email protected]
    Dim theForm as MainForm = new MainForm()
    theForm.Size = new Size(500, 350)
    theForm.Text = "Visual Basic.NET"
    theForm.ShowDialog()
    End Sub
    End Module
    Public Class MainForm
    Inherits Form
    Protected Overrides Sub OnPaint(e as PaintEventArgs)
    e.Graphics.DrawString("Hello World!", new Font("Verdana", 16), new SolidBrush(Color.Red), new PointF(10, 10))
    End Sub
    End Class

    Hope it helps,
    Stanislav
    Stanislav Okhvat
    [email protected]
    VB, PHP

  7. #7

    Thread Starter
    Member
    Join Date
    Jul 2002
    Posts
    39
    that works great, thanks
    Last edited by spike232; Jul 10th, 2002 at 06:42 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width