|
Hi,
as I already told you, you can use an index or an enumerator.
Here is an index example:
myListView2.Images.Add(myListView1.Images[0]); // "copy" first image
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
modified on Sunday, June 12, 2011 8:57 AM
|
|
|
|
|
im doing drag drop to listview imagelist images....selected images.my drag drop part cannot work...i tried so many type of coding but could't now im tring....creat another image list in listview 2 and add those selected items images in to that list view...i can add item text but cannot add image....anyone if can pl help me.....
thanks a lot here is my code...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Diagnostics;
namespace Project_import_1
{
public partial class ImportForm : Form
{
public ImportForm()
{
InitializeComponent();
}
OpenFileDialog dlg = new OpenFileDialog();
private void import(object sender, EventArgs e)
{
ImageList imageList = new ImageList();
imageList.ImageSize = new Size(100, 80);
imageList.ColorDepth = ColorDepth.Depth32Bit;
int i = 0;
string[] files = dlg.FileNames;
string[] pathes = new string[files.Length];
foreach (string file in files)
{
pathes[i] = file;
i++;
}
foreach (string path in pathes)
{
FileInfo fileInfo = new FileInfo(path);
String strDir = fileInfo.Name;
listView1.Items.Add(strDir);
imageList.Images.Add(Bitmap.FromFile(path));
listView1.TileSize = new System.Drawing.Size(100, 80);
}
for (int j = 0; j < pathes.Length; j++)
{
this.listView1.Items[j].ImageIndex = j;
}
this.listView1.View = View.LargeIcon;
this.listView1.LargeImageList = imageList;
}
private void btnImport_Click(object sender, EventArgs e)
{
dlg.Filter = "All Image Files|*.bmp;*.ico;*.gif;*.jpeg;*.jpg;" +
"*.jfif;*.png;*.tif;*.tiff;*.wmf;*.emf|" +
"Windows Bitmap (*.bmp)|*.bmp|" +
"Windows Icon (*.ico)|*.ico|" +
"Graphics Interchange Format (*.gif)|*.gif|" +
"JPEG File Interchange Format (*.jpg)|" +
"*.jpg;*.jpeg;*.jfif|" +
"Portable Network Graphics (*.png)|*.png|" +
"Tag Image File Format (*.tif)|*.tif;*.tiff|" +
"Windows Metafile (*.wmf)|*.wmf|" +
"Enhanced Metafile (*.emf)|*.emf|" +
"All Files (*.*)|*.*";
dlg.InitialDirectory = @"C:\Documents and Settings\All Users\Desktop\";
dlg.Multiselect = true;
try
{
if (dlg.ShowDialog() == DialogResult.OK)
{
import(sender, e);
}
dlg.Reset();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void btnsave_Click_1(object sender, EventArgs e)
{
try
{
SaveFileDialog dlgSave = new SaveFileDialog();
saveFileDialog1.Filter = "*.jpg|*.jpg|*.bmp|*.bmp|*.gif|*.gif";
saveFileDialog1.ShowDialog();
if (dlgSave.ShowDialog() == DialogResult.OK)
{
if (dlgSave.FileName != "")
{
}
}
catch
{
MessageBox.Show("there is no Pic selected please select a Pic first", "Dear " + System.Environment.UserDomainName);
}
}
private void listView1_ItemDrag(object sender, ItemDragEventArgs e)
{
this.listView1.DoDragDrop(this.listView1.SelectedItems[0], DragDropEffects.Copy);
}
private void listView1_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(ListViewItem)))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void listView2_ItemDrag(object sender, ItemDragEventArgs e)
{
this.listView2.DoDragDrop(this.listView2.SelectedItems[0], DragDropEffects.Copy);
}
private void listView2_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(ListViewItem)))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void listView2_DragDrop(object sender, DragEventArgs e)
{
ListViewItem item = e.Data.GetData(typeof(ListViewItem)) as ListViewItem;
this.listView2.View = View.LargeIcon;
ImageList imageList = new ImageList();
imageList.ImageSize = new Size(100, 100);
imageList.ColorDepth = ColorDepth.Depth32Bit;
foreach (ListViewItem each in listView1.SelectedItems)
{
listView2.Items.Add(item.Text, item.ImageIndex);
imageList.Images.Add(Bitmap.FromFile(
*********** HOW CAN I TAKE SELECTED IMAGES TO HERE*********************));
listView2.TileSize = new System.Drawing.Size(100, 80);
}
for (int j = 0; j < listView1.SelectedItems.Count; j++)
{
this.listView1.Items[j].ImageIndex = j;
}
this.listView2.View = View.LargeIcon;
this.listView2.LargeImageList = imageList;
foreach (ListViewItem removeItem in listView1.SelectedItems)
{
listView1.Items.Remove(removeItem);
}
}
private void listView1_MouseDown(object sender, MouseEventArgs e)
{
ListViewItem item = e.Data.GetData(typeof(ListViewItem)) as ListViewItem;
DirectoryInfo dir = new DirectoryInfo(Directory.GetCurrentDirectory());
String strDir = fileInfo.Name;
listView1.Items.Add(strDir);
tbxPath.Text = dir.FullName;
}
protected void DisplayFileInfo(FileInfo TheFile)
{
}
}
}
|
|
|
|
|
asw.asela wrote: HOW CAN I TAKE SELECTED IMAGES TO HERE
this.listView1.LargeImageList[each.ImageIndex]
|
|
|
|
|
LargeImageList like property but is used like a method....telling that error....
A S E L A
|
|
|
|
|
Sorry...
this.listView1.LargeImageList.Images[each.ImageIndex]
|
|
|
|
|
no still no...i think should be somthing like add or insert etc method....
A S E L A
|
|
|
|
|
|
Hi,
don't take it personal. Seems like all articles are unreachable right now...
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
modified on Sunday, June 12, 2011 8:57 AM
|
|
|
|
|
Since the string "qwerty" does not contain a small letter l with a double bar (\u2c61) one would expect that when the code below is executed, both p and q would get the value -1. However, the second call to IndexOf does in fact return 0 instead of -1. After some further experimenting I found that this happens with several characters from Latin Extended-C (probably all of them) and that the return value is the same as the value of the second argument, i.e. the starting position for the search.
Is this a known bug? And can it be circumvented other than by writing my own search method?
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int p = "qwerty".IndexOf('\u2c61', 0);
System.Console.WriteLine(p);
int q = "qwerty".IndexOf("\u2c61", 0);
System.Console.WriteLine(q);
System.Console.ReadKey();
}
}
}
|
|
|
|
|
Hi,
running Vista SP1 and Visual Studio 2008, targeting either .NET 3.5 SP1 or .NET 2.0 I get correct values for IndexOf(char) but your phenomena for IndexOf(string).
[ADDED]
Reflector tells me string.IndexOf is using CultureInfo.CurrentCulture.CompareInfo.IndexOf
(and it gets very messy when diving into that)
so it may go wrong in some cultures only, making it more likely to go unnoticed for a long time...
[/ADDED]
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
modified on Monday, March 2, 2009 9:02 AM
modified on Sunday, June 12, 2011 8:58 AM
|
|
|
|
|
Yes, it is probably a locale problem. Today I found out that I can solve the problem by applying a Unicode normalization to the strings and then calling IndexOf() with StringComparison.Ordinal as the third argument, so that the method just checks the bytes.
|
|
|
|
|
hi there!
I build one c# application and now I want to add a setup project, so I can have setup for my application. I am selecting all the files from the application and going through all the steps required for creating the setup, and at the end I am getting error: Specified cast is not valid. Does anyone knows how to solve this issue? Please help me, I will really appreciate. Greetings and thanks in advance, Laziale
|
|
|
|
|
Try and run the setup wizard first, you also don't want all the files from your app, only content and primary output.
|
|
|
|
|
I tried just with content and primary output as well, but it gives me the same error, I don't have any idea how I can solve that. 
|
|
|
|
|
What is virtual node algorithm or graph embedded ring..?
|
|
|
|
|
Hey,
I've just looked up your questions on Google and there's quite a few hits for you to read. If you want me to write a synopsis for you then get back to me!
Results 1 - 10 of about 1,840,000 for virtual node algorithm. (0.36 seconds)
Results 1 - 10 of about 543,000 for graph embedded ring. (0.30 seconds)
Alan.
|
|
|
|
|
I would appreciate that.. 
|
|
|
|
|
can u suggets me some website only for delegates where we can find all the details by example
rizvan sivally
|
|
|
|
|
|
The problem is, Image.FromStream likes to reset the position to 0 (somewhere in its scary native methods) and that's exactly what I do not want, since the image in question is simply not located there. Currently I work around this by copying a big part of the stream starting at the point where the image starts to a MemoryStream, but it's taking quite a while and it seems like it shouldn't be needed. This means I have to scan for a pattern that "looks like the header of the next image" which may not always work (what if the data itself contains sometime that looks like a header but isn't?).
I'm sure there is a better way to do this.
I've tried creating a stream that does not support seeking, but Image.FromStream hates that and copies the stream over to a MemoryStream itself so it's effectively equivalent to the "manual" way. Silently ignoring seeks and assignments to Position didn't exactly work so I guess it somehow needs them - would it be ok accept seeks and positions as long as they don't move the position to before a certain value? That sounds a lot like a hack to me - I hope there is a better way.
Last modified: 11mins after originally posted --
|
|
|
|
|
|
That looks very promising, thanks
A bit of a hack IMO but well
|
|
|
|
|
Where are you trying to read from? I've done something like this before, but I had a file set up like this:
[File]
[DataType]
[Length of data]
[stuff]
[DataType]
[Length of data]
[stuff]
[end of file]
[/File]
So I knew how much data I needed to read out of the file, I then like you did, read the data to a memory stream and then used Image.FromStream . If you have any control over the creation of the files you're reading in, then you may want to get it changed so it's similar to what I used, or better yet has some kind of index at the top that tells you where everything is.
My current favourite word is: Delicious!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
Unfortunately it's just like [data][data][data][data] and they're mostly PNG images, and it can not be changed
|
|
|
|
|
That's a shame, at least Alan's reply can help you out with extracting the image.
As for finding the actual images themselves, the image files should store the length of their contents in their header. So as long as you get the first image right, it should lead on to the next and so on. Removing the need to try and figure it out.
PNG files for example are pretty much an eight bit signature, then the length of the data, a 4-byte code, [the image itself], then a CRC at the very end. See here[^]
Jpegs are similar giving the length of the data inside as well as other information jpeg header[^]
It might be a bit of work to manage each type of image format you're going to come across but it will be worth it in the end right? Right?
My current favourite word is: Delicious!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|