c# Scrollbar thumbar position calculation in CustomControl

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>public class DrawCanvas : Control
{
private int _scale = 10000;
private Image m_bkImg = null;
private Image m_bkScaledImg = null;
private Point m_ptStart;
private Point m_ptEnd;
private Rectangle m_dstRect;
private Rectangle m_srcRect;
private VScrollBar m_vScrollBar;
private HScrollBar m_hScrollBar;
public DrawCanvas()
{
SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.DoubleBuffer, true);
m_vScrollBar = new VScrollBar();
m_vScrollBar.Scroll += OnScroll;
m_hScrollBar = new HScrollBar();
m_hScrollBar.Scroll += OnScroll;
Controls.Add(m_vScrollBar);
Controls.Add(m_hScrollBar);
m_dstRect = new Rectangle();
m_srcRect = ClientRectangle;
}
public float ScaleValue { get => _scale / 100.0f; }
private void OnScroll(object sender, ScrollEventArgs e)
{
if (e.ScrollOrientation == ScrollOrientation.VerticalScroll)
{
m_dstRect.Y = e.NewValue;
if (m_dstRect.Y < 0)
m_dstRect.Y = 0;
}
else if (e.ScrollOrientation == ScrollOrientation.HorizontalScroll)
{
m_dstRect.X = e.NewValue;
if (m_dstRect.X < 0)
m_dstRect.X = 0;
}
Invalidate();
}
private void CalcScrollSize()
{
m_srcRect = ClientRectangle;
int curImgWidth = m_bkScaledImg == null ? 0 : m_bkScaledImg.Width;
int curImgHeight = m_bkScaledImg == null ? 0 : m_bkScaledImg.Height;
bool hVisiable = false;
bool vVisiable = false;
if (curImgHeight > Height)
vVisiable = true;
if (curImgWidth > Width)
hVisiable = true;
if (!vVisiable)
{
if (hVisiable)
{
vVisiable = curImgHeight > (Height - m_hScrollBar.Height);
}
}
if (!hVisiable)
{
if (vVisiable)
{
hVisiable = curImgWidth > (Width - m_vScrollBar.Width);
}
}
m_vScrollBar.Visible = vVisiable;
m_hScrollBar.Visible = hVisiable;
if (m_vScrollBar.Visible)
{
m_vScrollBar.Location = new Point(Width - m_vScrollBar.Width, 0);
m_vScrollBar.Height = m_hScrollBar.Visible ? Height - m_hScrollBar.Height : Height;
m_vScrollBar.SmallChange = Height / 20;
m_vScrollBar.LargeChange = Height / 10;
m_vScrollBar.Maximum = m_hScrollBar.Visible ? (curImgHeight - Height + m_hScrollBar.Height) : curImgHeight - Height;
m_vScrollBar.Maximum += m_vScrollBar.LargeChange - 1;
m_srcRect.Width = Width - m_vScrollBar.Width;
}
if (m_hScrollBar.Visible)
{
m_hScrollBar.Location = new Point(0, Height - m_hScrollBar.Height);
m_hScrollBar.Width = m_vScrollBar.Visible ? Width - m_vScrollBar.Width : Width;
m_hScrollBar.SmallChange = Width / 20;
m_hScrollBar.LargeChange = Width / 10;
m_hScrollBar.Maximum = m_vScrollBar.Visible ? (curImgWidth - Width + m_vScrollBar.Width) : curImgWidth - Width;
m_hScrollBar.Maximum += m_hScrollBar.LargeChange - 1;
m_srcRect.Height = Height - m_hScrollBar.Height;
}
m_dstRect.Width = m_srcRect.Width;
m_dstRect.Height = m_srcRect.Height;
if (m_dstRect.X > 0 && m_dstRect.Right > curImgWidth)
{
m_dstRect.X = curImgWidth - m_dstRect.Width;
if (m_dstRect.X < 0)
m_dstRect.X = 0;
}
if (m_dstRect.Y > 0 && m_dstRect.Bottom > curImgHeight)
{
m_dstRect.Y = curImgHeight - m_dstRect.Height;
if (m_dstRect.Y < 0)
m_dstRect.Y = 0;
}
}
protected override void OnSizeChanged(EventArgs e)
{
base.OnSizeChanged(e);
CalcScrollSize();
Invalidate();
}
protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.Clear(Color.FromArgb(0xcc, 0xcc, 0xcc));
if (m_bkScaledImg != null && m_dstRect.Width * m_dstRect.Height > 0)
{
e.Graphics.DrawImage(m_bkScaledImg, m_srcRect, m_dstRect, GraphicsUnit.Pixel);
}
}
public void SetImage(string _imgFile)
{
m_bkImg = Image.FromFile(_imgFile);
m_bkScaledImg = m_bkImg.Clone() as Image;
CalcScrollSize();
Invalidate();
}
protected override void OnMouseDown(MouseEventArgs e)
{
base.OnMouseDown(e);
m_ptStart = e.Location;
}
private Rectangle GetClientArea()
{
int w = m_vScrollBar.Visible ? (Width - m_vScrollBar.Width) : Width;
int h = m_hScrollBar.Visible ? (Height - m_hScrollBar.Height) : Height;
return new Rectangle(0, 0, w, h);
}
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
if (e.Button == MouseButtons.Left)
{
int curImgWidth = m_bkScaledImg.Width;
int curImgHeight = m_bkScaledImg.Height;
m_ptEnd = e.Location;
//_currentObject?.ChangeSize(m_ptEnd);
int xoffset = m_ptEnd.X - m_ptStart.X;
int yoffset = m_ptEnd.Y - m_ptStart.Y;
m_dstRect.X -= xoffset;
m_dstRect.Y -= yoffset;
if (m_dstRect.X < 0) m_dstRect.X = 0;
if (m_dstRect.Y < 0) m_dstRect.Y = 0;
m_ptStart = e.Location;
var rc = GetClientArea();
if (curImgWidth - m_dstRect.X < rc.Width)
m_dstRect.X = curImgWidth - rc.Width;
if (curImgHeight - m_dstRect.Y < rc.Height)
m_dstRect.Y = curImgHeight - rc.Height;
if (m_dstRect.X < 0) m_dstRect.X = 0;
if (m_dstRect.Y < 0) m_dstRect.Y = 0;
m_vScrollBar.Value = m_dstRect.Y;
m_hScrollBar.Value = m_dstRect.X;
Invalidate();
}
}
protected override void OnMouseWheel(MouseEventArgs e)
{
base.OnMouseWheel(e);
if ((ModifierKeys & Keys.Control) == Keys.Control)
{
if (e.Delta < 0)
{
ScaleWith(5);
CalcScrollSize();
Invalidate();
}
if (e.Delta > 0)
{
ScaleWith(-5);
CalcScrollSize();
Invalidate();
}
}
}
public Image GetImage()
{
return m_bkImg;
}
public void AutoImage()
{
float r = Math.Min(Width * 1.0f / m_bkImg.Width, Height * 1.0f / m_bkImg.Height);
ScaleTo(r);
CalcScrollSize();
Invalidate(false);
}
public void ResetImage()
{
Restore();
CalcScrollSize();
Invalidate(false);
}
public void ScaleUpImage()
{
if (_scale < 400000)
{
ScaleWith(5);
CalcScrollSize();
Invalidate(false);
}
}
public void ScaleDownImage()
{
if (_scale > 5)
{
ScaleWith(-5);
CalcScrollSize();
Invalidate(false);
}
}
//public static Image Resize(this Image image, float scale)
//{
// int w = (int)(image.Width * scale);
// int h = (int)(image.Height * scale);
// Bitmap bmp = new Bitmap(w, h, image.PixelFormat);
// using (var g = Graphics.FromImage(bmp))
// {
// g.DrawImage(image, new Rectangle(0, 0, w, h), new Rectangle(0, 0, image.Width, image.Height), GraphicsUnit.Pixel);
// }
// return bmp;
//}
private void ScaleWith(int val)
{
if (val < 0 && _scale > 500 || val > 0 && _scale < 4000000)
{
_scale += val * 100;
m_bkScaledImg?.Dispose();
m_bkScaledImg = m_bkImg.Resize(_scale / 10000.0f);
}
}
public void ScaleTo(float val, bool _invalidate = false)
{
_scale = (int)(val * 10000);
m_bkScaledImg?.Dispose();
m_bkScaledImg = m_bkImg.Resize(val);
if (_invalidate)
{
CalcScrollSize();
Invalidate(false);
}
}
private void Restore()
{
_scale = 10000;
m_bkScaledImg?.Dispose();
m_bkScaledImg = m_bkImg.Clone() as Image;
}
}
</code>
<code>public class DrawCanvas : Control { private int _scale = 10000; private Image m_bkImg = null; private Image m_bkScaledImg = null; private Point m_ptStart; private Point m_ptEnd; private Rectangle m_dstRect; private Rectangle m_srcRect; private VScrollBar m_vScrollBar; private HScrollBar m_hScrollBar; public DrawCanvas() { SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.DoubleBuffer, true); m_vScrollBar = new VScrollBar(); m_vScrollBar.Scroll += OnScroll; m_hScrollBar = new HScrollBar(); m_hScrollBar.Scroll += OnScroll; Controls.Add(m_vScrollBar); Controls.Add(m_hScrollBar); m_dstRect = new Rectangle(); m_srcRect = ClientRectangle; } public float ScaleValue { get => _scale / 100.0f; } private void OnScroll(object sender, ScrollEventArgs e) { if (e.ScrollOrientation == ScrollOrientation.VerticalScroll) { m_dstRect.Y = e.NewValue; if (m_dstRect.Y < 0) m_dstRect.Y = 0; } else if (e.ScrollOrientation == ScrollOrientation.HorizontalScroll) { m_dstRect.X = e.NewValue; if (m_dstRect.X < 0) m_dstRect.X = 0; } Invalidate(); } private void CalcScrollSize() { m_srcRect = ClientRectangle; int curImgWidth = m_bkScaledImg == null ? 0 : m_bkScaledImg.Width; int curImgHeight = m_bkScaledImg == null ? 0 : m_bkScaledImg.Height; bool hVisiable = false; bool vVisiable = false; if (curImgHeight > Height) vVisiable = true; if (curImgWidth > Width) hVisiable = true; if (!vVisiable) { if (hVisiable) { vVisiable = curImgHeight > (Height - m_hScrollBar.Height); } } if (!hVisiable) { if (vVisiable) { hVisiable = curImgWidth > (Width - m_vScrollBar.Width); } } m_vScrollBar.Visible = vVisiable; m_hScrollBar.Visible = hVisiable; if (m_vScrollBar.Visible) { m_vScrollBar.Location = new Point(Width - m_vScrollBar.Width, 0); m_vScrollBar.Height = m_hScrollBar.Visible ? Height - m_hScrollBar.Height : Height; m_vScrollBar.SmallChange = Height / 20; m_vScrollBar.LargeChange = Height / 10; m_vScrollBar.Maximum = m_hScrollBar.Visible ? (curImgHeight - Height + m_hScrollBar.Height) : curImgHeight - Height; m_vScrollBar.Maximum += m_vScrollBar.LargeChange - 1; m_srcRect.Width = Width - m_vScrollBar.Width; } if (m_hScrollBar.Visible) { m_hScrollBar.Location = new Point(0, Height - m_hScrollBar.Height); m_hScrollBar.Width = m_vScrollBar.Visible ? Width - m_vScrollBar.Width : Width; m_hScrollBar.SmallChange = Width / 20; m_hScrollBar.LargeChange = Width / 10; m_hScrollBar.Maximum = m_vScrollBar.Visible ? (curImgWidth - Width + m_vScrollBar.Width) : curImgWidth - Width; m_hScrollBar.Maximum += m_hScrollBar.LargeChange - 1; m_srcRect.Height = Height - m_hScrollBar.Height; } m_dstRect.Width = m_srcRect.Width; m_dstRect.Height = m_srcRect.Height; if (m_dstRect.X > 0 && m_dstRect.Right > curImgWidth) { m_dstRect.X = curImgWidth - m_dstRect.Width; if (m_dstRect.X < 0) m_dstRect.X = 0; } if (m_dstRect.Y > 0 && m_dstRect.Bottom > curImgHeight) { m_dstRect.Y = curImgHeight - m_dstRect.Height; if (m_dstRect.Y < 0) m_dstRect.Y = 0; } } protected override void OnSizeChanged(EventArgs e) { base.OnSizeChanged(e); CalcScrollSize(); Invalidate(); } protected override void OnPaint(PaintEventArgs e) { e.Graphics.Clear(Color.FromArgb(0xcc, 0xcc, 0xcc)); if (m_bkScaledImg != null && m_dstRect.Width * m_dstRect.Height > 0) { e.Graphics.DrawImage(m_bkScaledImg, m_srcRect, m_dstRect, GraphicsUnit.Pixel); } } public void SetImage(string _imgFile) { m_bkImg = Image.FromFile(_imgFile); m_bkScaledImg = m_bkImg.Clone() as Image; CalcScrollSize(); Invalidate(); } protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); m_ptStart = e.Location; } private Rectangle GetClientArea() { int w = m_vScrollBar.Visible ? (Width - m_vScrollBar.Width) : Width; int h = m_hScrollBar.Visible ? (Height - m_hScrollBar.Height) : Height; return new Rectangle(0, 0, w, h); } protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); if (e.Button == MouseButtons.Left) { int curImgWidth = m_bkScaledImg.Width; int curImgHeight = m_bkScaledImg.Height; m_ptEnd = e.Location; //_currentObject?.ChangeSize(m_ptEnd); int xoffset = m_ptEnd.X - m_ptStart.X; int yoffset = m_ptEnd.Y - m_ptStart.Y; m_dstRect.X -= xoffset; m_dstRect.Y -= yoffset; if (m_dstRect.X < 0) m_dstRect.X = 0; if (m_dstRect.Y < 0) m_dstRect.Y = 0; m_ptStart = e.Location; var rc = GetClientArea(); if (curImgWidth - m_dstRect.X < rc.Width) m_dstRect.X = curImgWidth - rc.Width; if (curImgHeight - m_dstRect.Y < rc.Height) m_dstRect.Y = curImgHeight - rc.Height; if (m_dstRect.X < 0) m_dstRect.X = 0; if (m_dstRect.Y < 0) m_dstRect.Y = 0; m_vScrollBar.Value = m_dstRect.Y; m_hScrollBar.Value = m_dstRect.X; Invalidate(); } } protected override void OnMouseWheel(MouseEventArgs e) { base.OnMouseWheel(e); if ((ModifierKeys & Keys.Control) == Keys.Control) { if (e.Delta < 0) { ScaleWith(5); CalcScrollSize(); Invalidate(); } if (e.Delta > 0) { ScaleWith(-5); CalcScrollSize(); Invalidate(); } } } public Image GetImage() { return m_bkImg; } public void AutoImage() { float r = Math.Min(Width * 1.0f / m_bkImg.Width, Height * 1.0f / m_bkImg.Height); ScaleTo(r); CalcScrollSize(); Invalidate(false); } public void ResetImage() { Restore(); CalcScrollSize(); Invalidate(false); } public void ScaleUpImage() { if (_scale < 400000) { ScaleWith(5); CalcScrollSize(); Invalidate(false); } } public void ScaleDownImage() { if (_scale > 5) { ScaleWith(-5); CalcScrollSize(); Invalidate(false); } } //public static Image Resize(this Image image, float scale) //{ // int w = (int)(image.Width * scale); // int h = (int)(image.Height * scale); // Bitmap bmp = new Bitmap(w, h, image.PixelFormat); // using (var g = Graphics.FromImage(bmp)) // { // g.DrawImage(image, new Rectangle(0, 0, w, h), new Rectangle(0, 0, image.Width, image.Height), GraphicsUnit.Pixel); // } // return bmp; //} private void ScaleWith(int val) { if (val < 0 && _scale > 500 || val > 0 && _scale < 4000000) { _scale += val * 100; m_bkScaledImg?.Dispose(); m_bkScaledImg = m_bkImg.Resize(_scale / 10000.0f); } } public void ScaleTo(float val, bool _invalidate = false) { _scale = (int)(val * 10000); m_bkScaledImg?.Dispose(); m_bkScaledImg = m_bkImg.Resize(val); if (_invalidate) { CalcScrollSize(); Invalidate(false); } } private void Restore() { _scale = 10000; m_bkScaledImg?.Dispose(); m_bkScaledImg = m_bkImg.Clone() as Image; } } </code>
public class DrawCanvas : Control
{
private int _scale = 10000;
private Image m_bkImg = null;
private Image m_bkScaledImg = null;
private Point m_ptStart;
private Point m_ptEnd;
private Rectangle m_dstRect;
private Rectangle m_srcRect;

private VScrollBar m_vScrollBar;
private HScrollBar m_hScrollBar;

public DrawCanvas()
{
SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.DoubleBuffer, true);
m_vScrollBar = new VScrollBar();
m_vScrollBar.Scroll += OnScroll;
m_hScrollBar = new HScrollBar();
m_hScrollBar.Scroll += OnScroll;
Controls.Add(m_vScrollBar);
Controls.Add(m_hScrollBar);
m_dstRect = new Rectangle();
m_srcRect = ClientRectangle;
}

public float ScaleValue { get => _scale / 100.0f; }

private void OnScroll(object sender, ScrollEventArgs e)
{
if (e.ScrollOrientation == ScrollOrientation.VerticalScroll)
{
m_dstRect.Y = e.NewValue;
if (m_dstRect.Y < 0)
m_dstRect.Y = 0;
}
else if (e.ScrollOrientation == ScrollOrientation.HorizontalScroll)
{
m_dstRect.X = e.NewValue;
if (m_dstRect.X < 0)
m_dstRect.X = 0;
}

Invalidate();
}

private void CalcScrollSize()
{
m_srcRect = ClientRectangle;
int curImgWidth = m_bkScaledImg == null ? 0 : m_bkScaledImg.Width;
int curImgHeight = m_bkScaledImg == null ? 0 : m_bkScaledImg.Height;

bool hVisiable = false;
bool vVisiable = false;
if (curImgHeight > Height)
vVisiable = true;
if (curImgWidth > Width)
hVisiable = true;

if (!vVisiable)
{
if (hVisiable)
{
vVisiable = curImgHeight > (Height - m_hScrollBar.Height);
}
}

if (!hVisiable)
{
if (vVisiable)
{
hVisiable = curImgWidth > (Width - m_vScrollBar.Width);
}
}

m_vScrollBar.Visible = vVisiable;
m_hScrollBar.Visible = hVisiable;

if (m_vScrollBar.Visible)
{
m_vScrollBar.Location = new Point(Width - m_vScrollBar.Width, 0);
m_vScrollBar.Height = m_hScrollBar.Visible ? Height - m_hScrollBar.Height : Height;
m_vScrollBar.SmallChange = Height / 20;
m_vScrollBar.LargeChange = Height / 10;
m_vScrollBar.Maximum = m_hScrollBar.Visible ? (curImgHeight - Height + m_hScrollBar.Height) : curImgHeight - Height;
m_vScrollBar.Maximum += m_vScrollBar.LargeChange - 1;
m_srcRect.Width = Width - m_vScrollBar.Width;
}

if (m_hScrollBar.Visible)
{
m_hScrollBar.Location = new Point(0, Height - m_hScrollBar.Height);
m_hScrollBar.Width = m_vScrollBar.Visible ? Width - m_vScrollBar.Width : Width;
m_hScrollBar.SmallChange = Width / 20;
m_hScrollBar.LargeChange = Width / 10;
m_hScrollBar.Maximum = m_vScrollBar.Visible ? (curImgWidth - Width + m_vScrollBar.Width) : curImgWidth - Width;
m_hScrollBar.Maximum += m_hScrollBar.LargeChange - 1;
m_srcRect.Height = Height - m_hScrollBar.Height;
}

m_dstRect.Width = m_srcRect.Width;
m_dstRect.Height = m_srcRect.Height;


if (m_dstRect.X > 0 && m_dstRect.Right > curImgWidth)
{
m_dstRect.X = curImgWidth - m_dstRect.Width;
if (m_dstRect.X < 0)
m_dstRect.X = 0;
}

if (m_dstRect.Y > 0 && m_dstRect.Bottom > curImgHeight)
{
m_dstRect.Y = curImgHeight - m_dstRect.Height;
if (m_dstRect.Y < 0)
m_dstRect.Y = 0;
}
}


protected override void OnSizeChanged(EventArgs e)
{
base.OnSizeChanged(e);
CalcScrollSize();
Invalidate();
}

protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.Clear(Color.FromArgb(0xcc, 0xcc, 0xcc));
if (m_bkScaledImg != null && m_dstRect.Width * m_dstRect.Height > 0)
{
e.Graphics.DrawImage(m_bkScaledImg, m_srcRect, m_dstRect, GraphicsUnit.Pixel);
}
}

public void SetImage(string _imgFile)
{
m_bkImg = Image.FromFile(_imgFile);
m_bkScaledImg = m_bkImg.Clone() as Image;
CalcScrollSize();
Invalidate();
}

protected override void OnMouseDown(MouseEventArgs e)
{
base.OnMouseDown(e);
m_ptStart = e.Location;
}

private Rectangle GetClientArea()
{
int w = m_vScrollBar.Visible ? (Width - m_vScrollBar.Width) : Width;
int h = m_hScrollBar.Visible ? (Height - m_hScrollBar.Height) : Height;
return new Rectangle(0, 0, w, h);
}

protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
if (e.Button == MouseButtons.Left)
{
int curImgWidth = m_bkScaledImg.Width;
int curImgHeight = m_bkScaledImg.Height;

m_ptEnd = e.Location;
//_currentObject?.ChangeSize(m_ptEnd);

int xoffset = m_ptEnd.X - m_ptStart.X;
int yoffset = m_ptEnd.Y - m_ptStart.Y;

m_dstRect.X -= xoffset;
m_dstRect.Y -= yoffset;

if (m_dstRect.X < 0) m_dstRect.X = 0;
if (m_dstRect.Y < 0) m_dstRect.Y = 0;

m_ptStart = e.Location;

var rc = GetClientArea();
if (curImgWidth - m_dstRect.X < rc.Width)
m_dstRect.X = curImgWidth - rc.Width;

if (curImgHeight - m_dstRect.Y < rc.Height)
m_dstRect.Y = curImgHeight - rc.Height;

if (m_dstRect.X < 0) m_dstRect.X = 0;
if (m_dstRect.Y < 0) m_dstRect.Y = 0;

m_vScrollBar.Value = m_dstRect.Y;
m_hScrollBar.Value = m_dstRect.X;

Invalidate();
}
}

protected override void OnMouseWheel(MouseEventArgs e)
{
base.OnMouseWheel(e);

if ((ModifierKeys & Keys.Control) == Keys.Control)
{
if (e.Delta < 0)
{
ScaleWith(5);
CalcScrollSize();
Invalidate();
}

if (e.Delta > 0)
{
ScaleWith(-5);
CalcScrollSize();
Invalidate();
}
}
}


public Image GetImage()
{
return m_bkImg;
}

public void AutoImage()
{
float r = Math.Min(Width * 1.0f / m_bkImg.Width, Height * 1.0f / m_bkImg.Height);
ScaleTo(r);
CalcScrollSize();
Invalidate(false);
}

public void ResetImage()
{
Restore();
CalcScrollSize();
Invalidate(false);
}

public void ScaleUpImage()
{
if (_scale < 400000)
{
ScaleWith(5);
CalcScrollSize();
Invalidate(false);
}
}

public void ScaleDownImage()
{
if (_scale > 5)
{
ScaleWith(-5);
CalcScrollSize();
Invalidate(false);
}
}

//public static Image Resize(this Image image, float scale)
//{
//    int w = (int)(image.Width * scale);
//    int h = (int)(image.Height * scale);
//    Bitmap bmp = new Bitmap(w, h, image.PixelFormat);
//    using (var g = Graphics.FromImage(bmp))
//    {
//        g.DrawImage(image, new Rectangle(0, 0, w, h), new Rectangle(0, 0, image.Width, image.Height), GraphicsUnit.Pixel);
//    }
//    return bmp;
//}

private void ScaleWith(int val)
{
if (val < 0 && _scale > 500 || val > 0 && _scale < 4000000)
{
_scale += val * 100;
m_bkScaledImg?.Dispose();
m_bkScaledImg = m_bkImg.Resize(_scale / 10000.0f);
}
}

public void ScaleTo(float val, bool _invalidate = false)
{
_scale = (int)(val * 10000);
m_bkScaledImg?.Dispose();
m_bkScaledImg = m_bkImg.Resize(val);
if (_invalidate)
{
CalcScrollSize();
Invalidate(false);
}
}

private void Restore()
{
_scale = 10000;
m_bkScaledImg?.Dispose();
m_bkScaledImg = m_bkImg.Clone() as Image;
}
}

Now there is a problem, add a picture to the control (larger than the client area of the control). Reduce the image to the approximate size of the control, drag the image to scroll the scroll bar to the far right, and then click the scroll bar right button to find that the image has moved,that’s a problen.

I tried to print some key information of pictures and scroll bars during various operations, but I haven’t found the problem yet.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật