Solved

is it possible to draw an Icon in a vb textbox

Posted on 2002-03-05
6
325 Views
Last Modified: 2010-05-02
is it possible to draw an Icon in a vb textbox
0
Comment
Question by:pbr-streetgang
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

705 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