forum

Home / DeveloperSection / Forums / how to call bmp image for keypress event

how to call bmp image for keypress event

Madhu Mitha 2072 24-Apr-2015
hai..

I need something to do where I stored bmp images for alphabets and numbers and i call call those images when i type it in a textbox.
I have a sample code like

      Public Class Form1
          Dim graph As Graphics
          Dim g, g1 As System.Drawing.Graphics
          Dim img As New Bitmap(144, 16)
          Dim brush As New Drawing.SolidBrush(Color.Black)
          Private Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.TextChanged
              g1 = Graphics.FromImage(img)
              PictureBox1.Image = img
              ' to clear the bitmap
              g1.Clear(Color.White)
              'for drawsting function
              g1.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
              g1.TextRenderingHint = Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit
              g1.CompositingQuality = Drawing2D.CompositingQuality.HighQuality
              'to draw string
              g1.DrawString(TextBox1.Text, TextBox1.Font, Brushes.Black, 0, 0)
              PictureBox1.SizeMode = PictureBoxSizeMode.Normal
              PictureBox1.Refresh()
          End Sub
      End Class

       

      I have a seperate code for keypress event as

          Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
                  Dim file As String = String.Format("{0}\{1}.bmp", Application.StartupPath, e.KeyChar.ToString)
           
                  If System.IO.File.Exists(file) Then
           
                      PictureBox1.ImageLocation = file
           
                  Else
           
                      PictureBox1.ImageLocation = String.Empty
           
                  End If
              End Sub
          but i could call these functions to my program
          and aslo i could not call more than one bmp image in mypicturebox..
          can any one help me..                                                                                                                                                    

          Updated on 25-Apr-2015

          Can you answer this question?


          Answer

          12 Answers

          Liked By