c# – 标签要拉伸的图像模式

c# – 标签要拉伸的图像模式,第1张

概述我写了这段代码来添加我的标签: JArray a = JArray.Parse(temp);Label[] labels = new Label[100];foreach (JObject o in a.Children<JObject>()){ foreach (JProperty p in o.Properties()) { string name = p 我写了这段代码来添加我的标签:

JArray a = JArray.Parse(temp);Label[] labels = new Label[100];foreach (JObject o in a.Children<JObject>()){    foreach (JProperty p in o.PropertIEs())    {        string name = p.name;        string value = p.Value.ToString();        if (name == "name")        {            labels[counter] = new Label();            //Image i = Image.Fromfile("item.jpg");            labels[counter].Text = value;            labels[counter].Image =Image.Fromfile("item.jpg");            //labels[counter].Image            //labels[counter].Backcolor = color.Blue;            labels[counter].TextAlign = System.Drawing.ContentAlignment.MIDdleCenter;            labels[counter].top = height;                  height += 50;            Controls.Add(labels[counter]);        }    }}

图像拉伸到标签尺寸.我怎样才能做到这一点?

解决方法 显示和 *** 作图像和文本的能力在Winforms控件中以相当狂野的方式展开.

>标签无法拉伸其图像.
> PictureBox和Panel可以但不显示文本
>按钮可以同时执行,但无论您如何设置样式,它都将始终为按钮.

因此,要获得组合,您需要拥有者绘制一些东西:

>在重载中绘制DrawImage以获得正确的图像大小,然后将图像添加到标签
>或者将文本绘制到面板上以将其显示在图像旁边

或者你可以将两个控制与正确的能力结合起来:

您可以创建一个Panel并将其BackgroundImage设置为您的Image及其BackgroundImageLayout = Stretch.然后,您可以将Label及其Text集添加到Panel的控件集合中:

// preparation for testing:Image image = Image.Fromfile("D:\stop32.png");Size size = new Size(77,77);// create the combined control// I assume your Label is already therePanel pan = new Panel();pan.Size = size;// or,since the Label has the right size:pan.Size = label.Size;  // use ClIEntsize,if borders are involved!pan.BackgroundImage = image;pan.BackgroundImageLayout = ImageLayout.Stretch;label.Parent = pan;  // add the Label to the Panellabel.Location = Point.Empty;label.Text = "TEXT";label.Backcolor = color.transparent;// add to (e.g.) the formpan.Parent = this;

根据需要设置边框..

还有一个选项:如果所有图像应具有相同的大小,如果它是256×256像素或更少,您可以将它们添加到ImageList.这将以非常简单的方式将它们拉伸到ImageList.ImageSize,您可以将它们添加到Label中.

总结

以上是内存溢出为你收集整理的c# – 标签要拉伸的图像模式全部内容,希望文章能够帮你解决c# – 标签要拉伸的图像模式所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/1219586.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-05
下一篇2022-06-05

发表评论

登录后才能评论

评论列表(0条)

    保存