dcsimg
Results 1 to 8 of 8

Thread: [RESOLVED] How to make new column when drawn Listview items are greater than screen height

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Feb 2016
    Location
    Tennessee
    Posts
    2,293

    Resolved [RESOLVED] How to make new column when drawn Listview items are greater than screen height

    I'm drawing Listview Items to a form and I'm now at the point where I need to know how to create a new column before the number of items is greater than form height. I'm not sure if code will help, but I'll post a part of the drawing routine. I have six sizes of icons, but I'm just showing the code for icons that are 16x16.

    I imagine it will involve checking the value of Y before writing the item to a new column, and if item.Y is greater than form.height, start a new column. I don't expect anyone to give me code (although that would be good too), I'm just trying to find out what other peoples thoughts are about how to handle this.

    Any help greatly appreciated!

    Code:
      Dim exeIcon As Icon
      Select Case ImageSize
           Case 16
           DtListItems(i).extension = extesnion
           Dim ShortCut As String = DesktopWin.ResolveShortcut(DtListItems(i).Path)
           If IsDir(ShortCut) Then
                FolderimagePath = Path.Combine(DeskTopPath, DesktopWin.LastFolderImage)
                If IsDir(FolderimagePath) Then 'user is using default image for folder
                     .DrawImage(My.Resources.Gold, rect.X + 2, rect.Y + 2, ImageSize, ImageSize)
                     .DrawString(s, ListFont, New SolidBrush(ListForeColor), rect.X + 22, rect.Y + 2)
                     DtListItems(i).FolderUsed = True
                Else
                     .DrawImage(Image.FromFile(FolderimagePath), rect.X + 2, rect.Y + 2, ImageSize, ImageSize)
                     DtListItems(i).FolderUsed = True
                     .DrawString(s, ListFont, New SolidBrush(ListForeColor), rect.X + 22, rect.Y + 2)
                End If
           End If
    
           ret = Nothing
           Select Case DtListItems(i).extension
                Case ".zip"
                     ret = rk.GetValue("ZipIconPath")
                     If CStr(ret) <> "" Then
                          bmp = New Bitmap(Image.FromFile(CStr(ret)))
                          .DrawImage(bmp, rect.X + 2, rect.Y + 3, ImageSize, ImageSize)
                          .DrawString(s, ListFont, New SolidBrush(ListForeColor), rect.X + 22, rect.Y + 2)
                     Else
                          exeIcon = Icon.ExtractAssociatedIcon(DtListItems(i).Path)
                          .DrawImage(exeIcon.ToBitmap(), rect.X + 2, rect.Y + 4, ImageSize, ImageSize)
                          .DrawString(s, ListFont, New SolidBrush(ListForeColor), rect.X + 22, rect.Y + 1)
                     End If
                Case ".txt"
                     ret = rk.GetValue("TextIconPath")
                     If CStr(ret) <> "" Then
                          bmp = New Bitmap(Image.FromFile(CStr(ret)))
                          .DrawImage(bmp, rect.X + 2, rect.Y + 8, ImageSize, ImageSize)
                          .DrawString(s, ListFont, New SolidBrush(ListForeColor), rect.X + 22, rect.Y + 4)
                     Else
                          exeIcon = Icon.ExtractAssociatedIcon(DtListItems(i).Path)
                          .DrawImage(exeIcon.ToBitmap(), rect.X + 2, rect.Y + 4, ImageSize, ImageSize)
                          .DrawString(s, ListFont, New SolidBrush(ListForeColor), rect.X + 22, rect.Y + 4)
                     End If
                Case Else
                     If Not DtListItems(i).FolderUsed Then
                          exeIcon = Icon.ExtractAssociatedIcon(DtListItems(i).Path)
                          .DrawImage(exeIcon.ToBitmap(), rect.X + 2, rect.Y + 4, ImageSize, ImageSize)
                          .DrawString(s, ListFont, New SolidBrush(ListForeColor), rect.X + 22, rect.Y + 4)
                     End If
                End Select
           End Select

  2. #2
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,326

    Re: How to make new column when drawn Listview items are greater than screen height

    I think help is getting quite thin. How can anyone keep up with 5 threads per day and by the time they have read them you have edited and moved onto another question. It's upsetting still you post the code you found on the internet that you don't understand because quite frankly it is bad. And then you want members to fix it.


    The code is so hard to follow each and every thread, members are just not posting. Every time I see you post you do something One way then again another. This just shows you don't understand what's going on.


    Members will always help you but its One question per thread. If you have made an advancement post a new post. Don't edit. Just gets so confusing.

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Feb 2016
    Location
    Tennessee
    Posts
    2,293

    Re: How to make new column when drawn Listview items are greater than screen height

    Hello my friend. I don't think I post too much code from the Internet. If I do so, it's usually in the Code Bank where I try to share something with others in the hopes of helping someone. Much like the post I did today that you commented on as well.

    And I will admit that I have posted more today than usual. I didn't know it was 5 times because I wasn't counting. But I imagine each post was about something different.

    If you would like to advance this discussion more, feel free to send me a Private Message.
    Hope you have a wonderful night!

  4. #4
    Hyperactive Member
    Join Date
    Jun 2018
    Posts
    434

    Re: How to make new column when drawn Listview items are greater than screen height

    Since each item height varies you can loop through the list items and add up the row heights to the point of interest. Sum the total of the rowheights to the y coordinate of the mouse click or use the clientsize.height where it hits the bottom of the form client window.

    In the image two sizes 16, 32 are used (always starts at 0,0 upper left of form) on the left side you add the image heights:

    Name:  a1.jpg
Views: 44
Size:  27.3 KB

    h = 32 + 16 + 16 + 16 + 32 + 16 = 128


    on the right side example the items have 8 pixel padding each row on the bottom so the row height is now 24 and 40.

    Name:  a2.png
Views: 42
Size:  18.7 KB

    h = 40 + 24 + 24 + 40 = 128

    To determine the selected index loop the list items and add each item row height to the sum total. Check the total height with the y value like (not working code):

    Code:
      for i = 0 to theList.count - 1
    
             heightSum += thisItemRowHeight = icon.height + padding
    
             if heightsum > y then 
                  selectedIndex = i
                  exit for
             end if
    
      next
    One could also generate a rectangle for each item saved in class or methods in the class to produce it but its not really needed yet? Just add in an x value check now. Maybe when for two columns need to add the rects to the class then loop the item rects for the one that contains the e.location point.

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Feb 2016
    Location
    Tennessee
    Posts
    2,293

    Re: How to make new column when drawn Listview items are greater than screen height

    Hi Tom, you put a lot of work into this. Thank you. But based on your matrix (if I understand it), I want to make sure you know something. There are six sizes of Icons/Pngs. They are 16x16, 24x24, 32x32, 38x38, 42x42, and 48x48. However, they are never "mixed". Each view will be all one size. Like if one item is 16x16, they all will be. Hope I explained that well enough.

    I looked at your post right before I went to bed, but as usual, I wake up many times in the night and this time I wanted to write back so you would know I got your message. Now I'm going back to sleep, haha...

    Will write again in the morning to talk about this more.
    bye for now and again thank you

  6. #6
    Hyperactive Member
    Join Date
    Jun 2018
    Posts
    434

    Re: How to make new column when drawn Listview items are greater than screen height

    Quote Originally Posted by jumper77 View Post
    Hi Tom, you put a lot of work into this. Thank you. But based on your matrix (if I understand it), I want to make sure you know something. There are six sizes of Icons/Pngs. They are 16x16, 24x24, 32x32, 38x38, 42x42, and 48x48. However, they are never "mixed". Each view will be all one size. Like if one item is 16x16, they all will be. Hope I explained that well enough.

    I looked at your post right before I went to bed, but as usual, I wake up many times in the night and this time I wanted to write back so you would know I got your message. Now I'm going back to sleep, haha...

    Will write again in the morning to talk about this more.
    bye for now and again thank you
    Somehow I knew you would say that.

    Then my original one line equation from post 33 works fine.

  7. #7

    Thread Starter
    PowerPoster
    Join Date
    Feb 2016
    Location
    Tennessee
    Posts
    2,293

    Re: How to make new column when drawn Listview items are greater than screen height

    Haha... I'll look at the one liner again and see if it will help for knowing when to change to another column.
    Thanks.

  8. #8
    Hyperactive Member Peter Porter's Avatar
    Join Date
    Jul 2013
    Posts
    267

    Re: [RESOLVED] How to make new column when drawn Listview items are greater than scre

    [Deleted my comment]
    Last edited by Peter Porter; Apr 15th, 2019 at 09:21 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width