C# 事件Load和Shown区别

蓝奇 2012-07-25 05:44:33
不知道事件Load和Shown区别啊。。。

事件Load是双击窗体的时候自动生成,也可以直接在程序中写
事件Shown只能在程序中自己写么
...全文
2154 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
蓝奇 2012-07-27
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 的回复:]
Load:在第一次显示窗体前发生。
Shown:发生,只要窗体首次显示。
第一个窗体显示,Shown 事件仅引发;随后,最小化、最大化,还原,隐藏,显示或无效和重新绘制不会引发此事件。
show:向用户显示具有指定所有者的窗体。
问:事件Load和Shown 除了一前一后触发,还有其他区别么?
。。。。。。
[/Quote]

Shown:http://technet.microsoft.com/zh-cn/library/system.windows.forms.form.shown(v=vs.110).aspx
如果事件Load和Shown 的区别只是一前一后触发,那么把Shown的方法体放到Load里不就可以啦?
事实不是酱紫滴,这到底是为什么捏???\(^o^)/~
蓝奇 2012-07-27
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 的回复:]
引用 1 楼 的回复:
load是窗体创建完成的时候触发,shown是每次窗体visable的时候触发。load在shown之前触发。事件可在属性窗口的事件那里绑定


同意!!!
[/Quote]

Shown:http://technet.microsoft.com/zh-cn/library/system.windows.forms.form.shown(v=vs.110).aspx
蓝奇 2012-07-27
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 的回复:]
正解
[/Quote]
Shown:http://technet.microsoft.com/zh-cn/library/system.windows.forms.form.shown(v=vs.110).aspx
水晶烟灰缸 2012-07-26
  • 打赏
  • 举报
回复
shown是窗体首次显示完毕了以后才执行,这样在应用当中可以减少感觉上的等待,load是在窗体创建完成时触发的,但是尚未显示,如果代码加载在这里的话给人感觉好像程序没被打开一样容易重复操作
续写经典 2012-07-26
  • 打赏
  • 举报
回复
load是窗体创建完成的时候触发,shown是每次窗体visable的时候触发。load在shown之前触发。事件可在属性窗口的事件那里绑定

的确如此
二号匪 2012-07-26
  • 打赏
  • 举报
回复
Form ..::.Shown 事件 Visual Studio 2010Visual Studio 2010

发送反馈
只要窗体是首次显示就发生。


命名空间: System.Windows.Forms
程序集: System.Windows.Forms(在 System.Windows.Forms.dll 中)
语法VBC#C++F#JScript以带有颜色区分的格式查看复制到剪贴板打印Public Event Shown As EventHandler

Public Event Shown As EventHandler
public event EventHandler Shown

public event EventHandler Shown
public:
event EventHandler^ Shown {
void add (EventHandler^ value);
void remove (EventHandler^ value);
}

public:
event EventHandler^ Shown {
void add (EventHandler^ value);
void remove (EventHandler^ value);
}
member Shown : IEvent<EventHandler,
EventArgs>

member Shown : IEvent<EventHandler,
EventArgs>




备注
只有在首次显示窗体时才会引发 Shown 事件;随后执行的最小化、最大化、还原、隐藏、显示或无效化和重新绘制操作都不会引发该事件。

有关处理事件的更多信息,请参见 使用事件。

参见MSDN

蓝奇 2012-07-26
  • 打赏
  • 举报
回复
事件Load:在第一次显示窗体前发生。

事件Shown:发生,只要窗体首次显示。
第一个窗体显示,Shown 事件仅引发;随后,最小化、最大化,还原,隐藏,显示或无效和重新绘制不会引发此事件。

方法show:向用户显示具有指定所有者的窗体。

问:1.事件Load和Shown 除了一前一后触发,还有其他区别么?
。。。。。。
2.C#的事件和方法除了名字不同,是不是事件就等同于方法呢?
蓝奇 2012-07-26
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]
load是窗体创建完成的时候触发,shown是每次窗体visable的时候触发。load在shown之前触发。事件可在属性窗口的事件那里绑定
[/Quote]

窗体创建完成?就是加载窗体吧。。。那加载了不就窗体可见了么
Load 和Shown只是一前一后触发
还有什么区别么???搞不懂了。。。
Anod 2012-07-26
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]
load是窗体创建完成的时候触发,shown是每次窗体visable的时候触发。load在shown之前触发。事件可在属性窗口的事件那里绑定
[/Quote]

同意!!!
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 的回复:]

引用 4 楼 的回复:
事件Shown:发生,只要窗体首次显示。


不只是首次,是每一次show的时候都会触发,但Load只会触发一次。只是一般情况下一个窗体不会反复地Hide和Show,所以看起来似乎没什么区别一样,一般处理数据绑定和一些准备性的工作都放在Load里
[/Quote]

我错了
SocketUpEx 2012-07-26
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 的回复:]

引用 1 楼 的回复:
load是窗体创建完成的时候触发,shown是每次窗体visable的时候触发。load在shown之前触发。事件可在属性窗口的事件那里绑定

正解
[/Quote]
第一个句号之前的说法,明显是错误的
Form.Load之前,窗体早就创建好很久很久了
InitializeComponent();方法就已经把控件加载好了
另外,MSDN关于Shown的说法,和你的刚好相反:
有在首次显示窗体时才会引发 Shown 事件;随后执行的最小化、最大化、还原、隐藏、显示或无效化和重新绘制操作都不会引发该事件。
江南野鹤 2012-07-26
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]
load是窗体创建完成的时候触发,shown是每次窗体visable的时候触发。load在shown之前触发。事件可在属性窗口的事件那里绑定
[/Quote]
正解
SocketUpEx 2012-07-26
  • 打赏
  • 举报
回复
一前一后
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 的回复:]
事件Shown:发生,只要窗体首次显示。
[/Quote]

不只是首次,是每一次show的时候都会触发,但Load只会触发一次。只是一般情况下一个窗体不会反复地Hide和Show,所以看起来似乎没什么区别一样,一般处理数据绑定和一些准备性的工作都放在Load里
失落的code 2012-07-26
  • 打赏
  • 举报
回复
Load是加载,可以有也可以没有。和show没任何关系,show只是显示窗体。如果有Load的话会在InitializeComponent中绑定,第一次加载窗体的时候会执行,也不能说第一次加载,可以去掉第一次,因为没有第二次加载。
蓝奇 2012-07-26
  • 打赏
  • 举报
回复
up!
up!
up!
up!
up!
up!
zhui22222 2012-07-25
  • 打赏
  • 举报
回复
load是窗体创建完成的时候触发,shown是每次窗体visable的时候触发。load在shown之前触发。事件可在属性窗口的事件那里绑定
zhui22222 2012-07-25
  • 打赏
  • 举报
回复
load是窗体创建完成的时候触发,shown是每次窗体visable的时候触发。load在shown之前触发。事件可在属性窗口的事件那里绑定
3.0 (BUILD 3143) 13 September 2017 See also the Announcement Post Refreshed UI theme, including full high DPI support New icon Added alternate theme, Adaptive, that inherits colors from the color scheme Added new color schemes Breakers, Mariana and Sixteen, derived from the excellent work of Chris Kempson and Dmitri Voronianski Added color scheme and theme switchers with live preview via the command palette Windows: Added touch input Linux: Added repositories for apt, yum and pacman Mac: Added Touch Bar support Mac: Support for custom color window title bars on OS X 10.10+ Many additions and bug fixes to the theme engine, plus full documentation Significant improvements to Markdown syntax highlighting, with thanks to keith-hall Significant improvements to C# syntax highlighting, with thanks to gwenzek Significant improvements to Java syntax highlighting, with thanks to djspiewak Significant improvements to Python syntax highlighting, with thanks to FichteFoll Significant improvements for R syntax highlighting, with thanks to randy3k Markdown: Improved symbol handling C#: Improved symbol handling Many other syntax highlighting improvements Various bugs with the syntax highlighting engine have been resolved Fixed several crash issues Improved responsiveness when the system is under high CPU load High DPI textures are used on Windows and Linux when the DPI scale is greater than 1.0 Improved font selection on all platforms, allowing selection of different weights by name Added setting theme_font_options to control font rendering of UI elements Improved auto indent rules for HTML and PHP Font geometry issues that prevent bold or italics are now printed in the console Fixed flash-of-white that could occur when the auto complete window is closed Disable scroll animation when animation_enabled is false in settings Files can now be renamed when only the case has changed New windows start with an empty find history Find in Files panel now responds to find_all and replace_all commands Various regex handling improvements in the Find panel Fixed text widgets cutting off the bottom pixel of their selection border Fixed an issue with close_windows_when_empty in empty session Fixed empty panes on startup when hot_exit was set to false Fix Open Containing Folder on Windows with a folder containing a comma Fix multi-cursor pasting when clipboard contains one or more full lines Prevent UNC paths from being mangled by edit_settings Prevent a crash when a malformed regex is used in indentation settings Improved rendering performance with a large number of gutter icons Gutter icons are now sized properly on Windows and Linux high DPI screens Improved sidebar performance when folders contain many thousands of files Improved inline error message style Fixed an issue where multiple indexing status windows could be shown Windows: Font rendering defaults to DirectWrite unless using Consolas or Courier New Windows: Added support for no_antialias font option when using DirectWrite Windows: Improved touch pad scrolling Windows: Improved file change detection robustness Windows: Improved font selection logic Windows: Fix ctrl+` shortcut for UK (ISO) keyboards Windows: Improved fallback font handling in UI elements Windows: The subl executable on OS X and plugin_host.exe on Windows are now signed Windows: sublime_text.exe now has CompanyName set in VERSIONINFO Mac: Handle layout changes due to macOS Sierra tabs Mac: Improved default web browser detection Mac: OS X 10.11 and macOS 10.12+ default to using San Francisco for the UI font Mac: Fixed file change notifications from freezing UI on macOS Sierra Mac: the user's default shell is executed and environmental variables are set in the plugin Python environment Linux: Update X11 selection on clipboard every time selection changes Linux: Improved MOD3 modifier key handling minihtml: Added support for borders minihtml: Respects font_options from the settings minihtml: Fixed layout of html popups on Windows and Linux under High DPI minihtml: Fixed crash when doctype is present minihtml: Fixed a crash from non-existent CSS vars minihtml: Fixed a crash triggered by bad image paths API: Add View.text_to_window() and View.layout_to_window() API: All API functions now accept and return device-independent-pixels API: Fixed input panel not running on_cancel when re-showing the input panel API: Fixed selector scoring with the & operator API: Fixed a bug causing incorrect phantom contents API: Fixed crash in Window.set_view_index() API: Updated OpenSSL to 1.0.2k, SQLite to 3.16.02 BUILD 3126 23 September 2016 Added Indexing Status to the Help menu to give more information about what the indexer is doing Fixed a compatibility issue with some third party syntax definitions that include JavaScript.sublime-syntax Reduced the default number of worker processes used for indexing. This can be manually controlled via the index_workers setting API: Updated OpenSSL to 1.0.2i

110,546

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧