我的表单上有一个namespace Test1
{
/// <summary>
/// Interaktionslogik für MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
TabItem item = new TabItem();
item.Header = "Some header";
//item.Content = < your content>
TabControl.Items.Add(item);
}
}
}
,另一个表单上有一个按钮。一旦我按下另一个表单上的按钮,我将如何picturebox
在第一个表单上?
picturebox1_paint
这就是我所拥有的,为了让它发挥作用我需要改变什么?
答案 0 :(得分:0)
在Form1中,添加
Sub PaintImage(rectangle As Rectangle)
' create image in size of PictureBox1
Dim image As New Bitmap(PictureBox1.Width, PictureBox1.Height)
' paint on created image
Using gr As Graphics = Graphics.FromImage(image)
gr.DrawRectangle(New Pen(Color.Red), rectangle)
End Using
' display finished image in PictureBox1
PictureBox1.Image = image
End Sub
并使用按钮从表单中调用它:
Sub Button1_Click(sender as Object, e as EventArgs) Handles Button1.Click
Form1.PaintImage(New Rectangle(x, y, width, height)) ' assume we already have x, y, w, h
End Sub
您可以删除问题中显示的Paint()
事件处理程序。其目的是重新标记PictureBox1.Image
,如果它的大小或可见性发生变化,在大多数情况下,您可以将其保留原样。