在 C# 中调用另一个表单上的方法 [英] Calling a method on another form in C#

查看:19
本文介绍了在 C# 中调用另一个表单上的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个基本的图像编辑器.在我的应用中,如果用户想要调整图像大小,则会弹出一个新表单并要求用户为图像输入新的宽度和高度.

I am building a basic Image editor. In my app, if the user wants to resize the image a new form pops up and asks the user to input an new width and height for the image.

public partial class Form1 : Form
{
...
    private void resizeToolStripMenuItem_Click(object sender, EventArgs e)
    {
        resize resizeForm = new resize();
        resizeForm.ShowDialog();
    }
...
}

我想知道如何从 resizeForm 获取值并使用它们来更改父表单(Form1 实例)上的图像.

I am wondering how I can get the values from the resizeForm and use them to alter the image on the parent form (the Form1 instance).

如果这个问题需要澄清,请告诉我.

If this question needs clarification please let me know.

谢谢!

推荐答案

我认为有很多方法可以做到这一点.我可能会在 resizeForm 上使用公共属性,然后在 resizeForm.ShowDialog() 返回时获取这些属性.

I assume there are a number of ways to do this. I'd probably use public properties on the resizeForm and then get those when the resizeForm.ShowDialog() returns.

if (resizeForm.ShowDialog() == DialogResult.OK) // or whatever
{
   myVal = resizeForm.Val;
   ...
}

或类似的东西.

这篇关于在 C# 中调用另一个表单上的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆