动态改变PictureBox的高度
我有一个 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我做过这样的事情..
试试这个:
I have did this stuff like this..
try this: