Birger Sørensen

Birger Sørensen

  • NA
  • 37
  • 3.3k

Problom with numbers and datatypes

Mar 31 2017 7:44 AM
Visual Studio 2017 Community in Win7.
Displaying a large number of images.
First off, it is nesscessary to insert two panels - one to make a scrollbar, and one to hold the images. I want only vertcal scrolling - and panels seems to not care about pictureBox'es and/or manually setting height - Autoscroll does NOT dispaly scrollbar(s). But etting a panel inside anoter panel, and increase it eight to accomodate images, does the trick - at least visually and functioal.
Second, there seem to be a limit on "Top", that is not an int (32 bit signed integer) but a short (16 bit signed integer).
Images that has top greater than 32767 are not displayed. (Actually above 32588 are located wrong and > 32767 are not dispalyed at all...)
The panel Appears to actually adjust its size correctly - but it reports it size wrong. Setting Height to ex. 70.000 seems to do correctly on screen and compared to pictureBoxes, and the scrollbar (on the parent panel). But it never reports its own height - panel.Height - as more that 65535 (max for a 16 bit unsigned integer). It is supposed to a 32 bit signed integer....

Source for placing images is like this:
(
img.name is shown onscreen on the mouseover function - which is partly how I can determine this odd behavior.
Also the four labels gives data from the last image, so even if images are not shown, images are actually created.
)
private void AddImg(ref int pos, ref int row, String card, Panel cardpanel)
{
double sizfact = (double)(ImgGauge.Value + 25) / 100; // Fra 25 til 225 %
CardInfo CrdInf;
String fname;
int imHeight = Convert.ToInt16(242 * sizfact);
int imWidth = Convert.ToInt16(164 * sizfact);
byte Rank;
PictureBox img = new PictureBox();
img.Anchor = AnchorStyles.Top | AnchorStyles.Left;
img.SizeMode = PictureBoxSizeMode.Zoom;
img.Margin = new Padding(0);
img.Width = imWidth;
img.Height = imHeight;
img.Top = (int)(3 + row * (imHeight + 3));
img.Left = (int)(3 + pos++ * (imWidth + 3));
img.Tag = card;
img.Name = "card_" + card + "_" + row.ToString() + "-" + pos.ToString() + "_" + img.Top.ToString() + "-" + img.Left.ToString();
if ((3 + (pos + 1) * (imWidth + 3)) >= cardpanel.Width)
{ // adjust panel height
pos = 0;
row++;
cardpanel.Height = (int)(3 + (row + 1) * (imHeight + 3));
}
labelPanelHeight.Text = cardpanel.Height.ToString();
labelRows.Text = row.ToString();
labelLatestTop.Text = img.Top.ToString();
labelLastCard.Text = img.Name;
fname = ((CardInfo)cardstable[card]).Ikon;
if ((fname == null) || (fname.Length < 1)) fname = FindCardIkon(card);
img.ImageLocation = fname;
img.MouseEnter += new EventHandler(CollectionPictureMouseEnter);
img.MouseLeave += new EventHandler(CollectionPictureMouseLeave);
img.Click += new EventHandler(RankSet_Click);
cardpanel.Controls.Add(img);
}

Was thinking, there might be a wrong (automatic) casting, which is the reason for the (int) castings, where they should not be needed. But that does not seem to be the case...

Any comments, or similar experiances?
Solution?