Solved

is it possible to draw an Icon in a vb textbox

Posted on 2002-03-05
6
321 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

932 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now