Solved

is it possible to draw an Icon in a vb textbox

Posted on 2002-03-05
6
322 Views
Last Modified: 2010-05-02
is it possible to draw an Icon in a vb textbox
0
Comment
Question by:pbr-streetgang
  • 4
6 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6842008
Could you use a rich text box instead?
0
 
LVL 16

Accepted Solution

by:
Richie_Simonetti earned 50 total points
ID: 6842025
This is a complete form, save it with notepad:

VERSION 5.00
Begin VB.Form Form1
   Caption         =   "Form1"
   ClientHeight    =   3195
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   4680
   LinkTopic       =   "Form1"
   ScaleHeight     =   3195
   ScaleWidth      =   4680
   StartUpPosition =   3  'Windows Default
   Begin VB.TextBox Text1
      Height          =   1095
      Left            =   1980
      TabIndex        =   2
      Text            =   "Text1"
      Top             =   1440
      Width           =   2055
   End
   Begin VB.PictureBox Picture2
      Height          =   495
      Left            =   3180
      ScaleHeight     =   435
      ScaleWidth      =   1155
      TabIndex        =   1
      Top             =   300
      Width           =   1215
   End
   Begin VB.PictureBox Picture1
      Height          =   495
      Left            =   300
      Picture         =   "icon in textbox.frx":0000
      ScaleHeight     =   435
      ScaleWidth      =   1155
      TabIndex        =   0
      Top             =   240
      Width           =   1215
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'Option Explicit
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long

Private Sub Form_Click()
      Const PIXEL = 3
      Picture1.ScaleMode = PIXEL
      hDestDC& = GetDC(Text1.hwnd)
      x& = 0: y& = 0
      nWidth& = Picture1.ScaleWidth
      nHeight& = Picture1.ScaleHeight
      ' Assign information of the source bitmap.
      hSrcDC& = Picture1.hDC
      xSrc& = 0: ySrc& = 0
      ' Assign the SRCCOPY constant to the Raster operation.
      dwRop& = &HCC0020
      Suc& = BitBlt(hDestDC&, x&, y&, nWidth&, nHeight&, hSrcDC&, _
      xSrc&, ySrc&, dwRop&)
     
      End Sub
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 6842814
Textboxes do not support graphics.
As mentioned, a RichTextbox may be sufficient, or you may want to create your own, which is actually pretty easy:

* Add a usercontrol to your project.
* Drop an image control on the user control.
* Drop a textbox control on the user control.
* Run the User control wizard.
* Select all properties, methods and events you want to support.
* Map all user control properties to the corresponding "child" controls.
* Finalize the wizard

* Modify the code of the UserControl_resize so that the image control is attached to the left of the user control (or wherever you want it) and the textbox fills in the rest of the control.
* Optionally add a special picture to the user control's toolbox image.

Save this user control as something like IconTextBox.

Add this user control to your form as though you were adding a textbox.
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 3

Expert Comment

by:sridhar_PJ
ID: 6849539
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6850143
That form's code posted does it. Any progress?
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6992251
Hi again, do you need more help?
Just ask.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MS SQL store procedure to calculate and return result 6 57
Visual Studio 2005 text editor 10 38
How to read File Date Created using VB6 8 38
RUNRMTCMD from AS/400 12 44
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question