how to call bmp image for keypress event

Total Post:31

Points:217

VB.Net 
 1616  View(s)
Ratings:
Rate this:
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..                                                                                                                                                    
  1. Re: how to call bmp image for keypress event

    Why you calling images on the keypress event of textbox?

      Modified On Apr-25-2015 02:23:03 AM
  1. Re: how to call bmp image for keypress event

    There is no problem in your function, you only need to check specified file exist at the given path (Application.StartupPath) .
     and also you can only able to set one image in picture box at a time

  1. Re: how to call bmp image for keypress event

    hai john..


                 Because, instead of calling normal font for my application i need to call bitmap images of alphabets numbers and special characters.. so whenever i press my keys the relavent alphabet should place in my picturebox..

  1. Re: how to call bmp image for keypress event

    hai sunil..


           The specified file exists in my application start up path.. but as u said i can place oly one image in my picturebox.. but i need to place multiple bmp images in my picturebox..
      how can I do it

  1. Re: how to call bmp image for keypress event

    You mean to say if someone has pressed A B C D then images of A B C D alphabets should be placed  in your picturebox or You want to store previously pressed alphabets images in your picturebox?

  1. Re: how to call bmp image for keypress event

    hai Jack..



         Yes I need like that.. if I pass ABCD as my input.. Then bmp images of ABCD should be displayed in my picturebox

  1. Re: how to call bmp image for keypress event

    Then do not place images on keypress event , use button click event to place images on your picture box.

  1. Re: how to call bmp image for keypress event

    I just needed when i press the keys in textbox.. So how it wil be useful when i do with button click.. whenever i type in my textbox the images should be called..

      Modified On Apr-25-2015 03:04:07 AM
  1. Re: how to call bmp image for keypress event

    you can only able to set one image in picture box at a time.

  1. Re: how to call bmp image for keypress event

    Is there any other option to do so..

  1. Re: how to call bmp image for keypress event

    you can use imagelist control or dynamically create picturebox . On  textbox key press event create dynamic picturebox and set image to dynamically created picturebox according to keychar.

  1. Re: how to call bmp image for keypress event

    Okay.. I will try to do it.. 

    Thank you..

Answer

Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.