动态改变PictureBox的高度

发布于 2024-12-14 06:17:28 字数 631 浏览 4 评论 0原文

我有一个 RichTextBox。在它上面,我画了许多图片框。图片框不包含任何图像,但将背景颜色设置为黑色。最初,我将每个图片框的高度设置为与 Richtextbox 的高度相同。但是当我调整 Richtextbox 的大小时,我也想更改图片框的高度。

我通过监听 Richtextbox 的 Resize 事件处理程序来完成此操作,在那里我获取了 richtextbox 的当前高度并相应地更改了 picturebox 的高度。但问题是,我可以看到图片框越来越大,但后面部分的背景颜色没有设置为黑色,而是白色。我尝试通过使 &更新 Richtextbox 和图片框,但没有任何反应。有什么想法吗???

调整代码片段大小:

void tbx_resize(Object sender, EventArgs e)
{    
    var height = ((RichTextBox)sender).Height;
    foreach(PictureBox pic in ((RichTextBox)sender).Controls)
    {
       pic.Height = height;
       pic.Invalidate();
    }
    ((RichTextBox)sender).Invalidate();
} 

I am having a RichTextBox. On top of it, I draw number of pictureboxes. Pictureboxes donot contain any image, but setting background color to black. Initially, I set the height of each picturebox to be same as the height of richtextbox. But when I resize the richtextbox, I want to change the height of the pictureboxes as well.

I did this by listening to the Resize event handler of the richtextbox, there I get the current height of the richtextbox and change the height of picturebox accordingly. But the problem is that, I can see that the pictureboxes are getting larger but the latter part's background color is not set as black, but white. I try by invalidating & updating both richtextbox and pictureboxes, but nothing happens. Any ideas???

Resize code snippet:

void tbx_resize(Object sender, EventArgs e)
{    
    var height = ((RichTextBox)sender).Height;
    foreach(PictureBox pic in ((RichTextBox)sender).Controls)
    {
       pic.Height = height;
       pic.Invalidate();
    }
    ((RichTextBox)sender).Invalidate();
} 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雪落纷纷 2024-12-21 06:17:28

我做过这样的事情..
试试这个:

void tbx_resize(Object sender, EventArgs e) 
{     
    int height = ((RichTextBox)sender).Height;
    foreach (Control c in this.Controls)
    {
       if (c is PictureBox)
       {
          c.Height = height;
       }
    } 
} 

I have did this stuff like this..
try this:

void tbx_resize(Object sender, EventArgs e) 
{     
    int height = ((RichTextBox)sender).Height;
    foreach (Control c in this.Controls)
    {
       if (c is PictureBox)
       {
          c.Height = height;
       }
    } 
} 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文