Home > DeveloperSection > Forums > how to call bmp image for keypress event
Madhu Mitha
Madhu Mitha

Total Post:31

Points:217
Posted on    April-24-2015 10:54 PM

 .NET VB.Net 
Ratings:


 12 Reply(s)
 703  View(s)
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 textbox.
i have a sample code like

  1. Public Class Form1
  2.     Dim graph As Graphics
  3.     Dim g, g1 As System.Drawing.Graphics
  4.     Dim img As New Bitmap(144, 16)
  5.     Dim brush As New Drawing.SolidBrush(Color.Black)
  6.     Private Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.TextChanged
  7.         g1 = Graphics.FromImage(img)
  8.         PictureBox1.Image = img
  9.         ' to clear the bitmap
  10.         g1.Clear(Color.White)
  11.         'for drawsting function
  12.         g1.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
  13.         g1.TextRenderingHint = Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit
  14.         g1.CompositingQuality = Drawing2D.CompositingQuality.HighQuality
  15.         'to draw string
  16.         g1.DrawString(TextBox1.Text, TextBox1.Font, Brushes.Black, 0, 0)
  17.         PictureBox1.SizeMode = PictureBoxSizeMode.Normal
  18.         PictureBox1.Refresh()
  19.     End Sub
  20. End Class
  21.  
i have a seperate code for keypress event as

  1. Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
  2.         Dim file As String = String.Format("{0}\{1}.bmp", Application.StartupPath, e.KeyChar.ToString)
  3.  
  4.         If System.IO.File.Exists(file) Then
  5.  
  6.             PictureBox1.ImageLocation = file
  7.  
  8.         Else
  9.  
  10.             PictureBox1.ImageLocation = String.Empty
  11.  
  12.         End If
  13.     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..                                                                                                                                                    


John Smith

Total Post:102

Points:720
Posted on    April-25-2015 2:08 AM

Why you calling images on the keypress event of textbox?


Modified On Apr-25-2015 02:23:03 AM

Sunil Singh
Sunil Singh

Total Post:11

Points:77
Posted on    April-25-2015 2:19 AM

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

Madhu Mitha
Madhu Mitha

Total Post:31

Points:217
Posted on    April-25-2015 2:39 AM

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..

Madhu Mitha
Madhu Mitha

Total Post:31

Points:217
Posted on    April-25-2015 2:41 AM

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


Jack C
Jack C

Total Post:13

Points:91
Posted on    April-25-2015 2:49 AM

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?

Madhu Mitha
Madhu Mitha

Total Post:31

Points:217
Posted on    April-25-2015 2:51 AM

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

Jack C
Jack C

Total Post:13

Points:91
Posted on    April-25-2015 2:59 AM

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

Madhu Mitha
Madhu Mitha

Total Post:31

Points:217
Posted on    April-25-2015 3:02 AM

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

Sunil Singh
Sunil Singh

Total Post:11

Points:77
Posted on    April-25-2015 3:28 AM

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

Madhu Mitha
Madhu Mitha

Total Post:31

Points:217
Posted on    April-25-2015 4:33 AM

Is there any other option to do so..

Sunil Singh
Sunil Singh

Total Post:11

Points:77
Posted on    April-25-2015 5:06 AM

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.

Madhu Mitha
Madhu Mitha

Total Post:31

Points:217
Posted on    April-25-2015 5:34 AM

Okay.. I will try to do it.. 
Thank you..

Don't want to miss updates? Please click the below button!

Follow MindStick