473,657 Members | 2,523 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why is the image in picturebox ugly?

yxq
Please add the manifest file!

*************** *************** *************** *************** *
Imports System
Imports System.Drawing
Imports System.Runtime. InteropServices
Module Module1
Public Class Icon
'============== =============== =============== =============== =============== =
==========
' Enumerations

'============== =============== =============== =============== =============== =
==========
<Flags()> Private Enum SHGFI
SmallIcon = &H1
LargeIcon = &H0
Icon = &H100
DisplayName = &H200
Typename = &H400
SysIconIndex = &H4000
UseFileAttribut es = &H10
End Enum

Public Enum IconSize
SmallIcon = 1
LargeIcon = 0
End Enum
'============== =============== =============== =============== =============== =
==========
' Structures

'============== =============== =============== =============== =============== =
==========
<StructLayout(L ayoutKind.Seque ntial)> _
Private Structure SHFILEINFO
Public hIcon As IntPtr
Public iIcon As Integer
Public dwAttributes As Integer
<MarshalAs(Unma nagedType.LPStr , SizeConst:=260) > Public
szDisplayName As String
<MarshalAs(Unma nagedType.LPStr , SizeConst:=80)> Public
szTypeName As String

Public Sub New(ByVal B As Boolean)
hIcon = IntPtr.Zero
iIcon = 0
dwAttributes = 0
szDisplayName = vbNullString
szTypeName = vbNullString
End Sub
End Structure
'============== =============== =============== =============== =============== =
==========
' API Calls

'============== =============== =============== =============== =============== =
==========
Private Declare Auto Function SHGetFileInfo Lib "shell32" (ByVal
pszPath As String,

ByVal dwFileAttribute s As Integer, ByRef psfi As SHFILEINFO, ByVal
cbFileInfo As Integer, ByVal

uFlagsn As SHGFI) As Integer
'============== =============== =============== =============== =============== =
==========
' Functions and Procedures...

'============== =============== =============== =============== =============== =
==========
Public Shared Function GetDefaultIcon( ByVal Path As String, Optional
ByVal IconSize As

IconSize = IconSize.SmallI con, Optional ByVal SaveIconPath As String = "")
As Icon
Dim info As New SHFILEINFO(True )
Dim cbSizeInfo As Integer = Marshal.SizeOf( info)
Dim flags As SHGFI = SHGFI.Icon Or SHGFI.UseFileAt tributes
flags = flags + IconSize
SHGetFileInfo(P ath, 256, info, cbSizeInfo, flags)
GetDefaultIcon = Icon.FromHandle (info.hIcon)
If SaveIconPath <> "" Then
Dim FileStream As New IO.FileStream(S aveIconPath,
IO.FileMode.Cre ate)
GetDefaultIcon. Save(FileStream )
FileStream.Clos e()
End If
End Function 'GetDefaultIcon (ByVal Path As String, Optional ByVal
IconSize As

IconSize = IconSize.SmallI con, Optional ByVal SaveIconPath As String = "")
As Icon

'============== =============== =============== =============== =============== =
==========
Public Shared Function ImageToIcon(ByV al SourceImage As Image) As
Icon
' converts an image into an icon
Dim TempBitmap As New Bitmap(SourceIm age)
ImageToIcon = Icon.FromHandle (TempBitmap.Get Hicon())
TempBitmap.Disp ose()
End Function 'ImageToIcon(By Val SourceImage As Image) As Icon

'============== =============== =============== =============== =============== =
==========

End Class
Public Declare Unicode Function PickIconDlg _
Lib "shell32.dl l" Alias "#62" ( _
ByVal hwndOwner As IntPtr, _
ByVal lpstrFile As System.Text.Str ingBuilder, _
ByVal nMaxFile As Integer, _
ByRef lpdwIconIndex As Integer) _
As Integer

Public Declare Function ExtractIcon _
Lib "shell32.dl l" Alias "ExtractIco nA" ( _
ByVal hInst As IntPtr, _
ByVal lpszExeFileName As String, _
ByVal nIconIndex As Integer) _
As IntPtr

Public Declare Function DestroyIcon _
Lib "user32.dll " (ByVal hIcon As Integer) _
As Integer
End Module
*************** *************** *************** *************** *************** *
*****

Private Sub Form1_Load(ByVa l sender As Object, ByVal e As
System.EventArg s) Handles

MyBase.Load
Dim ObjLVI As ListViewItem
Dim arrItem(1) As String
Dim eachDrv As String
Dim ObjSize As New Size()
ObjSize.Height = 32
ObjSize.Width = 32

ImageList1.Imag eSize = ObjSize
ImageList1.Colo rDepth = ColorDepth.Dept h32Bit
ListView1.Large ImageList = ImageList1

For Each eachDrv In System.Environm ent.GetLogicalD rives
arrItem(0) = eachDrv
ObjLVI = New ListViewItem(ar rItem)
ImageList1.Imag es.Add(Icon.Get DefaultIcon(arr Item(0),
Icon.IconSize.L argeIcon, ""))
ObjLVI.ImageInd ex = ImageList1.Imag es.Count - 1

ListView1.Items .Add(ObjLVI)
Next
End Sub

Private Sub ListView1_Selec tedIndexChanged (ByVal sender As Object, ByVal e
As

System.EventArg s) Handles ListView1.Selec tedIndexChanged
Try
PictureBox1.Ima ge =
ImageList1.Imag es(ListView1.Se lectedItems(0). ImageIndex)
Catch
End Try
End Sub
*************** *************** *************** *************** *************** *
**********

Thanks
Nov 20 '05 #1
0 1468

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
13368
by: Alberto | last post by:
I'm trying to load an image in a PictureBox but I want the PictureBox has always the same size and if the image is bigger, show a scrollBars. How can I do it? Thank you
1
3633
by: Novice | last post by:
I'm afraid I will incur the wraith of Mr. Powell on this one - but I did read his #1 FAQ and some others and I still can't figure this out. I created this little c# app. and I have a PictureBox in my Form. I load this image from the filesystem into the PictureBox and then I draw random little lines on the image. Then when I minimize and reopen the application the little lines are gone. Is there a way to save my lines in memory and...
1
12780
by: marco | last post by:
I'm a newbie and i'm doing a little application that open image. I don't understand what i've to do to have a zoom of an image...i don't know where's the error. If anyone know a simple code tell me the url :O) private void Zoom200_Click(object sender, System.EventArgs e) { PictureBox.Width = PictureBox.Width + (PictureBox.Width * 2);
2
7465
by: marco | last post by:
I'm a newbie and i'm doing a little application in C# for a Pocket PC that open image. I don't understand what i've to do to have a zoom of an image...i don't know where's the error. If anyone know a simple code tell me the url :O) private void Zoom200_Click(object sender, System.EventArgs e) {
6
2141
by: Patrick Dugan | last post by:
Hello, I'm trying to load different images (icons) into a PictureBox1.Image. The first image loads just fine, but the second image always returns the error "Invalid property used." It doesn't matter what icons are loaded. The first always shows up and any icons after that give me the error. Here is the offending code: The "DestinationPath" variable is the full path and filename of the icon
3
63389
by: Tom | last post by:
I have a picturebox on my VB.NET form. The picturebox size mode is set to stretched. I then load an image into that form and display it. As the user moves the mouse over the form, I want to get and display (in the status bar) the image coordinates of the mouse location. However, if I use the picturebox's MouseMove event, I am getting the coordinates of the mouse over the PICTUREBOX, not the actual image underneath that (which is stretched)....
7
11613
by: lgbjr | last post by:
Hello All, I¡¯m using a context menu associated with some pictureboxes to provide copy/paste functionality. Copying the image to the clipboard was easy. But pasting an image from the clipboard is proving to be more difficult. These pictureboxes are bound to an AccessDB. If the user wants to add an image, they select an image using an OpenFileDialog: Dim result As DialogResult = Pic_Sel.ShowDialog() If (result = DialogResult.OK) Then
4
2556
by: John Swan | last post by:
Hello. I'm trying to create a simple program that amongst other things creates a thumbnail of an image (Bitmap) to a set size determined by the user in pixels? The problem is: All of the examples I have seen so far are in c#. Can anyone please provide reference to a c++ managed version. Thanks. John
4
1482
by: rodchar | last post by:
hey all, i have an image that i want to put on my form and was just wondering if there is a way to take away the white background on the image (make it transparent)? thanks, rodchar
3
22441
by: Andrzej | last post by:
I have a picturebox on my C# .NET form. The picturebox size mode is set to zoom. I then load an image into that form and display it. As the user moves the mouse over the form, I want to get and display (in the status bar) the image coordinates of the mouse location. However, if I use the picturebox's MouseMove event, I am getting the coordinates of the mouse over the PICTUREBOX, not the actual image underneath that (which is zoomed). i.e....
0
8403
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8316
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8737
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8509
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7345
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6174
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4168
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4327
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2735
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.