【发布时间】:2021-12-23 03:39:43
【问题描述】:
我创建了一个新的用户控件并在它的设计器中添加了一个图片框。
这是带有图片框的用户控件设计器的屏幕截图
User Control designer with pictureBox in the middle
然后我将这段代码添加到用户控件中
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Extract
{
public partial class Slider : UserControl
{
public float Height;
public float Min = 0.0f;
public float Max = 1.0f;
private float defaultValue = 0.1f;
public Slider()
{
InitializeComponent();
}
private void sliderControl_Paint(object sender, PaintEventArgs e)
{
float bar_size = 0.45f;
float x = Bar(defaultValue);
int y = (int)(sliderControl.Height * bar_size);
e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
e.Graphics.FillRectangle(Brushes.DimGray, 0, y, sliderControl.Width, y / 2);
}
private float Bar(float value)
{
return (sliderControl.Width - 24) * (value - Min) / (float)(Max - Min);
}
}
}
然后当我将控件从工具箱拖到 form1 设计器时:
问题是当我尝试在 form1 设计器中调整控件的大小时,我只想看到 pictureBox 而没有它周围的控件。但是当我调整它的大小时,pictureBox 向下移动太多然后进入了:
Resized the control in form1 designer
如果我在用户控件设计器中调整控件大小以适应图片框大小,那么当在 form1 设计器中拖动它时,我根本看不到图片框。我需要调整它的大小才能看到图片框。
我认为没有动态调整大小。
【问题讨论】: