[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Write text in a Picture Box

Posted on 2012-09-03
2
Medium Priority
?
1,832 Views
Last Modified: 2012-09-05
I have numeric keyboard, and i have a picture with a key background. I need to show a "label" for each numeric key. For ex. all keys (pictures) has the same image (background) and i need write in each one the correspondent number.
0
Comment
Question by:rflorencio
2 Comments
 
LVL 30

Assisted Solution

by:Randy Downs
Randy Downs earned 400 total points
ID: 38361382
Try this

http://www.tek-tips.com/viewthread.cfm?qid=1475823

    Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint

        Dim t As String = "This is some text"
        Dim f As Font = New Font("Arial", 12, FontStyle.Regular)
        Dim g As Graphics = e.Graphics
        Dim StringSize As SizeF = g.MeasureString(t, f)
        Dim StringTop As Single = CSng((PictureBox1.Height / 2) - (StringSize.Height / 2))
        Dim StringLeft As Single = CSng((PictureBox1.Width / 2) - (StringSize.Width / 2))
        g.DrawString(t, f, Brushes.Aquamarine, StringLeft, StringTop)

    End Sub

    Private Sub PictureBox1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox1.Resize

        PictureBox1.Invalidate()

    End Sub

Open in new window

0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 1600 total points
ID: 38361554
This will divide the PictureBox into a 3x4 grid and draw the digits centered in each cell:
Public Class Form1

    Private Sub PictureBox1_Paint(sender As System.Object, e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
        Dim digits(,) As String = {{"7", "8", "9"}, {"4", "5", "6"}, {"1", "2", "3"}, {"", "0", "."}}
        Dim width As Integer = PictureBox1.Size.Width / 3
        Dim height As Integer = PictureBox1.Size.Height / 4
        Dim SF As New StringFormat
        SF.Alignment = StringAlignment.Center
        SF.LineAlignment = StringAlignment.Center
        For row As Integer = 0 To 3
            For col As Integer = 0 To 2
                Dim rc As New Rectangle(col * width, row * height, width, height)
                e.Graphics.DrawString(digits(row, col), Me.Font, Brushes.Black, rc, SF)
            Next
        Next
    End Sub

    Private Sub PictureBox1_Resize(sender As Object, e As System.EventArgs) Handles PictureBox1.Resize
        PictureBox1.Refresh()
    End Sub

End Class

Open in new window


*As Number-1 has done, you may want to create your own font and use that instead of "Me.Font".
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month18 days, 4 hours left to enroll

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question