Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
3K views

How To Add Picture To A Command Button in Visual Basic

This document provides instructions for adding a picture to a command button in Visual Basic. It outlines 9 steps: 1) launching Visual Basic, 2) creating a new project, 3) drawing a command button on the form, 4) setting the button's caption, 5) browsing for an image file, 6) setting the button's style, 7) running the program, 8) returning to design mode, and 9) saving the project. The document also discusses using an image box control to display images and printing reports from Access databases using Automation in Visual Basic.

Uploaded by

mykeymar
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3K views

How To Add Picture To A Command Button in Visual Basic

This document provides instructions for adding a picture to a command button in Visual Basic. It outlines 9 steps: 1) launching Visual Basic, 2) creating a new project, 3) drawing a command button on the form, 4) setting the button's caption, 5) browsing for an image file, 6) setting the button's style, 7) running the program, 8) returning to design mode, and 9) saving the project. The document also discusses using an image box control to display images and printing reports from Access databases using Automation in Visual Basic.

Uploaded by

mykeymar
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

How to Add Picture to a Command Button in Visual Basic

By miasavc, eHow Member

VB command button with picture


User-Submitted Article

Command buttons in Visual Basic are objects used to execute commands once the user triggers an event such as
clicking, hovering the mouse over it, or pressing the "Tab" or "Enter" key. Most programmers only put captions in
command buttons when designing the program interface. But you can add a small picture or icon in the control itself
to make it more pleasing to the eye. Learn how to add picture to a command button control in Visual Basic by
following these steps.

Instructions

Things You'll Need:

 Computer
 Visual Basic software

1. 1

Launch Visual Basic program from your computer by clicking "Start > Programs > Microsoft Visual Studio >
Microsoft Visual Basic [version number]".

2. 2

Start a new standard exe project by clicking "Standard EXE" from the "New" tab under the "New Project" dialog
box. Click "Open" button to proceed.

3. 3

Draw a command button into the form. You can do this by clicking the "Command Button" control from the
"Toolbox" and dragging the mouse into the form to draw the button. Make sure that the command button is big
enough to hold a small picture or icon, along with its caption.

4. 4

Set the command button's "Caption" property to "Edit" at the "Properties" window.

5. 5

Click the command button's "Picture" property. You will notice a small button on the right with three dots. Click
to launch the "Load Picture" dialog box. Browse for picture files in your computer and add it to your control.
Click "Open" button to continue.

6. 6
Set the command button's "Style" property to "1-Graphical".

7. 7

Press F5 on your keyboard to run the program. You will notice that your command button has both picture and
caption on it.

8. 8

Click "End" button to go back to "Object" mode in Visual Basic.

9. 9

Save your work if you wish to by pressing "Ctrl" + "S" on your keyboard, or you may add more controls and
codes into the form.

3.2.5 The Image Box

The Image Box is another control that handles images and pictures. It functions almost identically to the picture box.
However, there is one major difference, the image in an Image Box is stretchable, which means it can be resized.
This feature is not available in the Picture Box. Similar to the Picture Box, it can also use the LoadPicture method to
load the picture. For example, the statement loads the picture grape.gif into the image box.

Image1.Picture=LoadPicture ("C:\VB program\Images\grape.gif")

As you may know, Microsoft Access provides a much more robust reporting system than Visual Basic. As a result,
if you use Access as a back-end to your application, you may want to print Access reports from your VB
application. Fortunately, you can do just that with Automation.

The following code shows one way to do so, using late binding:

Dim objAccess As Object

Private Sub Command1_Click()

Dim dbName As String

Dim rptName As String

Dim Preview As Long


Const acNormal = 0

Const acPreview = 2

dbName = "D:\PathToDB\db1.mdb"

rptName = "MyReportName"

Preview = acPreview 'acNormal

With objAccess

.OpenCurrentDatabase filepath:=dbName

If Preview = acPreview Then

.Visible = True

.DoCmd.OpenReport rptName, Preview

Else

.DoCmd.OpenReport rptName

End If

End With

End Sub

Private Sub Form_Load()

Set objAccess = CreateObject("Access.Application")

End Sub

Private Sub Form_Unload(Cancel As Integer)

On Error Resume Next

objAccess.Quit

On Error GoTo 0

Set objAccess = Nothing

End Sub
how to print datagrid in vb6?

Sakshi a replied to gl0omy sun on 02-Feb-10 09:57 PM

Private Sub Command2_Click()


Dim i As Integer
For i = 0 To DataGrid1.Columns.Count - 1
DataGrid1.Col = i
printer.Print DataGrid1.Text
Next
End Sub
printer.enddoc

To print:

Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click


Dim stringWrite As New System.IO.StringWriter()
Dim htmlWrite As New System.Web.UI.HtmlTextWriter(stringWrite)
Dim w As System.Web.UI.WebControls.Unit
w.Pixel(400)
DataGrid1.Width = w
Dim scr As String = "<script>function window.onafterprint(){history.back(1);}</script>"

htmlWrite.Write(scr)
Dim str As String = "" '"<div align=center id=titl1><h3><Font face=Verdana>Your
DataGrid:</font></h3></div>"
htmlWrite.Write(str)
DataGrid1.RenderControl(htmlWrite)
Dim strHTML As String = stringWrite.ToString()
Response.Clear()
' you could send it to Excel, too....
'Response.ContentType = "application/vnd.ms-excel"

Response.ContentType = "text/HTML"
Response.Write(strHTML)
Response.Write("<script>window.print();</script>")
Response.End()
End Sub

You might also like