|
Quote:
Originally Posted by StaticFX
sorry but that is not correct.
In working on my own app, i discovered its done by the center of the icon image. because if you create a BIG icon, it will center in its location. it does not start it at the upper left corner.
so, locate the center of each icon, then calculate accordingly...
I know this code seems crazy, and IM SURE i could make it simpler, but here is how i calc it... a row number is passed into the sub... also, dont forget to calc for 5 icon dock.
This is done like this because i use a sub so i dont have to repeat the code.
VB.NET 2008
Code:
Dim tPlus As Integer
tPlus = 18 - ((Row - 1) * 2)
If Row = 5 Then tPlus = 24
Dim iW As Integer = imgDct(iName).Width
Dim iH As Integer = imgDct(iName).Height
Dim iC5 As Integer = If(Row = 5 And chk5Icons.Checked, 61, 76)
Dim iCp As Integer = If(Row = 5 And chk5Icons.Checked, 0, 8)
Dim iX As Integer = (iC5 * (Col - 1)) + iCp
iX = iX + (38 - iW / 2)
Dim iY As Integer = (90 * (Row - 1)) + tPlus
iY = iY + (45 - iH / 2)
gr.DrawImage(imgDct(iName), iX, iY, iW, iH)
now what you could od is just find each icons location center (on the screen)
Then take 1/2 the width and 1/2 the height and start it there...
so say icon one starts at X:55 , Y:60 and the icon is 60x60
55-30 = 25
60-30 = 30
start the icon in X,Y = 25,30
hope this helps... took a LOOOOOONG to to figure that out!! LOL every time i thought i had it.. bam, i would find another exception to the rule (thats probably why my stupid formulas are so crazy! )
good luck!
|
First of let me say thank you, that was a big post and not many people would even post this. So thanks :P
And about 10 mins after I posted that, I realized the same thing. I realized this because I had all had 57x57 icons, and if I generated a preview with 60x60 they wouldn't fit.
And not many people would share code, so thanks so much. But sadly I'm coding with c# so I can't use that code  . But don't worry your post was helpful. Sharing the routine will make it easy to replicate in c#.
Quote:
Originally Posted by StaticFX
sorry but that is not correct.
In working on my own app, i discovered its done by the center of the icon image. because if you create a BIG icon, it will center in its location. it does not start it at the upper left corner.
....
|
So I went back and re-wrote my code with your suggestion and my findings in mind, and here's my code.
Code:
int i = 0;
foreach (ListViewItem item in listView1.CheckedItems)
{
i++;
if (System.IO.File.Exists(item.SubItems[1].Text))
{
if (i <= 20)
{
System.Drawing.Image icon = System.Drawing.Image.FromFile(item.SubItems[1].Text,false);
int w = (icon.Width / 2);
int h = (icon.Height / 2);
if (i == 1)
{
g.DrawImage(icon, (46 - w), (61 - h), icon.Width, icon.Height);
}
if (i == 2)
{
g.DrawImage(icon, (122 - w), (61 - h), icon.Width, icon.Height);
}
if (i == 3)
{
g.DrawImage(icon, (198 - w), (61 - h), icon.Width, icon.Height);
}
if (i == 4)
{
g.DrawImage(icon, (274 - w), (61 - h), icon.Width, icon.Height);
}
if (i == 5)
{
g.DrawImage(icon, (46 - w), (150 - h), icon.Width, icon.Height);
}
if (i == 6)
{
g.DrawImage(icon, (122 - w), (150 - h), icon.Width, icon.Height);
}
if (i == 7)
{
g.DrawImage(icon, (198 - w), (150 - h), icon.Width, icon.Height);
}
if (i == 8)
{
g.DrawImage(icon, (274 - w), (150 - h), icon.Width, icon.Height);
}
if (i == 9)
{
g.DrawImage(icon, (46 - w), (238 - h), icon.Width, icon.Height);
}
if (i == 10)
{
g.DrawImage(icon, (122 - w), (238 - h), icon.Width, icon.Height);
}
if (i == 11)
{
g.DrawImage(icon, (198 - w), (238 - h), icon.Width, icon.Height);
}
if (i == 12)
{
g.DrawImage(icon, (274 - w), (238 - h), icon.Width, icon.Height);
}
if (i == 13)
{
g.DrawImage(icon, (46 - w), (326 - h), icon.Width, icon.Height);
}
if (i == 14)
{
g.DrawImage(icon, (122 - w), (326 - h), icon.Width, icon.Height);
}
if (i == 15)
{
g.DrawImage(icon, (198 - w), (326 - h), icon.Width, icon.Height);
}
if (i == 16)
{
g.DrawImage(icon, (274 - w), (326 - h), icon.Width, icon.Height);
}
if (i == 17)
{
g.DrawImage(icon, (46 - w), (428 - h), icon.Width, icon.Height);
}
if (i == 18)
{
g.DrawImage(icon, (122 - w), (428 - h), icon.Width, icon.Height);
}
if (i == 19)
{
g.DrawImage(icon, (198 - w), (428 - h), icon.Width, icon.Height);
}
if (i == 20)
{
g.DrawImage(icon, (274 - w), (428 - h), icon.Width, icon.Height);
}
}
}
}
Basically how mine works is it runs through that once for each checked icon in the list, and depending on what icon number it is it puts it in the right position. It is a lot simpler then your code but also there's a lot more code so it is less efficient.
Here's a little cleaned up version I just changed:
Code:
foreach (ListViewItem item in listView1.CheckedItems)
{
i++;
if (System.IO.File.Exists(item.SubItems[1].Text))
{
if (i <= 20)
{
System.Drawing.Image icon = System.Drawing.Image.FromFile(item.SubItems[1].Text,false);
int w = (icon.Width / 2);
int h = (icon.Height / 2);
if (i == 1)
g.DrawImage(icon, (46 - w), (61 - h), icon.Width, icon.Height);
else if (i == 2)
g.DrawImage(icon, (122 - w), (61 - h), icon.Width, icon.Height);
else if (i == 3)
g.DrawImage(icon, (198 - w), (61 - h), icon.Width, icon.Height);
else if (i == 4)
g.DrawImage(icon, (274 - w), (61 - h), icon.Width, icon.Height);
else if (i == 5)
g.DrawImage(icon, (46 - w), (150 - h), icon.Width, icon.Height);
else if (i == 6)
g.DrawImage(icon, (122 - w), (150 - h), icon.Width, icon.Height);
else if (i == 7)
g.DrawImage(icon, (198 - w), (150 - h), icon.Width, icon.Height);
else if (i == 8)
g.DrawImage(icon, (274 - w), (150 - h), icon.Width, icon.Height);
else if (i == 9)
g.DrawImage(icon, (46 - w), (238 - h), icon.Width, icon.Height);
else if (i == 10)
g.DrawImage(icon, (122 - w), (238 - h), icon.Width, icon.Height);
else if (i == 11)
g.DrawImage(icon, (198 - w), (238 - h), icon.Width, icon.Height);
else if (i == 12)
g.DrawImage(icon, (274 - w), (238 - h), icon.Width, icon.Height);
else if (i == 13)
g.DrawImage(icon, (46 - w), (326 - h), icon.Width, icon.Height);
else if (i == 14)
g.DrawImage(icon, (122 - w), (326 - h), icon.Width, icon.Height);
else if (i == 15)
g.DrawImage(icon, (198 - w), (326 - h), icon.Width, icon.Height);
else if (i == 16)
g.DrawImage(icon, (274 - w), (326 - h), icon.Width, icon.Height);
else if (i == 17)
g.DrawImage(icon, (46 - w), (428 - h), icon.Width, icon.Height);
else if (i == 18)
g.DrawImage(icon, (122 - w), (428 - h), icon.Width, icon.Height);
else if (i == 19)
g.DrawImage(icon, (198 - w), (428 - h), icon.Width, icon.Height);
else if (i == 20)
g.DrawImage(icon, (274 - w), (428 - h), icon.Width, icon.Height);
}
}
}
I will re-release the preview system with this update.
New version released!
|
Last edited by agentfubu; 04-10-2009 at 05:09 PM..
Reason: Automerged Doublepost
|