Keeping a PictureBox centered inside a container

前端 未结 3 747
闹比i
闹比i 2020-12-20 14:40

I am designing a simple picture viewer with ability to do some basic image processing. At the moment I have the problem of keeping the PictureBox centered insid

3条回答
  •  盖世英雄少女心
    2020-12-20 15:33

    I believe your problem lies here

    var xPoint = tabImageView.Location.X + ((splitContainer.Panel2.Width / 2) / 2);
    var yPoint = tabImageView.Location.Y;
    
    var width = tabImageView.Width / 2;
    var height = (tabImageView.Height / 2) - toolStripImageView.Height;
    

    ypoint is alwways set to tabImageView Y, althought it should be set to

    tabImageView.Location.Y + (tabImageView.Size.Height - picBoxView.Size.Height)/2
    

    should be almost the same with xPoint

    tabImageView.Location.X + (tabImageView.Size.Width - picBoxView.Size.Width)/2
    

    and

    width = picBoxView.Image.Width;
    height = picBoxView.Image.Height;
    

提交回复
热议问题