簡體   English   中英

在窗體中單擊按鈕時,如何在用戶控件中調整圖片框的大小?

[英]How to resize a picturebox in the user control when a button is clicked in the form?

因此,我是c#的新手,而此用戶控件使我頭疼。

當前正在努力創建一個用戶控件,該控件應充當進度條,因此我想起初我可以嘗試使用面板並在其中放置圖片框,從而顯示其進度,在我的表格中我有一個2按鈕說明下一個和上一個。 它就像進度條,主要用於向導中以檢測步驟。 考慮我有15個步驟,當我按“下一步”按鈕時,圖片框應以(width_of_the_panel / 15(no of steps))的比例展開。 我很困惑我可以寫resize_method嗎。 如果我在userControl中提到它,如何從我的表格中訪問它?

private void image_size()
{
    if (pictureBox1.Image.Width < pictureBox1.Width && pictureBox1.Image.Height < pictureBox1.Height)
    {
        pictureBox1.SizeMode = PictureBoxSizeMode.Normal;
    }
    else
    {
        pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
    }
    int wid = panel1.Width / val;
    Image img = new Bitmap(panel1.Width, panel1.Height);
    Graphics gr = Graphics.FromImage(img);
    gr.SmoothingMode = SmoothingMode.HighQuality;
    gr.InterpolationMode = InterpolationMode.HighQualityBicubic;
    gr.PixelOffsetMode = PixelOffsetMode.HighQuality;
    gr.DrawImage(img, 0, 0, wid, panel1.Height);
}

您可以使用.NET附帶的常規進度條。 使用ProgressBar.MaximumProgressBar.Step屬性,以適合您的向導樣式。 如果需要自定義,則可以從ProgressBar繼承,也可以創建帶有ProgressBar的復合UserControl 無需重新發明輪子並從頭開始創建自己的ProgressBar

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM