System.Windows.Forms.ListView.LayoutIcons C# (CSharp) Method

LayoutIcons() public method

public LayoutIcons ( Size item_size, bool left_aligned, int x_spacing, int y_spacing ) : void
item_size Size
left_aligned bool
x_spacing int
y_spacing int
return void
		void LayoutIcons (Size item_size, bool left_aligned, int x_spacing, int y_spacing)
		{
			header_control.Visible = false;
			header_control.Size = Size.Empty;
			item_control.Visible = true;
			item_control.Location = Point.Empty;
			ItemSize = item_size; // Cache item size
			this.x_spacing = x_spacing;
			this.y_spacing = y_spacing;

			if (items.Count == 0)
				return;

			Size sz = item_size;

			CalculateRowsAndCols (sz, left_aligned, x_spacing, y_spacing);

			layout_wd = UseCustomColumnWidth ? cols * custom_column_width : cols * (sz.Width + x_spacing) - x_spacing;
			layout_ht = rows * (sz.Height + y_spacing) - y_spacing;

			if (virtual_mode) { // no actual assignment is needed on items for virtual mode
				item_control.Size = new Size (layout_wd, layout_ht);
				return;
			}

			bool using_groups = UsingGroups;
			if (using_groups) // the groups layout will override layout_ht
				CalculateGroupsLayout (sz, y_spacing, 0);

			int row = 0, col = 0;
			int x = 0, y = 0;
			int display_index = 0;

			for (int i = 0; i < items.Count; i++) {
				ListViewItem item = items [i];
				if (using_groups) {
					ListViewGroup group = item.Group;
					if (group == null)
						group = groups.DefaultGroup;

					Point group_items_loc = group.items_area_location;
					int current_item = group.current_item++;
					int starting_row = group.starting_row;

					display_index = group.starting_item + current_item;
					row = (current_item / cols);
					col = current_item % cols;

					x = UseCustomColumnWidth ? col * custom_column_width : col * (item_size.Width + x_spacing);
					y = row * (item_size.Height + y_spacing) + group_items_loc.Y;

					SetItemLocation (display_index, x, y, row + starting_row, col);
					SetItemAtDisplayIndex (display_index, i);
					item_index_matrix [row + starting_row, col] = i;

				} else
				{
					x = UseCustomColumnWidth ? col * custom_column_width : col * (item_size.Width + x_spacing);
					y = row * (item_size.Height + y_spacing);
					display_index = i; // Same as item index in Items

					SetItemLocation (i, x, y, row, col);
					item_index_matrix [row, col] = i;

					if (left_aligned) {
						row++;
						if (row == rows) {
							row = 0;
							col++;
						}
					} else {
						if (++col == cols) {
							col = 0;
							row++;
						}
					}
				}

				item.Layout ();
				item.DisplayIndex = display_index;
				item.SetPosition (new Point (x, y));
			}

			item_control.Size = new Size (layout_wd, layout_ht);
		}
ListView