How To Add Picture To A Command Button in Visual Basic
How To Add Picture To A Command Button in Visual Basic
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
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
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.
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.
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:
Const acPreview = 2
dbName = "D:\PathToDB\db1.mdb"
rptName = "MyReportName"
With objAccess
.OpenCurrentDatabase filepath:=dbName
.Visible = True
Else
.DoCmd.OpenReport rptName
End If
End With
End Sub
End Sub
objAccess.Quit
On Error GoTo 0
End Sub
how to print datagrid in vb6?
To print:
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