Visualizzazione dei risultati da 1 a 3 su 3
  1. #1
    Utente di HTML.it L'avatar di x69asterix
    Registrato dal
    Jan 2005
    Messaggi
    1,303

    [VB.NET]Scrivere del testo su Picturebox

    ragazzi come si fà a scrivere del testo su un' immagine caricata in un controllo Picturebox?

  2. #2
    Utente di HTML.it
    Registrato dal
    Jan 2007
    Messaggi
    172
    Dim Graphics As Graphics = PictureBox1.CreateGraphics
    Graphics.DrawString("Hello000000000000000!", Me.Font, Brushes.Red, 10, 10)

  3. #3
    Utente di HTML.it L'avatar di x69asterix
    Registrato dal
    Jan 2005
    Messaggi
    1,303
    ciao io provato quanto segue, e funziona abbastanza bene, solo che non capisco come devo formattare il testo in modo che la scritta sia multilinea.
    codice:
    Imports System.Drawing.Drawing2D
    Public Class Form1
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim textSize As SizeF
            Dim g As Graphics
            Dim myBackBrush As Brush = Brushes.Gray
            Dim myForeBrush As Brush = Brushes.Black
            Dim myFont As New Font("Times New Roman", Me.nudFontSize.Value, FontStyle.Regular)
            Dim myState As GraphicsState ' Used to store current state of Graphics
            Dim xLocation, yLocation As Single ' Used for the location
            Dim textHeight As Single
    
    
            g = picDemoArea.CreateGraphics()
            g.Clear(Color.White)
    
            textSize = g.MeasureString(Me.txtShortText.Text, myFont)
            xLocation = (picDemoArea.Width - textSize.Width) / 2
            yLocation = (picDemoArea.Height - textSize.Height) / 2
            g.TranslateTransform(xLocation, yLocation)
    
            Dim lineAscent As Integer
            Dim lineSpacing As Integer
            Dim lineHeight As Single
    
            lineAscent = myFont.FontFamily.GetCellAscent(myFont.Style)
            lineSpacing = myFont.FontFamily.GetLineSpacing(myFont.Style)
            lineHeight = myFont.GetHeight(g)
            textHeight = lineHeight * lineAscent / lineSpacing
            myState = g.Save()
    
            
            g.ScaleTransform(1, -1.0F)
            g.DrawString(txtShortText.Text, myFont, Brushes.Lavender, 0, -textHeight)
            g.Restore(myState)
    
            g.DrawString(txtShortText.Text, myFont, Brushes.DarkMagenta, 0, -textHeight)
        End Sub
    ho provato il tuo codice , anche li non capisco come scrivere in modalità multilinea.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.