如何从用户控件显示新表单?
我正在制作一个用户控件,它是一个文件管理器(剪切、复制、粘贴..等)
所以在移动/处理文件时..当文件已经存在时我必须显示一个消息框..让用户确认覆盖它或取消..但我需要4个按钮
所以我制作了一个名为“MyMessageBox”的新表单,其中包含 4 个按钮和一个标签。
我的问题是..在(userControl1.cs)中我无法初始化表单像这样:
MyMessageBox msgbox = new MyMessageBox("覆盖文件?");
I'm making a usercontrol which is a file manager (cut ,copy ,paste .. etc)
so while moving/coping files .. i had to show a messagebox when the file is already exist .. to let the user to confirm overwrite it or cancel .. but i need 4 buttons
so i made a new form called "MyMessageBox" which contains the 4 buttons and a label.
my problem is .. in (userControl1.cs) i can't initialize the form like this:
MyMessageBox msgbox = new MyMessageBox("overwrite file ?");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,您需要确保您的用户控件具有您创建的表单的可见性(即,如果您的表单位于另一个名称空间或项目中,您将需要使用 using 语句或添加项目引用,以便您的用户控件能够使用它。)并且您的构造函数就是您所认为的,正如 M.Babcock 所建议的那样。您可以尝试类似
UserControl:
CustomMessageBox:
这会给您这样的结果。
First of all you need to make sure that your usercontrol has visibility of the form that you created(i.e. if your form is in another namespace or project you will need to use a using statement or add a project reference in order for your usercontrol to be able to use it.) and that your constructor is what you are thinking it is as M.Babcock is suggesting. You can try something like this
UserControl:
CustomMessageBox:
Which will give you a result like this.